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

Add logic for shifting labels before computing metrics #1913

Merged
merged 11 commits into from
Jan 27, 2023

Conversation

alextrott16
Copy link
Contributor

@alextrott16 alextrott16 commented Jan 26, 2023

What does this PR do?

Adds a shift_labels init argument to HuggingFaceModel class. This instructs the model whether to shift labels by one token before computing metrics, which mimics the way HF Causal LM classes handle labels when computing loss. This fixes the current implementation, which never does this shifting and produces incorrect metric results for Causal LMs.

If shift_labels is not specified, HuggingFaceModel will try to infer the correct behavior based on whether the model is an instance of a registered HF Causal LM class (or a subclass of one).

What issue(s) does this change relate to?

https://mosaicml.atlassian.net/browse/CO-1691

Before submitting

  • Have you read the contributor guidelines?
  • Is this change a documentation change or typo fix? If so, skip the rest of this checklist.
  • Was this change discussed/approved in a GitHub issue first? It is much more likely to be merged if so.
  • Did you update any related docs and document your change?
  • Did you update any related tests and add any new tests related to your change? (see testing)
  • Did you run the tests locally to make sure they pass?
  • Did you run pre-commit on your change? (see the pre-commit section of prerequisites)

@alextrott16 alextrott16 requested a review from a team as a code owner January 26, 2023 20:54
Copy link
Contributor

@dakinggg dakinggg left a comment

Choose a reason for hiding this comment

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

Can you add a test please? Otherwise LGTM. Will approve after test

composer/models/huggingface.py Outdated Show resolved Hide resolved
alextrott16 and others added 4 commits January 26, 2023 14:05
Typo fix

Co-authored-by: Daniel King <43149077+dakinggg@users.noreply.github.com>
Copy link
Contributor

@dakinggg dakinggg left a comment

Choose a reason for hiding this comment

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

LGTM, left one comment to cleanup the fixture usage a bit (sorry, i pointed you to the wrong place for the usage you wanted)

tests/models/test_hf_model.py Outdated Show resolved Hide resolved
tests/common/models.py Outdated Show resolved Hide resolved
@alextrott16 alextrott16 merged commit b33c381 into dev Jan 27, 2023
@alextrott16 alextrott16 deleted the alex/causal-roll-labels-1691 branch January 27, 2023 00:48
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