[CuTe DSL] Fix REPL crash: clear diagnostic and keep the interpreter alive (issue #3413) - #3424
Open
layahaasini wants to merge 2 commits into
Open
[CuTe DSL] Fix REPL crash: clear diagnostic and keep the interpreter alive (issue #3413)#3424layahaasini wants to merge 2 commits into
layahaasini wants to merge 2 commits into
Conversation
layahaasini
force-pushed
the
fix/cutedsl-repl-crash-3413
branch
from
July 30, 2026 21:28
2cbcd71 to
9094546
Compare
A @cute.jit function defined in the REPL (or via exec()) has no retrievable source, which raised an "[Internal Error] this is a bug in the DSL" envelope and then killed the whole interactive session via the DSL excepthook's unconditional sys.exit(1). - Raise a user-facing DSLUserCodeError (new DiagId.UNSUP_NO_SOURCE) for the no-source case, keeping DSLRuntimeError for real parse failures - Skip sys.exit(1) in the excepthook for interactive sessions; script exit status is unchanged Fixes NVIDIA#3413
layahaasini
force-pushed
the
fix/cutedsl-repl-crash-3413
branch
from
July 30, 2026 21:36
9094546 to
575cf49
Compare
layahaasini
marked this pull request as ready for review
July 30, 2026 21:40
Contributor
|
LGTM, thanks for contributing |
brandon-yujie-sun
approved these changes
Aug 3, 2026
brandon-yujie-sun
left a comment
Collaborator
There was a problem hiding this comment.
LGTM with a couple comments, and thanks for contributing the changes!
| print(str(exc_value), file=sys.stderr) | ||
| sys.exit(1) | ||
| # Don't kill an interactive session (REPL, `python -i`) | ||
| if not (hasattr(sys, "ps1") or sys.flags.interactive): |
Collaborator
There was a problem hiding this comment.
Besides -i, can we also cover the PYTHONINSPECT=1 case which sets sys.flags.inspect?
| f"Failed to parse function {func_name}", | ||
| suggestion="DSL does not support REPL mode, save the function to a file instead.", | ||
| ) | ||
| except OSError as e: |
Collaborator
There was a problem hiding this comment.
Seems OSError might not be enough: https://docs.python.org/3/library/inspect.html#inspect.getsourcelines Can we also handle the TypeError?
…rom getsourcelines
Author
|
Done, thanks for the feedback! |
Collaborator
|
@Junkai-Wu for further proceeding. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3413
Calling a
@cute.jitfunction defined in the REPL (or viaexec()) causes 2 problems:DSLRuntimeError, rendering as "[Internal Error] This is a bug in the DSL ... please report this". It isn't a DSL bug, REPL is a known unsupported case ([BUG] Cutlass Python DSL: could not get source code #2636 says a clear message was added for it in 4.3, but it doesn't reach the user because of the error class).sys.exit(1), so the uncaught error kills the whole interactive session instead of returning to the prompt. Same thing happens when debugging a normal file-based kernel withpython -i.Changes:
ast_preprocessor.py: catchOSErrorfrominspect.getsourcelinesseparately and raiseDSLUserCodeErrorwith a new catalog entryUNSUP_NO_SOURCE("save the function to a .py file"). Other parse failures still raiseDSLRuntimeError, now with the cause chained.common.py: skip thesys.exit(1)in_dsl_excepthookwhen the session is interactive. Scripts still exit 1 on uncaught DSL errors.This doesn't add REPL support, it just makes the failure behave as intended.
With the patch, the repro from the issue now gives:
Tested against the 4.6.1 wheel on a DGX Spark (GB10): the two new regression tests in
test/python/CuTeDSL/test_no_source_diagnostics.pyfail on the stock wheel and pass with the patch; a third checks script exit status is unchanged. Also verified a normal file-based kernel still compiles and launches.Note: #3396 touches the same
exceptblock for a different bug (stale on-disk source), small rebase likely needed