Skip to content

Use raw strings and :math: roles for LaTeX in the Stiefel retraction … - #318

Merged
skyw merged 2 commits into
NVIDIA-NeMo:mainfrom
avgvi:fix/raw-string-latex-docstrings
Oct 21, 2026
Merged

skyw merged 2 commits into
NVIDIA-NeMo:mainfrom
avgvi:fix/raw-string-latex-docstrings

Conversation

@avgvi

@avgvi avgvi commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The four retraction docstrings in riemannian_optimizers/retractions/stiefel.py and the ObliqueSteepestSGD docstring are plain """ strings that contain LaTeX in $...$. Python reads the backslashes as escape sequences, which causes three problems:

  • \S, \e and \| are invalid escapes. Compiling stiefel.py prints three SyntaxWarnings, for example on the first import from a source checkout or when examples/nanogpt/train.py starts.
  • \t and \f are valid escapes, so \text turns into a TAB followed by ext, \to into a TAB followed by o, and \frac into a form feed followed by rac. help() and IDE tooltips show the corrupted text.
  • The API reference builds these docstrings as reST through autodoc, and reST has no $...$ math. In a local Sphinx build of docs/, the ObliqueSteepestSGD entry shows $l_1 <TAB>o <TAB>ext{RMS}$ as plain text. Fixing the escapes alone would still render it as $l_1 to text{RMS}$.

This PR makes those docstrings raw strings and writes the math with :math: roles, as the rest of the package does (for example procrustes_step.py:34). Because the strings are now raw, step\\_size becomes step\_size. No code changes.

Before and after

On main:

$ python -W always -c "import emerging_optimizers.riemannian_optimizers.retractions.stiefel"
stiefel.py:68: SyntaxWarning: invalid escape sequence '\S'
stiefel.py:92: SyntaxWarning: invalid escape sequence '\e'
stiefel.py:134: SyntaxWarning: invalid escape sequence '\|'

>>> stiefel.cayley_retraction.__doc__      # excerpts
'$(I - \x0crac{\\eta}{2} A)'               # \f (form feed) + "rac"
>>> ObliqueSteepestSGD.__doc__
' $l_1 \to \text'                          # both \t are real TAB characters

$ ruff check --select W605 emerging_optimizers
Found 11 errors.

Rendered apidocs/riemannian-optimizers.html on main:

Oracle (LMO) with respect to the $l_1       o       ext{RMS}$ norm constraint.

With this change:

$ python -W error::SyntaxWarning -c "import emerging_optimizers.riemannian_optimizers.retractions.stiefel"
$ ruff check .
All checks passed!
Oracle (LMO) with respect to the <span class="math">\(l_1 \to \text{RMS}\)</span> norm constraint.

Verification

  • tests/test_normalized_optimizer.py: 36 OK
  • tests/test_isospectral.py: 17 OK
  • tests/test_spel.py: 32 OK
  • sphinx-build -b html docs docs/_build/html: no new warnings
  • pre-commit run --files <changed files>: all hooks pass

…and ObliqueSteepestSGD docstrings

Signed-off-by: August Vi <augustvilakia@gmail.com>
@avgvi
avgvi requested a review from a team as a code owner October 21, 2026 02:43
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Fixes LaTeX in five docstrings without changing optimizer behavior.

  • Optimizer docstrings preserve their formulas and show them as math.

Reviews (2) · Last reviewed commit: "Drop the W605 lint rule" · Reviewed by Greptile

@skyw skyw added the docs-only With great power comes great responsibility. label Oct 21, 2026
@skyw

skyw commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Dropping W605 change can make review simpler

Signed-off-by: August Vi <augustvilakia@gmail.com>
@avgvi

avgvi commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@skyw Hey I dropped W605 change

@skyw
skyw removed the request for review from a team October 21, 2026 22:28
@skyw

skyw commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

/ok to test 898505b

@skyw
skyw merged commit aa32262 into NVIDIA-NeMo:main Oct 21, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-only With great power comes great responsibility.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants