Skip to content

Add ONNX support for InternLM2 #2244

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gmf14
Copy link

@gmf14 gmf14 commented Apr 28, 2025

What does this PR do?

Adds support for ONNX export of InternLM2 model for text generation tasks (#2240).

Note: I checked the ONNX contribution guide and it seems I cannot find an updated version to add the tests, hence I haven't committed them yet. I would like to kindly ask what steps to take in order to add the tests correctly.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@fxmarty, @echarlaix, @JingyaHuang, @michaelbenayoun

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks a lot for the addition @gmf14

@@ -2414,7 +2414,7 @@ class ORTModelForCausalLMIntegrationTest(ORTModelTestMixin):

# TODO: fix "mpt" for which inference fails for transformers < v4.41
if is_transformers_version(">=", "4.41"):
SUPPORTED_ARCHITECTURES.extend(["phi3", "mpt"])
SUPPORTED_ARCHITECTURES.extend(["phi3", "mpt", "internlm2"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test using a tiny random model like katuni4ka/tiny-random-internlm2 ?
You can add it in respectively PYTORCH_EXPORT_MODELS_TINY and MODEL_NAME

Copy link
Author

Choose a reason for hiding this comment

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

Hi @echarlaix! Thanks a lot for your answer. I've added the tests in both PYTORCH_EXPORT_MODELS_TINY and MODEL_NAME.

Copy link
Member

Choose a reason for hiding this comment

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

you will have to pass trust_remote_code=True for this model since huggingface/transformers#29667 was not merged

Copy link
Author

Choose a reason for hiding this comment

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

I'm figuring out what the best way to pass the trust_remote_code = True parameter to main_export() is for the text_export.py and text_export_cli.py files, for instance. Are there any other models that require this to true? A shallow approach (later can be abstracted) would be to simply add e.g. here something like:

# Check for models that require remote code execution
if "internlm2" in model_name:
    trust_remote_code = True

Something similar would apply for ORTModelForCausalLM in test_modeling.py.

Thanks a lot for your feedback @echarlaix @IlyasMoutawwakil!

Copy link
Member

Choose a reason for hiding this comment

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

@gmf14 for now we don't support many (any ?) of remote code models (because they are usually hard to maintain).
let's simply use if model_type in ["internlm2"]: trust_remote_code = True in both export and modeling tests.

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.

5 participants