Skip to content

[Transformer2DModel] Handle norm_type safely while remapping#8370

Merged
sayakpaul merged 5 commits intomainfrom
safe-norm-type-handling-transformer
Jun 4, 2024
Merged

[Transformer2DModel] Handle norm_type safely while remapping#8370
sayakpaul merged 5 commits intomainfrom
safe-norm-type-handling-transformer

Conversation

@sayakpaul
Copy link
Copy Markdown
Member

What does this PR do?

See: #7647 (comment)

@sayakpaul sayakpaul requested review from DN6 and yiyixuxu May 31, 2024 10:35
@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.

Comment on lines +88 to +95
else:
input_norm_type = config["norm_type"]
mappings = _CLASS_REMAPPING_DICT.get(previous_class_name)
all_norm_types = list({k for k in mappings if "norm" in k})
logger.info(
f"`{previous_class_name}` couldn't be mapped because `{input_norm_type}` isn't available"
f" in the remappings. Available `norm_type`s: {all_norm_types}"
)
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.

Not sure we need to do this check if a remapping doesn't exist. Any specific reason why we can't just return the class?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't understand. What class is to be returned in this case?

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.

The original class. Why can this just not be

if remapped_class:
  ...
else:
  return old_class

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We are doing that only. Additionally, we're providing the user with some information via the warning. Do you think no need?

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.

they don't need a warning here - they get the class they intended to use

sayakpaul and others added 2 commits June 3, 2024 11:56
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
@sayakpaul
Copy link
Copy Markdown
Member Author

@yiyixuxu @DN6 done removing the warning when returning the old_class.

@sayakpaul sayakpaul merged commit 6ddbf62 into main Jun 4, 2024
@sayakpaul sayakpaul deleted the safe-norm-type-handling-transformer branch June 4, 2024 09:39
sayakpaul added a commit that referenced this pull request Jun 4, 2024
* handle norm_type of transformer2d_model safely.

* log an info when old model class is being returned.

* Apply suggestions from code review

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>

* remove extra stuff

---------

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
sayakpaul added a commit that referenced this pull request Dec 23, 2024
* handle norm_type of transformer2d_model safely.

* log an info when old model class is being returned.

* Apply suggestions from code review

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>

* remove extra stuff

---------

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
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.

4 participants