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

Generic downstream eval #160

Merged
merged 35 commits into from
Jul 9, 2024
Merged

Generic downstream eval #160

merged 35 commits into from
Jul 9, 2024

Conversation

mrudat-iais
Copy link
Collaborator

@mrudat-iais mrudat-iais commented Jun 24, 2024

What does this PR do?

We can now convert a modalities model into a HF model. This model can then be evaluated in eval harness.

  • (main) We now have a convert_pytorch_to_hf_checkpoint endpoint that takes the model_name, model_config_path and output_dir and creates HF files that can then be loaded with AutoModel.from_pretrained
  • (tests) we have a test that shows the functionality tests/checkpointing/test_checkpoint_conversion.py

General changes

  • none besides the above
  • PR feedback addressed and implemented

Breaking Changes

  • no breaking changes

Checklist before submitting final PR

  • My PR is minimal and addresses one issue / enhancement in isolation
  • I have merged main into this feature branch
  • I have reviewed my own code w.r.t. correct implementation, missing type hints, proper documentation, etc.
  • I have run a sample config for model training
  • I have fixed all failing tests (python tests/tests.py)

rrutmann and others added 20 commits June 10, 2024 13:33
- Added test for checkpoint conversion.
- In process of adapting HuggingFaceAdapterConfig for loading the saved HF model.
- In process of adapting HuggingFaceAdapterConfig for loading the saved HF model.
- Adapted HuggingFaceAdapterModel for loading the saved HF model.
- Adapted HuggingFaceAdapterModel for loading the saved HF model.
- fixed end point for checkpoint conversion
…dels

- test cases added for gpt2 and mamba
- only one single HFAdapter and HFAdapterConfig
- added gpt2 config example yaml file for testing
- type hints added
- comments in toml deleted
- loading a model with registry is now in models/utils.py
- both tests and hf_adapter call util method
@mrudat-iais mrudat-iais marked this pull request as ready for review June 25, 2024 13:14
@mrudat-iais mrudat-iais requested a review from le1nux June 25, 2024 13:14
@le1nux le1nux added the enhancement New feature or request label Jun 26, 2024
Copy link
Member

@le1nux le1nux left a comment

Choose a reason for hiding this comment

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

Really good work and awesome that you guys found a generic solution to it! :-) Thanks a lot for digging deep into the huggingface source code!

I left a few remarks here and there that you should address but overall the solution is great!

src/modalities/__main__.py Outdated Show resolved Hide resolved
src/modalities/checkpointing/checkpoint_conversion.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
tests/checkpointing/test_checkpoint_conversion.py Outdated Show resolved Hide resolved
tests/checkpointing/test_checkpoint_conversion.py Outdated Show resolved Hide resolved
tests/checkpointing/test_checkpoint_conversion.py Outdated Show resolved Hide resolved
Copy link
Member

@le1nux le1nux left a comment

Choose a reason for hiding this comment

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

Really good work and awesome that you guys found a generic solution to it! :-) Thanks a lot for digging deep into the huggingface source code!

I left a few remarks here and there that you should address but overall the solution is great!

le1nux

This comment was marked as duplicate.

- Add missing type hints
- consolidate code
- refactor tests
- shorten test configs
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/utils.py Outdated Show resolved Hide resolved
tests/checkpointing/test_checkpoint_conversion.py Outdated Show resolved Hide resolved
Copy link
Member

@le1nux le1nux left a comment

Choose a reason for hiding this comment

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

The PR is almost in a mergable state. I found one potential bug with the PosixPath to string conversion. And some minor things that I think should be addressed before merging. Other than that it's in a great state and we should be able to merge after including the requested changes and another person has reviewed it :-)

@le1nux le1nux requested a review from mali-git July 3, 2024 14:56
- Added type hints in test_checkpoint_conversion.py and hf_adapter.py
- Added ConfigError in exceptions.py
- Fixed the bug in forward() in hf_adapter.py where the return_dict condition was returning wrong data type.
- Converted model_type in utils.py from str to Enum.
- Added back the test to check the output of the model before and after conversion.
- Bug fix in convert_posixpath_to_str() for list values.
- Added test for convert_posixpath_to_str()
- Changed _convert_posixpath_to_str() to convert_posixpath_to_str()
- Added type arguments to the fixture arguments in test_checkpoint_conversion.py
- Changed back convert_posixpath_to_str() to _convert_posixpath_to_str()
@ajude2s ajude2s self-assigned this Jul 5, 2024
ajude2s and others added 7 commits July 5, 2024 12:37
Added prediction_key argument in the convert_pytorch_to_hf_checkpoint end point
Changed this back. It was not a bug. Huggingface requires the output in the particular format when return_dict = True
Fixed the issue where the config of checkpointed model still needs checkpointed_model key and used the non-converted checkpoint in Eval Harness.
src/modalities/__main__.py Outdated Show resolved Hide resolved
src/modalities/__main__.py Outdated Show resolved Hide resolved
src/modalities/checkpointing/checkpoint_conversion.py Outdated Show resolved Hide resolved
src/modalities/checkpointing/checkpoint_conversion.py Outdated Show resolved Hide resolved
src/modalities/models/huggingface_adapters/hf_adapter.py Outdated Show resolved Hide resolved
src/modalities/models/utils.py Outdated Show resolved Hide resolved
tests/models/test_hf_adapter.py Outdated Show resolved Hide resolved
@rrutmann rrutmann merged commit f25c018 into main Jul 9, 2024
@rrutmann rrutmann deleted the generic-downstream-eval branch July 9, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants