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

Setup loss_type in config at model init time #34616

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ChanderG
Copy link

@ChanderG ChanderG commented Nov 5, 2024

ensures no additional graph break introduced when torch.compile'ed

fixes #34615

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

ensures no additional graph break introduced when torch.compile'ed

fixes huggingface#34615

Signed-off-by: ChanderG <[email protected]>
@ChanderG
Copy link
Author

ChanderG commented Nov 5, 2024

If this approach is fine - I will extend the PR to cover a wide set of models.

Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

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

Hi @ChanderG! Thanks for opening an issue and PR! Nice catch with the graph breaks!
Re the PR it is usually not the best decision to modify class attribute inplace, however this pattern is widely used across classification models losses

if self.num_labels == 1:
    self.config.problem_type = "regression"
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
    self.config.problem_type = "single_label_classification"
else:
    self.config.problem_type = "multi_label_classification"

do you have other ideas on how to handle it without modifying the config attribute? Is there a way to fix re.findall instead of introducing the change for all models?

Alternatively we can have a model attribute, smth like

self.loss_type = "ForCausalLM" if self.config.loss_type is None else self.config.loss_type

but not feel strong re this :)

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.

Torch.compile Graph break introduced due to new loss function api
2 participants