Skip to content

Add ONNX support for InternLM2#2244

Merged
echarlaix merged 8 commits into
huggingface:mainfrom
gmf14:internlm2-support
Jun 6, 2025
Merged

Add ONNX support for InternLM2#2244
echarlaix merged 8 commits into
huggingface:mainfrom
gmf14:internlm2-support

Conversation

@gmf14
Copy link
Copy Markdown
Contributor

@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
Copy link
Copy Markdown

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
Copy Markdown
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

Comment thread tests/onnxruntime/test_modeling.py Outdated
# 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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.

@echarlaix echarlaix added the onnx Related to the ONNX export label Jun 4, 2025
@echarlaix echarlaix self-assigned this Jun 5, 2025
@echarlaix echarlaix merged commit 297a6a0 into huggingface:main Jun 6, 2025
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

onnx Related to the ONNX export

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants