Repository navigation
[Studio] Try installing causal-conv1d from prebuilt wheels if avialable - #4547
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces an optimization for models that depend on Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant improvement by adding a "fast path" for installing causal-conv1d. It attempts to download and install a pre-built wheel from GitHub releases for specific models, which avoids a slow, blocking source compilation during worker startup. The logic correctly probes the environment to construct the appropriate wheel URL and includes a fallback from uv to pip. Additionally, the blocking installation of mamba-ssm is removed to further improve startup times. My review includes a few suggestions to enhance robustness by using more specific exception handling and ensuring exceptions are logged, even if at a debug level, to aid in future debugging.
fa011a7 to
8b73a56
Compare
4907f88 to
d943551
Compare
This reverts commit d943551.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0330b46ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
… handling
- Add nemotron-h (hyphen) and granite-4.0-h / granitemoehybrid to model
detection for both causal-conv1d and mamba-ssm. These hybrid Mamba models
were silently skipped since nemotron_h (underscore) never matches real
HF model IDs like nvidia/Nemotron-H-8B-Base, and granite was missing
entirely despite being a supported model in model_config.py and loader.py.
- Fix _causal_conv1d_platform_tag to detect linux_aarch64 via
platform.machine() instead of hardcoding linux_x86_64. Both upstream
releases publish aarch64 wheels. Drop win_amd64 since neither repo
publishes Windows wheels (avoids a wasted HTTP probe on every run).
- Pin torch to >=2.6.0,<2.11.0 instead of <=2.10.0 to add a version floor
and document the wheel coverage range with upstream release links.
- Strip non-numeric suffixes from torch minor version so nightly builds
like 2.7a0 correctly resolve to wheel tag torch2.7 instead of torch2.7a0.
- Use stderr=_sp.PIPE instead of stderr=_sp.STDOUT in the env probe so
torch import warnings do not corrupt the JSON output.
- Add timeout=30 to the env probe subprocess to prevent indefinite hangs.
- Catch Exception (not just ImportError) on the existing-install check so
ABI-broken installs with OSError/RuntimeError are retried rather than
silently accepted.
- Guard uv invocation with shutil.which("uv") to prevent FileNotFoundError
crash when uv is not on PATH. Wrap the top-level ensure calls in
try/except so failures do not kill the training worker.
- Hoist _SSM_MODEL_SUBSTRINGS to module level.
- Remove redundant --torch-backend=auto flag from direct wheel URL install.
|
Pushed a fix commit (cd70181) addressing the following: Model detection gaps
Platform tag fix
Torch pin
Error handling
Probe robustness
Minor cleanup
|
- Add "lfm2" to _model_wants_causal_conv1d so Studio picks up the fast kernel path for Liquid Foundation Model 2. - Replace silent logger.warning on SSM dependency install failure with an error event that tells the user to choose another model and stops the training job immediately.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the installation process for causal-conv1d and mamba-ssm by introducing helper functions to manage prebuilt wheel installations via uv or pip, with a fallback to PyPI. It also updates the Python stack installation to pin torch to a compatible version range. Feedback suggests improving the readability and efficiency of model substring checks by using constant sets instead of tuples to avoid duplicates and enhance performance.
| def _model_wants_causal_conv1d(model_name: str) -> bool: | ||
| name = model_name.lower() | ||
| return any( | ||
| key in name | ||
| for key in ( | ||
| "qwen3.5", | ||
| "qwen3_5", | ||
| "qwen3-next", | ||
| "qwen3_next", | ||
| "nemotron_h", | ||
| "nemotron-h", | ||
| "nemotron-3-nano", | ||
| "falcon_h1", | ||
| "falcon-h1", | ||
| "granite-4.0-h", | ||
| "granitemoehybrid", | ||
| "lfm2", | ||
| ) | ||
| ) |
There was a problem hiding this comment.
To improve readability, prevent duplicates, and make the list of model keys reusable, consider extracting it into a constant set. This also resolves the duplicate entries for 'nemotron-h' and 'falcon-h1'. Using a set also provides a minor performance improvement for membership testing.
_CAUSAL_CONV1D_MODEL_SUBSTRINGS = {
"qwen3.5",
"qwen3_5",
"qwen3-next",
"qwen3_next",
"nemotron_h",
"nemotron-3-nano",
"falcon_h1",
"granite-4.0-h",
"granitemoehybrid",
"lfm2",
}
def _model_wants_causal_conv1d(model_name: str) -> bool:
name = model_name.lower()
return any(key in name for key in _CAUSAL_CONV1D_MODEL_SUBSTRINGS)| _SSM_MODEL_SUBSTRINGS = ( | ||
| "nemotron_h", | ||
| "nemotron-h", | ||
| "nemotron-3-nano", | ||
| "falcon_h1", | ||
| "falcon-h1", | ||
| "granite-4.0-h", | ||
| "granitemoehybrid", | ||
| ) |
There was a problem hiding this comment.
This tuple contains duplicate strings ('nemotron-h' and 'falcon-h1'). Using a set instead of a tuple would prevent duplicates and slightly improve performance for the membership check in _ensure_mamba_ssm.
_SSM_MODEL_SUBSTRINGS = {
"nemotron_h",
"nemotron-3-nano",
"falcon_h1",
"granite-4.0-h",
"granitemoehybrid",
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6df5c7a02e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| stdout = _sp.PIPE, | ||
| stderr = _sp.PIPE, | ||
| text = True, | ||
| timeout = 30, |
There was a problem hiding this comment.
Catch torch probe timeouts and continue with fallback
_probe_causal_conv1d_env() uses subprocess.run(..., timeout=30) but does not handle TimeoutExpired. When torch import/probing exceeds 30 seconds (e.g., cold startup on slower disks), the exception bubbles up to run_training_process() step 1b and the worker returns a hard error instead of trying the existing PyPI fallback path. This makes otherwise recoverable startup delays fail training for hybrid-model jobs.
Useful? React with 👍 / 👎.
…tError - _probe_causal_conv1d_env: wrap subprocess.run in try/except for TimeoutExpired so a slow torch import returns None (falls back to PyPI) instead of killing the training job. - _install_package_wheel_first: narrow except Exception to except ImportError on the __import__ check so unexpected errors from a broken module still propagate.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the installation process for causal-conv1d and mamba-ssm packages in studio/backend/core/training/worker.py. The new approach dynamically installs these packages, prioritizing pre-built wheels based on the PyTorch environment and falling back to PyPI if necessary, with added error handling. Additionally, studio/install_python_stack.py is updated to pin the torch stack to a version range compatible with these packages and adjusts the installation step numbering. Feedback includes suggestions to remove duplicate strings in model name lists, simplify redundant type conversions in environment probing, and refactor duplicated installation logic for better maintainability.
| "falcon_h1", | ||
| "falcon-h1", |
| "print(json.dumps({" | ||
| "'python_tag': f'cp{sys.version_info.major}{sys.version_info.minor}', " | ||
| "'torch_mm': torch_mm, " | ||
| "'cuda_major': str(int(str(torch.version.cuda).split('.', 1)[0])) if torch.version.cuda else '', " |
There was a problem hiding this comment.
The conversion str(int(...)) is redundant here. The result of str(torch.version.cuda).split('.', 1)[0] is already the major version string. You can simplify this for better readability and to avoid unnecessary type conversions.
| "'cuda_major': str(int(str(torch.version.cuda).split('.', 1)[0])) if torch.version.cuda else '', " | |
| "'cuda_major': str(torch.version.cuda).split('.', 1)[0] if torch.version.cuda else '', " |
| if shutil.which("uv"): | ||
| uv_cmd = [ | ||
| "uv", | ||
| "pip", | ||
| "install", | ||
| "--python", | ||
| sys.executable, | ||
| "--no-deps", | ||
| wheel_url, | ||
| ] | ||
| result = _sp.run( | ||
| uv_cmd, | ||
| stdout = _sp.PIPE, | ||
| stderr = _sp.STDOUT, | ||
| text = True, | ||
| ) | ||
| if result.returncode == 0: | ||
| installed = True | ||
| else: | ||
| logger.warning( | ||
| "uv failed to install %s wheel:\n%s", | ||
| display_name, | ||
| result.stdout, | ||
| ) | ||
| if not installed: | ||
| pip_cmd = [ | ||
| sys.executable, | ||
| "-m", | ||
| "pip", | ||
| "install", | ||
| "--no-deps", | ||
| wheel_url, | ||
| ] | ||
| result = _sp.run( | ||
| pip_cmd, | ||
| stdout = _sp.PIPE, | ||
| stderr = _sp.STDOUT, | ||
| text = True, | ||
| ) | ||
| if result.returncode == 0: | ||
| installed = True | ||
| else: | ||
| logger.warning( | ||
| "pip failed to install %s wheel:\n%s", | ||
| display_name, | ||
| result.stdout, | ||
| ) |
There was a problem hiding this comment.
The logic for installing with uv and then falling back to pip is very similar and contains duplicated code. This could be refactored into a helper function to improve maintainability and reduce redundancy.
For example, you could create a helper function like _try_install(cmd, installer_name, display_name) that runs the subprocess and handles logging, and then call it for both uv and pip.
The torch>=2.6.0,<2.11.0 pin was added to ensure prebuilt causal-conv1d / mamba-ssm wheels exist, but it runs at install time for all users regardless of model choice. This can downgrade or unnecessarily upgrade torch. The worker already handles wheel compatibility at training time by probing the environment and falling back to PyPI, so the install-time pin is not needed.
…le (unslothai#4547) * Try installing causal-conv1d from prebuilt wheels if avialable * Prefer installing mamba-ssm from wheel to speed up things * undo python stack install changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Revert "undo python stack install changes" This reverts commit d943551. * add comments * Fix wheel installer: model detection, platform tags, torch pin, error handling - Add nemotron-h (hyphen) and granite-4.0-h / granitemoehybrid to model detection for both causal-conv1d and mamba-ssm. These hybrid Mamba models were silently skipped since nemotron_h (underscore) never matches real HF model IDs like nvidia/Nemotron-H-8B-Base, and granite was missing entirely despite being a supported model in model_config.py and loader.py. - Fix _causal_conv1d_platform_tag to detect linux_aarch64 via platform.machine() instead of hardcoding linux_x86_64. Both upstream releases publish aarch64 wheels. Drop win_amd64 since neither repo publishes Windows wheels (avoids a wasted HTTP probe on every run). - Pin torch to >=2.6.0,<2.11.0 instead of <=2.10.0 to add a version floor and document the wheel coverage range with upstream release links. - Strip non-numeric suffixes from torch minor version so nightly builds like 2.7a0 correctly resolve to wheel tag torch2.7 instead of torch2.7a0. - Use stderr=_sp.PIPE instead of stderr=_sp.STDOUT in the env probe so torch import warnings do not corrupt the JSON output. - Add timeout=30 to the env probe subprocess to prevent indefinite hangs. - Catch Exception (not just ImportError) on the existing-install check so ABI-broken installs with OSError/RuntimeError are retried rather than silently accepted. - Guard uv invocation with shutil.which("uv") to prevent FileNotFoundError crash when uv is not on PATH. Wrap the top-level ensure calls in try/except so failures do not kill the training worker. - Hoist _SSM_MODEL_SUBSTRINGS to module level. - Remove redundant --torch-backend=auto flag from direct wheel URL install. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add LFM2 to causal-conv1d detection; stop training on install failure - Add "lfm2" to _model_wants_causal_conv1d so Studio picks up the fast kernel path for Liquid Foundation Model 2. - Replace silent logger.warning on SSM dependency install failure with an error event that tells the user to choose another model and stops the training job immediately. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Catch subprocess timeout in torch probe; narrow import guard to ImportError - _probe_causal_conv1d_env: wrap subprocess.run in try/except for TimeoutExpired so a slow torch import returns None (falls back to PyPI) instead of killing the training job. - _install_package_wheel_first: narrow except Exception to except ImportError on the __import__ check so unexpected errors from a broken module still propagate. * Remove unconditional torch pin from install_python_stack The torch>=2.6.0,<2.11.0 pin was added to ensure prebuilt causal-conv1d / mamba-ssm wheels exist, but it runs at install time for all users regardless of model choice. This can downgrade or unnecessarily upgrade torch. The worker already handles wheel compatibility at training time by probing the environment and falling back to PyPI, so the install-time pin is not needed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
Tested on B200 with torch 2.11 (build from pypi) and 2.9 (install from wheel)
Click to view full logs. Install takes few seconds
H100 logs with new branch