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

Fix pipelines #608

Merged
merged 6 commits into from
May 23, 2024
Merged

Fix pipelines #608

merged 6 commits into from
May 23, 2024

Conversation

dacorvo
Copy link
Collaborator

@dacorvo dacorvo commented May 23, 2024

What does this PR do?

This fixes a regression in Neuron pipelines with transformers == 4.40.2.

The issue is actually fixed in transformers as a side-effect of this pull-request:
huggingface/transformers#30534
But the issue in optimum-neuron actually comes from the fact that all neuron models are based on optimum.OptimizedModel that reimplements transformers.PretrainedModel without providing all its methods (including to()).

This pull-request therefore introduces a new top-level NeuronModel class that inherits from optimum.OptimizedModel and provides the missing methods.

All neuron model classes should now inherit from NeuronModel.

In the process, NeuronBaseModel is renamed to NeuronTracedModel to remove any ambiguity.

The docker package must be updated to be compatible with the latest
requests release. In the meantime we pin requests version.
@dacorvo dacorvo force-pushed the fix_ci_pipelines_tgi branch 2 times, most recently from cfa1c39 to fb1d6fc Compare May 23, 2024 09:22
@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.

@dacorvo dacorvo force-pushed the fix_ci_pipelines_tgi branch 2 times, most recently from c942f7c to 53f7ed4 Compare May 23, 2024 11:46
This base class will implement transformers PreTrainedModel methods
that are not implemented in optimum PreTrainedModel base class.
Copy link
Collaborator

@JingyaHuang JingyaHuang left a comment

Choose a reason for hiding this comment

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

Thx David for opening the PR! Left some nits!

neuron_config: Optional["NeuronDefaultConfig"] = None,
**kwargs,
):
def __init__(self, model: "PreTrainedModel", config: "PretrainedConfig"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

For traced models, we are passing torch.jit._script.ScriptModule as model here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I realized that when the CI failed ... 🫣

huggingface_token = use_auth_token
elif use_auth_token:
huggingface_token = HfFolder.get_token()
if hasattr(model, "device"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary, for traced model setting all dummy device as CPU would be fine I think.

Copy link
Collaborator Author

@dacorvo dacorvo May 23, 2024

Choose a reason for hiding this comment

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

Yes, but I was wondering if at some point we wouldn't end up with models on XLA device.

Whether the Neuron model has separated weights and neff graph (by setting `inline_weights_to_neff=False` during the compilation).
"""
return not self.config.neuron.get("inline_weights_to_neff", True)
def to(self, device: Union[str, torch.device]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to add content if this is actually a no-op function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As long as it exist, someone might want to call it, so I added a check.

@@ -0,0 +1,611 @@
# coding=utf-8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just keep it in modeling_base.py?

@dacorvo dacorvo marked this pull request as ready for review May 23, 2024 15:25
@dacorvo dacorvo requested a review from JingyaHuang May 23, 2024 16:14
Copy link
Collaborator

@JingyaHuang JingyaHuang left a comment

Choose a reason for hiding this comment

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

LGTM!

@JingyaHuang JingyaHuang merged commit 639c17a into main May 23, 2024
12 of 13 checks passed
@JingyaHuang JingyaHuang deleted the fix_ci_pipelines_tgi branch May 23, 2024 16:27
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.

3 participants