Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the transformation for maco #60

Closed
wants to merge 35 commits into from

Conversation

sushmanthreddy
Copy link
Contributor

issue #57

  • adding transformation for MaCO implementation

@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.70%. Comparing base (df90177) to head (f87f5c8).
Report is 3 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   83.03%   91.70%   +8.66%     
==========================================
  Files          22       19       -3     
  Lines         825      747      -78     
==========================================
  Hits          685      685              
+ Misses        140       62      -78     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sushmanthreddy
Copy link
Contributor Author

Subject: Request for Assistance with PyTorch Function Implementation

Hey @Mayukhdeb,

Here's a summary of what the function does:

  • It compiles sub-objectives into one function for optimization.
  • Returns a reconfigured model, a loss calculator function, objective names, and input shape.

Would you mind taking a look at the draft TensorFlow function and helping me adapt it to PyTorch? I've attached the code snippet below for reference:

def compile_objectives(self) -> Tuple[tf.keras.Model, Callable, List[str], Tuple]:
        """
        Compile all the sub-objectives into one and return the objects
        for the optimization process.

        Returns
        -------
        modified_model
            Model with the outputs needed for the optimization.
        loss_calculator
            Function to compute the loss for the objectives.
        objective_names
            Names of each objective.
        input_shape
            Shape of the input, one sample for each optimization.
        """
        num_objectives = len(self.multipliers)

        # Rearrange masks to match different objectives with model outputs
        mask_combinations = np.array([np.array(m, dtype=object) for m in itertools.product(*self.masks)])
        mask_tensors = [tf.cast(tf.stack(list(mask_combinations[:, i])), tf.float32) for i in range(num_objectives)]

        # Concatenate names for each combination of objectives
        objective_names = np.array([' & '.join(names) for names in itertools.product(*self.names)])

        # Define multipliers for each sub-objective
        objective_multipliers = tf.constant(self.multipliers)

        def compute_loss(model_outputs):
            total_loss = 0.0
            for index in range(num_objectives):
                outputs = model_outputs[index]
                total_loss += self.funcs[index](
                    outputs, tf.cast(mask_tensors[index], outputs.dtype))
                total_loss *= objective_multipliers[index]
            return total_loss

        # Create the modified model with necessary layers
        modified_model = tf.keras.Model(self.model.input, [*self.layers])

        num_combinations = mask_tensors[0].shape[0]
        input_shape = (num_combinations, *modified_model.input.shape[1:])

        return modified_model, compute_loss, objective_names, input_shape

Any insights, suggestions, or code snippets you could provide would be greatly appreciated! Let me know if you have any questions or need further clarification on anything.

Looking forward to your guidance!

@sushmanthreddy
Copy link
Contributor Author

the main problem is coming near the modified model part..

@sushmanthreddy sushmanthreddy deleted the maco branch May 7, 2024 12:31
@sushmanthreddy sushmanthreddy restored the maco branch May 7, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants