Skip to content

Cache merged_typed_dict to not break validate_typed_dict caching - #45807

Merged
zucchini-nlp merged 2 commits into
huggingface:mainfrom
lgeiger:cache-merged-td
May 7, 2026
Merged

Cache merged_typed_dict to not break validate_typed_dict caching#45807
zucchini-nlp merged 2 commits into
huggingface:mainfrom
lgeiger:cache-merged-td

Conversation

@lgeiger

@lgeiger lgeiger commented May 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

#40793 introduced type validation

validate_typed_dict calls the lru-cached _build_strict_cls_from_typed_dict function. However since we re-create merged_typed_dict on every run this cache will always be ignore and recompute strict type dict. This can be slow.

This PR fixes it by also caching the merged_typed_dict creation. Alternatively we could manually validate the two type dicts individually.

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

/cc @zucchini-nlp

Comment thread src/transformers/processing_utils.py Outdated
Comment thread src/transformers/processing_utils.py Outdated
@lgeiger
lgeiger requested a review from zucchini-nlp May 7, 2026 09:52

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❤️

@zucchini-nlp
zucchini-nlp enabled auto-merge May 7, 2026 11:30
@zucchini-nlp
zucchini-nlp added this pull request to the merge queue May 7, 2026
@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.

Merged via the queue into huggingface:main with commit 95fdeb3 May 7, 2026
29 checks passed
@lgeiger
lgeiger deleted the cache-merged-td branch May 7, 2026 12:14
louzongzhi pushed a commit to louzongzhi/transformers that referenced this pull request May 11, 2026
…uggingface#45807)

* Cache `merged_typed_dict` to not break `validate_typed_dict` caching

* Set maxsize=8
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