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

Add dtype arg to Gemma HF conversion script #1452

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

nkovela1
Copy link
Collaborator

No description provided.

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

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

looks good! just don't understand the yield

def _set_default_tensor_type(dtype: torch.dtype):
"""Sets the default torch dtype to the given dtype."""
torch.set_default_dtype(dtype)
yield
Copy link
Member

Choose a reason for hiding this comment

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

what is this yield doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The yield allows whatever is in the context (in this case, the checkpoint conversion) to fully execute. After that is done, this will reset to the default torch dtype.

Copy link
Member

Choose a reason for hiding this comment

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

Ah i see. in that case, do we need to care?

No real problem with this, but overall is intended to be running as a toplevel script right? Is there some scenario in which more python would be changed after the conversion inside the same python execution?

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 think it's good practice to keep the dtype change within the context of the scope rather than affecting it globally. If we add any more code outside the scope after, we'd need to be aware of a global property change.

@nkovela1 nkovela1 merged commit f1428e6 into keras-team:master Feb 22, 2024
6 checks passed
abuelnasr0 pushed a commit to abuelnasr0/keras-nlp that referenced this pull request Apr 2, 2024
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.

2 participants