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

[MAINTENANCE] Refactor and clean up. #4008

Conversation

alexsherstinsky
Copy link
Collaborator

Scope

  • Make the implementation for the fix of the ViTEncoder to ensure that the transformers.ViTModel returns the output_attentions more elegant (and cuts on the amount of code).

Code Pull Requests

Please provide the following:

  • a clear explanation of what your code does
  • if applicable, a reference to an issue
  • a reproducible test for your PR (code, config and data sample)

Documentation Pull Requests

Note that the documentation HTML files are in docs/ while the Markdown sources are in mkdocs/docs.

If you are proposing a modification to the documentation you should change only the Markdown files.

api.md is automatically generated from the docstrings in the code, so if you want to change something in that file, first modify ludwig/api.py docstring, then run mkdocs/code_docs_autogen.py, which will create mkdocs/docs/api.md .

gradient_checkpointing=gradient_checkpointing,
)
if output_attentions:
config = ViTConfig(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just create a dictionary mapping, then optionally add "attn_implementation" if output_attention and pass the dictionary as **kwargs into the Config? Will reduce boilerplate :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@arnavgarg1 Done -- sorry about missing the obvious! Thanks!

"gradient_checkpointing": gradient_checkpointing,
}
config_dict["attn_implementation"] = "eager"
config = ViTConfig(**config_dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we no longer need to do the if else so we can pass these custom args in both cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@arnavgarg1 We do -- I updated the code. If we do not do it, the tests still pass, because locally nothing changes (but runs slower). This is because of the breaking change on the HF side, where they default to SDPA for speed (but it is lazy execution, leaving attention tensors as None; with "eager" in either case, things still work, but less efficiently). This is fixed now -- good catch -- thanks!

Copy link

github-actions bot commented May 23, 2024

Unit Test Results

  6 files  ±0    6 suites  ±0   14m 23s ⏱️ +2s
12 tests ±0    9 ✔️ ±0    3 💤 ±0  0 ±0 
60 runs  ±0  42 ✔️ ±0  18 💤 ±0  0 ±0 

Results for commit 9b91d6b. ± Comparison against base commit 7053966.

♻️ This comment has been updated with latest results.

@alexsherstinsky alexsherstinsky merged commit 3b9192b into master May 23, 2024
18 checks passed
@alexsherstinsky alexsherstinsky deleted the maintenance/alexsherstinsky/requirements/cleanup_update_vision_transformer_encoder_for_transformers_version_4_41_1_compatibility-2024_05_23-37 branch May 23, 2024 22:13
skanjila pushed a commit to skanjila/ludwig that referenced this pull request Jun 7, 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.

None yet

2 participants