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

Jammy flow integration #728

Merged
merged 36 commits into from
Sep 18, 2024

Conversation

RasmusOrsoe
Copy link
Collaborator

@RasmusOrsoe RasmusOrsoe commented May 29, 2024

This PR adds support for Normalizing Flows via the jammy_flows package, and therefore supersedes #649. The benefit of using jammy_flows is that it contains many different normalizing flows, and that we avoid maintaining that code ourselves :-).

The package is not listed as a direct dependency but used as an optional support package.

Specifically, this PR introduces the following major changes:

  1. StandardFlowTask now uses jammy_flows to construct pdfs of any kind that it supports. These pdfs can be both conditional and non-conditional. Conditional flows can be conditioned on latent model output, event-level information or pulse-level information.
  2. A new model class is added: NormalizingFlow which work with the StandardFlowTask. Usage is similar to StandardModel.
  3. An example of training a conditional flow is added under examples/04_training/07_train_normalizing_flow.py
  4. has_jammy_flows_package() is added under graphnet.utils.imports to check if its installed, and is used in a few places to make sure that the code runs also for people who choose not to install jammy_flows.

Minor changes:

  1. repeat_labels is added as an argument to GraphDefinition - if True, event-level information, .e.g energy is repeated row-wise to match the number of pulses in the event. This feature was added in this PR to make it possible to build flows that learn pulse-level pdfs conditioned on event-level information.
  2. Installation matrix is updated to provide a note on the installation of jammy flows
  3. Github workflows is adjusted to run with jammy_flows installed.
  4. **kwargs for Trainer is added for predict-methods in EasySyntax to allow the same level of control over Trainer arguments as we have for .fit

@RasmusOrsoe
Copy link
Collaborator Author

@Aske-Rosted checks are now passing. Please let me know if you have any questions

@RasmusOrsoe RasmusOrsoe mentioned this pull request Aug 7, 2024
Copy link
Collaborator

@Aske-Rosted Aske-Rosted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - A few questions here and there that do not necessarily require fixing.

sensor listed here will be removed from the graph. Defaults to None.
string_mask: A list of string id's to be masked from the graph. Defaults to None.
sensor listed here will be removed from the graph.
Defaults to None.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some unintended formatting happen here?

return self._default_prediction_labels

def nb_inputs(self) -> Union[int, None]: # type: ignore
"""Return number of conditional inputs assumed by task."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does non-conditional inputs also exist or what is the reason for the distinction of "conditional"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow can be trained both as a conditional flow, where it's conditioned on a latent representation of an event e.g. p(target|latent_rep) which is the probability of seeing target for event represented by latent_rep, and as an unconditional probability distribution e.g. p(target) which would just learn the overall distribution of the variable in the dataset.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes unrelated to jammy flows?

Copy link
Collaborator

@Aske-Rosted Aske-Rosted Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reread the minor changes and these changes are described there, you can disregard this question.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes also unrelated to Jammy flows?

Copy link
Collaborator

@Aske-Rosted Aske-Rosted Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reread the minor changes and these changes are described there, you can disregard this question.

labels = labels.to(self.dtype)
# Set the initial parameters of flow close to truth
# This speeds up training and helps with NaN
if self._initialized is False:
Copy link

@jvaracarbonell jvaracarbonell Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick note: I noticed that this part could override the learned weights whenever they are loaded from a state dict, which might affect further training or inference. It could be worth adding a global boolean to check if the weights have been loaded. Otherwise, it might be good at least to pass and self.training , which should work when the model is set to evaluation mode for predictions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jvaracarbonell thanks for pointing this out! I've added the check

@RasmusOrsoe RasmusOrsoe merged commit 4d9ca09 into graphnet-team:main Sep 18, 2024
13 of 14 checks passed
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.

3 participants