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

[zero] added error message to handle on-the-fly import of torch Module class #1135

Merged
merged 2 commits into from
Jun 20, 2022

Conversation

FrankLeeeee
Copy link
Contributor

The zero init context has a precondition that the module class has to be imported before entering the context. However, sometimes this is not always so. For example:

with ctx:
    model = transformers.BertModel(...)

This example will raise exception because BertModel is only imported on the fly. This PR adds an error message for easier debugging.

@@ -80,6 +80,10 @@ def __exit__(self, exc_type, exc_value, traceback):
torch.set_default_dtype(self._old_default_dtype)

def _disable_class(cls):
if not hasattr(cls, '_old_init'):
raise AttributeError(
f"_old_init is not found in the {cls.__name__}, please make sure that you have this class imported before entering the context."
Copy link
Contributor

Choose a reason for hiding this comment

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

make sure import InsertPostInitMethodToModuleSubClasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sure cls is imported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@FrankLeeeee FrankLeeeee merged commit 73ad05f into hpcaitech:main Jun 20, 2022
@FrankLeeeee FrankLeeeee deleted the hotfix/zero-init-ctx branch January 26, 2023 07:08
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.

None yet

2 participants