Skip to content

Raise on stale source in DSL jit preprocessing - #3522

Open
VaggelisGian wants to merge 1 commit into
NVIDIA:mainfrom
VaggelisGian:fix-dsl-loud-stale-source
Open

Raise on stale source in DSL jit preprocessing#3522
VaggelisGian wants to merge 1 commit into
NVIDIA:mainfrom
VaggelisGian:fix-dsl-loud-stale-source

Conversation

@VaggelisGian

Copy link
Copy Markdown

Summary

Fixes #3395

The jit preprocessor re-reads function sources from disk at first compile and slices at the code object's recorded line number. When the module source changed after import, two silent failure modes existed:

  1. the re-read slice no longer starts with the DSL decorator, transform_function returned [], and the function was silently skipped from staging;
  2. downstream code replacement failed with the cryptic ValueError: kernel_fn() requires a code object with 0 free vars.

ast_preprocessor.transform_function now raises DSLUserCodeError naming the stale file when the re-read slice does not start with the decorator, covering both cases with one loud error at the right place.

Programmatic decoration without a matching source decorator also raises loudly now (it was never staged before either); aliased decorators (jj = cute.jit) take the same path.

Test plan

New test/python/CuTeDSL/test_stale_source.py (3 tests, CPU-only): a module whose source changed after import raises the new loud error naming the file; unmodified modules compile normally; a failed-then-restored source compiles again (no preprocessor state poisoning).

Run in a python:3.12-slim container against this branch (wheel natives bridged, branch tree first on sys.path):

Ran 3 tests in 0.356s

OK

With only ast_preprocessor.py reverted to the parent commit, same environment:

Ran 3 tests in 0.049s

FAILED (errors=3)

End-to-end repro of issue case 2 before the fix:

ValueError: kernel_add() requires a code object with 0 free vars, not 2

after the fix the failure names the stale file and suggests re-importing it.

The jit preprocessor re-reads function sources from disk at first
compile and slices at the code object's recorded line number. When a
module changed after import, for example an in-place package upgrade
while a long-lived process kept the old modules loaded, the slice no
longer starts with the decorated definition. The preprocessor then
silently skipped staging and the kernel failed later far from the
cause, with a NameError from unstaged execution or a ValueError about
free variables during code replacement.

Turn that case into an immediate error naming the file whose source
went stale. Functions decorated programmatically without a decorator
in their source take the same path; they were never staged before
either, so nothing that worked regresses.

Add test/python/CuTeDSL/test_stale_source.py covering slices landing
on an undecorated def, on an import line, and recovery once the file
matches again.

Test Plan:
  docker python:3.12-slim, editable install of python/CuTeDSL:
    module modified after import, unfixed code:
      ValueError: kernel_fn() requires a code object with 0 free vars, not 2
    fixed code: immediate error naming mod_under_test.py and suggesting
      a process restart
    python test/python/CuTeDSL/test_stale_source.py -v:
      Ran 3 tests ... OK (all three fail on unfixed code)
    unmodified module still compiles
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.

[BUG][CuTe DSL] Stale source after import breaks lazy jit preprocessing silently

1 participant