Skip to content

fix(deberta-v2): move "Copied from" comments above @torch.jit.script for Python 3.13 compat#44916

Closed
s-zx wants to merge 2 commits intohuggingface:mainfrom
s-zx:fix/44855-deberta-v2-jit-script-comment
Closed

fix(deberta-v2): move "Copied from" comments above @torch.jit.script for Python 3.13 compat#44916
s-zx wants to merge 2 commits intohuggingface:mainfrom
s-zx:fix/44855-deberta-v2-jit-script-comment

Conversation

@s-zx
Copy link
Copy Markdown

@s-zx s-zx commented Mar 21, 2026

Summary

Importing DebertaV2Model (or anything that depends on it, e.g. gliner) raises
IndentationError on Python 3.13 because torch.jit.script calls inspect.getsource(),
dedents the snippet, and passes it to ast.parse(). Python 3.13's stricter parser rejects
a comment placed between a decorator and the def statement.

Root Cause

Three functions in modeling_deberta_v2.py had a # Copied from ... comment between
@torch.jit.script and def:

@torch.jit.script
# Copied from transformers.models.deberta.modeling_deberta.c2p_dynamic_expand
def c2p_dynamic_expand(...):
    ...

Fix

Move each # Copied from comment to the line above its @torch.jit.script decorator:

+# Copied from transformers.models.deberta.modeling_deberta.c2p_dynamic_expand
 @torch.jit.script
-# Copied from transformers.models.deberta.modeling_deberta.c2p_dynamic_expand
 def c2p_dynamic_expand(...):

Applied to all three affected functions (c2p_dynamic_expand, p2c_dynamic_expand,
pos_dynamic_expand).

Fixes #44855

Python 3.13's stricter AST parser (PEP 701 and related parser
tightening) raises IndentationError when ast.parse() encounters a
comment between a decorator and a def statement.

Three functions in modeling_deberta_v2.py had this pattern:
  @torch.jit.script
  # Copied from ...
  def fn(...):

Move each comment to the line immediately above @torch.jit.script to
fix the IndentationError on Python 3.13.

Fixes huggingface#44855
@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: deberta_v2, gpt_neox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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