Repository navigation
Conversation
Submissions can leave files next to themselves, and warm Modal containers serve many users. Mojo submissions in particular write their .mojo source and a __mojocache__ build next to submission.py, which the next submission in the same container could read. Each run_pytorch_script call now runs in a temporary directory that is removed afterwards.
Mojo submissions stay ordinary Python submissions: submission.py embeds the Mojo source, compiles it with mojo.importer, and exposes custom_kernel. The platform changes are: - Install a pinned max package (Mojo compiler, mojo.importer, MAX GPU libs) in the Modal image, so submissions no longer need a runtime pip install. - Accept Mojo starter templates in task definitions and the Discord template command. - Add a vectoradd example that launches on PyTorch's current stream via DeviceContext.create_external_stream. Mojo's default stream only works with evaluators that use the legacy default stream; side streams and CUDA graph capture miss the kernel otherwise. - Cover the example in Modal integration tests: test mode on T4 and H100, a ranked run with a bandwidth lower bound on timings, and a side-stream and CUDA-graph check. Co-authored-by: M. Tolga Cangöz <mtcangoz@gmail.com>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||
tolgacangoz
reviewed
Nov 23, 2026
Comment on lines
+69
to
+74
| # Launch on PyTorch's current stream so ordering and CUDA-event timing | ||
| # match the evaluator. | ||
| var stream = self_ptr[].ctx.create_external_stream( | ||
| Pointer[NoneType, MutUntrackedOrigin](unsafe_from_address=Int(py=stream_py)) | ||
| ) | ||
| stream.enqueue_function( |
There was a problem hiding this comment.
Shouldn't we avoid using any word having "stream" 🤔?
kernelbot/src/kernelbot/api/api_utils.py
Lines 271 to 275 in 7f720fd
|
Thanks a bunch for getting this over to the completion, Mark! |
This branch has not been deployed
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.
Supersedes #533 by @tolgacangoz. The approach is theirs: Mojo lives inside a normal
submission.pyand is compiled withmojo.importer. The commits credit them as co-author. This PR adds fixes found by running it end to end on Modal.Approach
Mojo submissions are still Python submissions.
submission.pyembeds the Mojo source, imports it throughmojo.importer, and exposescustom_kernel. Nothing between the CLI and the Modal function had to change: the.pyextension check,#!POPCORNdirectives, KernelGuard, CPU precompile (skipped because there is noload_inline), andlang: pyrouting all work as they are.Changes
max==26.7.0is pinned in the Modal image, with amojo.importer/mojo --versionsmoke check. Without it, a submission has to pip install at runtime, which gets flagged ashacked. It is pinned because Mojo syntax still changes between releases.DeviceContext.create_external_stream. The version in Propose to add Mojo🔥-based kernels #533 launches on Mojo's own stream. That only works because the PMPP eval uses the legacy default stream. Under a side stream it races, and under CUDA graph capture the graph comes out empty ("The CUDA Graph is empty"). The Helion eval uses both. The new example also uses a plainimportinstead ofimportlib, so KernelGuard now classifies it asvalid(Propose to add Mojo🔥-based kernels #533's version wassuspiciousunder--profile strict).mojo.importerneeds the.mojofile on disk and writes__mojocache__next to it.run_pytorch_scriptused to remove only the files it created itself, and GPU containers are reused across users. So the next submission in a warm container could read the previous user's Mojo source. Each run now gets a temporary working directory that is deleted afterwards.Mojois accepted as a template language intask.ymland in the Discord template command (from Propose to add Mojo🔥-based kernels #533).Tests
tests/test_run_eval.py, which fails onmain, and a Mojo template case intests/test_task.py.test_modal_launcher_python_script(T4, H100).test_modal_mojo_leaderboard: H100 ranked run. Its timing must be above a lower bound set by memory bandwidth.test_modal_mojo_uses_torch_current_stream: side-stream and CUDA-graph-replay check.Verified before opening
I ran
modal_run_configon the realcuda_imagefrom this branch (KERNELBOT_NVCC_TOOLCHAIN=0, ephemeral app, separate Modal workspace):.mojofiles remained under/rootor/tmpafter any run.custom_kernelcall is about 11 µs, so no DLPack conversion is involved.Not covered
max..mojofile submissions are not supported. That would break the Python-only assumption in the extension check, KernelGuard, CPU precompile, the website editor, and the CLI.