Skip to content

Fix regex escape characters in documentation#4363

Open
DrStone1971 wants to merge 1 commit into
pytorch:mainfrom
DrStone1971:patch-1
Open

Fix regex escape characters in documentation#4363
DrStone1971 wants to merge 1 commit into
pytorch:mainfrom
DrStone1971:patch-1

Conversation

@DrStone1971
Copy link
Copy Markdown

Fix for vllm

error:

vllm
/home/tore/.venvs/comfy/lib/python3.12/site-packages/torchao/quantization/quant_api.py:1501: SyntaxWarning: invalid escape sequence '.'
"""Configuration class for applying different quantization configs to modules or parameters based on their fully qualified names (FQNs).

Fix for vllm

vllm
/home/tore/.venvs/comfy/lib/python3.12/site-packages/torchao/quantization/quant_api.py:1501: SyntaxWarning: invalid escape sequence '\.'
  """Configuration class for applying different quantization configs to modules or parameters based on their fully qualified names (FQNs).
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 1, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4363

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures

As of commit 30e1ed4 with merge base 28e6aca (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2026
@DrStone1971
Copy link
Copy Markdown
Author

This PR fixes Python SyntaxWarning caused by invalid escape sequences in docstring regex examples.
The regex examples are documentation-only and now escape backslashes correctly for Python string literals.

@andrewor14
Copy link
Copy Markdown
Contributor

@claude review

@claude
Copy link
Copy Markdown

claude Bot commented May 4, 2026

Claude finished @andrewor14's task in 52s —— View job


Code Review: Fix regex escape characters in documentation

  • Gather context and review the diff
  • Check surrounding code for similar issues
  • Provide review feedback

LGTM

This is a correct and straightforward fix. The docstring at torchao/quantization/quant_api.py:1501 is a regular (non-raw) string, so \. is an invalid escape sequence that triggers a SyntaxWarning in Python 3.12+. The fix correctly doubles the backslashes (\\.) so that the rendered docstring still shows the intended regex pattern \..

Details:

  • Lines 1515, 1517: re:language\.layers\..+\.q_projre:language\\.layers\\..+\\.q_proj — correct
  • No other instances of this issue found in the file
  • The alternative approach would be to make this a raw docstring (r"""..."""), but doubling the backslashes is equally valid and a smaller change

One minor note: On line 1515, the trailing .weight still uses an unescaped . (i.e., q_proj.weight rather than q_proj\.weight). This is technically a regex wildcard, not a literal dot. However, since this is just an illustrative example in documentation and not executed code, it's fine to leave as-is — the PR author's fix addresses the actual SyntaxWarning correctly.


* fully qualified parameter name, e.g. `language.layers.0.q_proj.weight`
* fully qualified module name, e.g. `language.layers.0.q_proj`
* regex for parameter names, must start with `re:`, e.g. `re:language\.layers\..+\.q_proj.weight`.
* regex for parameter names, must start with `re:`, e.g. `re:language\\.layers\\..+\\.q_proj.weight`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel the fix should be add a r in L1501 before """?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

see #3825

can you help test this

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants