Skip to content

fix: remove Copied from comments between @torch.jit.script and def for Python 3.13 compat#44986

Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom
Krishnachaitanyakc:fix-deberta-v2-jit-script-python313
Mar 25, 2026
Merged

fix: remove Copied from comments between @torch.jit.script and def for Python 3.13 compat#44986
Rocketknight1 merged 1 commit intohuggingface:mainfrom
Krishnachaitanyakc:fix-deberta-v2-jit-script-python313

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

Summary

Fixes #44855

On Python 3.13, placing a # Copied from comment between @torch.jit.script and the function definition causes an IndentationError. This happens because torch.jit.script calls inspect.getsource() followed by ast.parse(), and Python 3.13's stricter parser fails to associate the function body with the def when a comment intervenes between the decorator and the function signature.

As suggested by @Rocketknight1, the fix is to remove the # Copied from comments entirely from these locations. The three affected functions (c2p_dynamic_expand, p2c_dynamic_expand, pos_dynamic_expand) are identical to their source in modeling_deberta.py and will remain in sync without the copy markers.

Changes

  • modeling_deberta_v2.py: Removed 3 # Copied from comments between @torch.jit.script decorators and def statements
  • modeling_sew_d.py: Removed the same 3 # Copied from comments (same bug pattern)

Coordination

Testing

  • Verified DebertaV2Model imports successfully after the change
  • Verified sew_d module imports successfully after the change
  • Ruff linting and formatting checks pass

AI assistance disclosure

This PR was prepared with AI assistance (Claude Code). The change was reviewed line-by-line by the submitter before opening.

…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
Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yes, LGTM now, thank you for the PR!

@Rocketknight1 Rocketknight1 enabled auto-merge March 25, 2026 13:22
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: deberta_v2, sew_d

@Rocketknight1 Rocketknight1 added this pull request to the merge queue Mar 25, 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 2f62491 Mar 25, 2026
22 checks passed
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
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.

IndentationError when importing DebertaV2Model on Python 3.13 - @torch.jit.script fails to parse function with comment between decorator and def

3 participants