fix: remove Copied from comments between @torch.jit.script and def for Python 3.13 compat#44986
Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom Mar 25, 2026
Conversation
…f for Python 3.13 compat On Python 3.13, placing a comment between @torch.jit.script and the function definition causes an IndentationError when torch.jit.script calls inspect.getsource() followed by ast.parse(). The stricter parser in Python 3.13 fails to associate the function body with the def when a comment intervenes. Remove the `# Copied from` comments from the three affected functions (c2p_dynamic_expand, p2c_dynamic_expand, pos_dynamic_expand) in both modeling_deberta_v2.py and modeling_sew_d.py, as suggested by the maintainer in issue huggingface#44855. Fixes huggingface#44855
Rocketknight1
approved these changes
Mar 25, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
Yes, LGTM now, thank you for the PR!
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: deberta_v2, sew_d |
|
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. |
zucchini-nlp
pushed a commit
to zucchini-nlp/transformers
that referenced
this pull request
Mar 27, 2026
…r Python 3.13 compat (huggingface#44986) fix: remove `# Copied from` comments between @torch.jit.script and def for Python 3.13 compat On Python 3.13, placing a comment between @torch.jit.script and the function definition causes an IndentationError when torch.jit.script calls inspect.getsource() followed by ast.parse(). The stricter parser in Python 3.13 fails to associate the function body with the def when a comment intervenes. Remove the `# Copied from` comments from the three affected functions (c2p_dynamic_expand, p2c_dynamic_expand, pos_dynamic_expand) in both modeling_deberta_v2.py and modeling_sew_d.py, as suggested by the maintainer in issue huggingface#44855. Fixes huggingface#44855
NielsRogge
pushed a commit
to NielsRogge/transformers
that referenced
this pull request
Mar 30, 2026
…r Python 3.13 compat (huggingface#44986) fix: remove `# Copied from` comments between @torch.jit.script and def for Python 3.13 compat On Python 3.13, placing a comment between @torch.jit.script and the function definition causes an IndentationError when torch.jit.script calls inspect.getsource() followed by ast.parse(). The stricter parser in Python 3.13 fails to associate the function body with the def when a comment intervenes. Remove the `# Copied from` comments from the three affected functions (c2p_dynamic_expand, p2c_dynamic_expand, pos_dynamic_expand) in both modeling_deberta_v2.py and modeling_sew_d.py, as suggested by the maintainer in issue huggingface#44855. Fixes huggingface#44855
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #44855
On Python 3.13, placing a
# Copied fromcomment between@torch.jit.scriptand the function definition causes anIndentationError. This happens becausetorch.jit.scriptcallsinspect.getsource()followed byast.parse(), and Python 3.13's stricter parser fails to associate the function body with thedefwhen a comment intervenes between the decorator and the function signature.As suggested by @Rocketknight1, the fix is to remove the
# Copied fromcomments entirely from these locations. The three affected functions (c2p_dynamic_expand,p2c_dynamic_expand,pos_dynamic_expand) are identical to their source inmodeling_deberta.pyand will remain in sync without the copy markers.Changes
modeling_deberta_v2.py: Removed 3# Copied fromcomments between@torch.jit.scriptdecorators anddefstatementsmodeling_sew_d.py: Removed the same 3# Copied fromcomments (same bug pattern)Coordination
Testing
DebertaV2Modelimports successfully after the changesew_dmodule imports successfully after the changeAI assistance disclosure
This PR was prepared with AI assistance (Claude Code). The change was reviewed line-by-line by the submitter before opening.