Repository navigation
Studio: make the install-time bytecode precompile opt-in - #15923
Conversation
Windows Defender scans every .pyc written during an update, so the post-install precompile from #15646 made Windows updates slower. Python already compiles each module lazily on first import, which spreads that cost over the imports a launch actually makes. setup.ps1 now runs studio/precompile_bytecode.py only when UNSLOTH_STUDIO_COMPILE_BYTECODE (or UV_COMPILE_BYTECODE) is true, and the helper itself defaults to off on Windows with the same opt-in. A false value still wins. Linux, macOS and WSL are unchanged.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
v0.1.912-beta shipped the post-install bytecode precompile from #15646. It made
unsloth studio updateand Desktop updates slower on every desktop OS: every update re-runs setup, which compiles a.pycfor every module in the Studio venv (about 25,000 files, including packages whose versions did not change). On Windows, Defender real-time protection also scans each newly written file. Python already compiles each module lazily the first time it is imported and caches it in__pycache__, which spreads the same work over only the modules a launch actually loads.This turns the precompile off by default on every OS and keeps it as an opt-in.
What changes
studio/setup.ps1andstudio/setup.sh: the "Precompile bytecode" step runs only whenUNSLOTH_STUDIO_COMPILE_BYTECODE(orUV_COMPILE_BYTECODE) is true (1,true,yes,on, case and whitespace insensitive). A false value on either name still wins. Without the opt-in the step prints nothing and starts no process.studio/precompile_bytecode.py: the helper itself also defaults to off with the same opt-in, so a direct call behaves the same way as setup.Opt-in
Results: 911 to 912 Desktop update, precompile on (main) vs off (this PR)
Same update command and environment the 911 Desktop app runs, on the staging runners (CPU torch). "Net saved" is the update time saved minus the extra time of the first backend
import mainafterwards, which now compiles on demand.import main, precompiled / lazyThe precompile phase was 41 to 52% of the whole update on every runner, and 20 to 30% of a fresh install. Modules imported later in a session also compile on first use and are not counted in the import column.
What is unchanged
UV_COMPILE_BYTECODEis not set by any installer), andUV_COMPILE_BYTECODE_TIMEOUTininstall.sh/install.ps1stays as is..pycas a readiness signal: Studio: precompile bytecode after setup so the first launch does not #15646 only added the helper, its two call sites, tests and the parity workflow path filter. No launch timeout, health check orverify-installstep depends on it.__pycache__(for example a per-machine install under Program Files), the import still succeeds and the module is compiled in memory on each launch, the same behaviour as before Studio: precompile bytecode after setup so the first launch does not #15646.Tests
tests/python/test_installer_compile_bytecode.py:setup.ps1block (under PowerShell) and thesetup.shblock (under bash) do not call the helper with no switch set or after no dependency pass, and do call it forUNSLOTH_STUDIO_COMPILE_BYTECODE=1/OnandUV_COMPILE_BYTECODE=true/1; a false on either name wins over a true;The new default-off cases fail on
main; on this branchtest_installer_compile_bytecode.py,test_installer_interactive_prompts.py(143 passed together) andtests/python/test_cross_platform_parity.py(119 passed) pass.Windows detail: Defender exclusions removed (911 to 912 Desktop update)
Same update command and environment the 911 Desktop app runs, then the 912 installer with
/S /UPDATE; two runs per arm. "Defender on" = the runner's drive exclusions removed and real-time protection enabled before the update.import maintimed twice from the installed backend afterwards. Runner speed varies between jobs, so compare within a row pair.import main(s)The precompile writes about 25,000
.pycfiles for the whole venv on every update, including packages whose versions did not change. Skipping it moves about 7 s (Defender off) or 16 to 18 s (Defender on) to the first backend import after the update, for a net saving of about 36 to 73 s (off) and 60 to 130 s (on). Modules imported later in a session also compile on first use and are not counted here.