Skip to content

Feat: add unsloth skill, fix cli - #4443

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
TimPietrusky:feat/cli-fixes-and-skill
Sep 8, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
TimPietrusky:feat/cli-fixes-and-skill

Conversation

@TimPietrusky

@TimPietrusky TimPietrusky commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

summary

adds an agent skill (skills/unsloth/SKILL.md) so that any ai coding agent can use the unsloth cli without trial-and-error exploration. covers training, inference, export, and studio commands with config templates and gotchas.

eval results: 100% correctness with skill vs 93% without, 31% fewer tokens, 49% less time.

cli fixes found while testing the skill

  • list-checkpoints and export crashed with ModuleNotFoundError: No module named 'loggers' — venv re-exec wasn't adding studio/backend/ to the python path
  • --local-dataset cli flag was broken — Optional[List[str]] wasn't detected as a list type, leaked through as a string flag
  • inference didn't work on macOS — added GGUF model routing to llama-server

test plan

  • all cli commands work after fixes
  • fresh venv install verified
  • 7/7 unit tests pass
  • automated skill evals pass

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2b923de15

ℹ️ 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".

Comment thread cli/commands/studio.py Outdated
existing = env.get("PYTHONPATH", "")
env["PYTHONPATH"] = f"{backend_dir}{os.pathsep}{existing}" if existing else backend_dir

args = [str(studio_python), "-m", "cli", *command_args]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Re-exec the checkout's CLI instead of the Studio wheel

When an existing ~/.unsloth/studio/.venv is present, this launches python -m cli, but studio/install_python_stack.py:299-305 installs unsloth from studio/backend/requirements/base.txt:1-3 into that venv. Because the re-exec only adds studio/backend to PYTHONPATH, the child process imports the packaged cli module from the venv rather than the current checkout, so users keep running stale command handlers (or an older wheel that lacks cli.__main__) until they rerun unsloth studio setup after every CLI change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the rebase — now uses -m unsloth_cli instead of -m cli.

Comment thread unsloth_cli/commands/train.py Outdated
@@ -33,6 +35,8 @@ def train(
config_overrides: dict = None,
):
"""Launch training using the existing Unsloth training backend."""
_reexec_cli_in_studio_venv(sys.argv[1:])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not require Studio setup for train --dry-run

This re-execs before the config is even loaded, but the dry_run branch at lines 59-65 only dumps the resolved YAML and exits; it never touches the Studio backend. On a fresh install or CI machine without ~/.unsloth/studio/.venv, unsloth train --dry-run now exits with "Studio not set up" instead of validating and printing the config, which regresses a lightweight workflow that worked before this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Moved _reexec_cli_in_studio_venv after the dry-run exit in 2ab03d3, so unsloth train --dry-run now works without studio setup.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +121 to +122
with_response = (eval_dir / "with_skill" / "outputs" / "response.md").read_text()
without_response = (eval_dir / "without_skill" / "outputs" / "response.md").read_text() if without_result else "N/A"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard grading against missing eval outputs

run_claude() returns {"error": ...} on timeout/JSON-parse failures and, in those cases, never writes response.md, but run_grader() unconditionally reads both response files here. If either the with-skill or baseline run fails, the benchmark crashes with FileNotFoundError during grading instead of recording a failed run and continuing, so a single flaky eval aborts the whole comparison run.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ab03d3 — run_grader now checks if response.md exists before reading. Failed/timed-out runs get (run failed — no output) instead of crashing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2b923de15

ℹ️ 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".

Comment thread cli/commands/studio.py Outdated
existing = env.get("PYTHONPATH", "")
env["PYTHONPATH"] = f"{backend_dir}{os.pathsep}{existing}" if existing else backend_dir

args = [str(studio_python), "-m", "cli", *command_args]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Re-exec the checkout's CLI instead of the Studio wheel

When an existing ~/.unsloth/studio/.venv is present, this launches python -m cli, but studio/install_python_stack.py:299-305 installs unsloth from studio/backend/requirements/base.txt:1-3 into that venv. Because the re-exec only adds studio/backend to PYTHONPATH, the child process imports the packaged cli module from the venv rather than the current checkout, so users keep running stale command handlers (or an older wheel that lacks cli.__main__) until they rerun unsloth studio setup after every CLI change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix — resolved in the rebase, now uses -m unsloth_cli.

Comment thread unsloth_cli/commands/train.py Outdated
@@ -33,6 +35,8 @@ def train(
config_overrides: dict = None,
):
"""Launch training using the existing Unsloth training backend."""
_reexec_cli_in_studio_venv(sys.argv[1:])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not require Studio setup for train --dry-run

This re-execs before the config is even loaded, but the dry_run branch at lines 59-65 only dumps the resolved YAML and exits; it never touches the Studio backend. On a fresh install or CI machine without ~/.unsloth/studio/.venv, unsloth train --dry-run now exits with "Studio not set up" instead of validating and printing the config, which regresses a lightweight workflow that worked before this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ab03d3 — _reexec_cli_in_studio_venv now runs after the dry-run check.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +121 to +122
with_response = (eval_dir / "with_skill" / "outputs" / "response.md").read_text()
without_response = (eval_dir / "without_skill" / "outputs" / "response.md").read_text() if without_result else "N/A"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard grading against missing eval outputs

run_claude() returns {"error": ...} on timeout/JSON-parse failures and, in those cases, never writes response.md, but run_grader() unconditionally reads both response files here. If either the with-skill or baseline run fails, the benchmark crashes with FileNotFoundError during grading instead of recording a failed run and continuing, so a single flaky eval aborts the whole comparison run.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix — grader now guards against missing response files.

@TimPietrusky
TimPietrusky marked this pull request as draft March 18, 2026 20:45
@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from b2b923d to 5df7fc5 Compare March 18, 2026 20:53
@TimPietrusky TimPietrusky changed the title Fix CLI venv re-exec, GGUF inference routing, and add agent skill Feat: add unsloth skill, fix cli Mar 18, 2026
@TimPietrusky
TimPietrusky marked this pull request as ready for review March 18, 2026 21:00
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ded3b48af

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +252 to +254
for config, res in [("with_skill", with_res), ("without_skill", without_res)]:
if not res or "error" in res:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record failed eval runs instead of dropping them

If either Claude invocation times out or returns invalid JSON, build_benchmark() skips that configuration entirely here. That makes benchmark.json and the printed deltas look healthier than reality—for example, a timed-out with_skill run disappears and the summary is computed only from the surviving baseline runs. Please emit a run entry with errors > 0 and a zero pass rate so failures count against the benchmark instead of being silently ignored.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bf59c63 — failed/timed-out runs now emit a run entry with errors: 1 and zero pass rate instead of being skipped.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca1a77e60b

ℹ️ 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".

Comment thread unsloth_cli/commands/studio.py Outdated
Comment on lines +130 to +134
env["PYTHONPATH"] = (
f"{backend_dir}{os.pathsep}{existing}" if existing else backend_dir
)

args = [str(studio_python), "-m", "unsloth_cli", *command_args]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the checkout root to PYTHONPATH before re-exec

Fresh evidence after the rebase: this still only prepends studio/backend before launching python -m unsloth_cli. studio/install_python_stack.py installs unsloth into ~/.unsloth/studio/.venv, so when a developer runs unsloth from any cwd outside the repo root, the child process will import the venv wheel's unsloth_cli instead of the checkout they are testing. That means CLI changes in this PR are silently ignored until Studio setup is rerun, so the original stale-code problem still exists for a common development workflow.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e2e2a31 — now adds both the checkout root and studio/backend to PYTHONPATH, so the re-exec'd process imports unsloth_cli from the local checkout instead of a stale venv wheel.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +217 to +219
result = subprocess.run(
cmd, capture_output = True, text = True, timeout = 120, cwd = str(REPO_ROOT)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Catch grading timeouts and keep the benchmark running

run_grader() uses subprocess.run(..., timeout=120) without handling TimeoutExpired. If any grading call hangs or is just slower than two minutes, the exception escapes and the whole eval script aborts before benchmark.json is written, even though the per-run execution path already treats timeouts as recoverable. In practice this makes a single flaky grader response kill the entire benchmark iteration.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e2e2a31 — run_grader now catches TimeoutExpired and returns empty grading instead of crashing the script.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +257 to +259
expectations = g.get("expectations", [])
passed = 0 if is_error else sum(1 for e in expectations if e.get("passed"))
total = len(expectations) or (1 if is_error else 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark ungraded runs as unavailable instead of 0%

When grading is skipped (--skip-grading) or a grader parse failure leaves expectations empty, successful runs fall into this branch with is_error == False, so total becomes 0 and the emitted pass_rate is forced to 0 a few lines later. That makes benchmark.json and the printed summary report a failed eval even though nothing was graded, which corrupts the experiment results rather than signaling that the score is unavailable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e2e2a31 — ungraded runs now emit pass_rate: null (filtered from stats) instead of a misleading 0%.

@danielhanchen

Copy link
Copy Markdown
Member

Thanks so much @TimPietrusky ! :)

@TimPietrusky

Copy link
Copy Markdown
Contributor Author

@danielhanchen while creating the skill and testing it, i found a couple of things that need to be changed in order for the skill to work. if this pr is too large to review, i can also split it, but those changes are needed to make the skill work.

@rolandtannous

Copy link
Copy Markdown
Contributor

@TimPietrusky great work! can you elaborate on the changes?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8d2a944b9

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +296 to +297
if not vals:
return {"mean": 0, "min": 0, "max": 0}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve missing-baseline stats instead of zero-filling

When this runner is invoked with its advertised --skip-baseline mode, without_runs is empty, but stats() still returns {mean: 0, min: 0, max: 0} and the delta block below compares the with-skill run against those zeros. That makes benchmark.json and the printed summary report fake improvements in pass rate, tokens, and time even though no baseline was executed, which corrupts the comparison for a supported workflow.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2034a86 — stats() returns None when no runs exist, delta is skipped entirely when baseline is missing. No more fake improvements from zero-filled stats.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +33 to +36
- unsloth CLI is installed at /opt/homebrew/bin/unsloth (version 2026.3.5)
- Studio venv exists at ~/.unsloth/studio/.venv (Python 3.11)
- Use pip3, not pip.
- `unsloth studio setup` is already done in this environment. Only run it if the task explicitly requires verifying setup behavior.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop telling the fresh-setup eval that Unsloth is installed

These environment hints are prepended to every eval prompt, including setup-fresh in skills/unsloth/evals/evals.json:22-37. That case is supposed to measure a clean-machine install, but the agent is explicitly told that unsloth is already installed, the Studio venv already exists, and setup is already done, so it can legitimately skip the very install/setup actions the grader expects. This makes the fresh-install benchmark unreliable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2034a86 — split ENV_CONTEXT into base context (all evals) and ENV_CONTEXT_INSTALLED (appended only for non-fresh evals). setup-fresh no longer gets told that unsloth is already installed.

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from 2034a86 to 5777037 Compare March 19, 2026 08:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

"Error: provide --dataset or --local-dataset (or via --config)", err = True

P2 Badge Stop suggesting the removed --local-dataset flag

This validation path still tells users to pass --local-dataset, but this commit's options.py change deliberately removed list-valued CLI flags, so Typer now rejects that option. In the new local-JSONL workflow, a user who follows this error message immediately hits No such option: --local-dataset instead of being directed to the YAML --config path that actually works.

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
eval_id: str = "",
) -> dict:
"""Run a single eval via claude -p and return the JSON result."""
output_dir.mkdir(parents = True, exist_ok = True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear previous outputs before reusing an iteration directory

run_claude() now reuses output_dir as-is. If someone reruns the same --iteration and the current Claude call times out or returns invalid JSON, this function exits before overwriting response.md, so run_grader() later reads the stale file from the previous attempt and scores the failed run as if it had succeeded. That corrupts benchmark.json for retry/partial-rerun workflows.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9e8cb63 — run_claude() now clears the output directory before each run, so stale response.md files from previous attempts can't leak into grading.

Comment thread skills/unsloth/evals/run_evals.py Outdated
ENV_CONTEXT = """
CONTEXT about the environment:
- Working directory: {repo_root}
- Mac M4, no NVIDIA GPU. Full Unsloth training does not work here, but dry-run flows do. GGUF inference does work on this machine.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect the eval machine instead of hard-coding Mac-only context

Every eval prompt now tells Claude it is on a "Mac M4, no NVIDIA GPU" box where full training cannot work and GGUF inference does. On any Linux/CUDA runner, CI host, or Windows machine, that steers both the skill and baseline agents away from capabilities that actually exist (or toward ones that do not), so tasks like train-and-export no longer measure the real environment and the benchmark results become misleading outside the author's laptop.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9e8cb63 — ENV_CONTEXT now auto-detects platform (platform.system() + machine()) and GPU (checks nvidia-smi) instead of hardcoding Mac M4.

@TimPietrusky

Copy link
Copy Markdown
Contributor Author

@rolandtannous the main goal was to add an agent skill (skills/unsloth/SKILL.md) so that any ai coding agent can use the unsloth cli without trial-and-error exploration. it covers training, inference, export, and studio commands with config templates and gotchas. i ran automated evals comparing agent performance with vs without the skill: 100% correctness with skill vs 93% without, 31% fewer tokens, 49% less time.

while building and testing the skill on macOS (M4), i found and fixed several cli issues:

  • list-checkpoints and export crashed with ModuleNotFoundError: No module named 'loggers' — the venv re-exec wasn't adding studio/backend/ to the python path
  • --local-dataset cli flag was broken — Optional[List[str]] wasn't being detected as a list type, so it leaked through as a string flag that caused pydantic errors
  • inference didn't work on macOS — added GGUF model routing to llama-server so cpu/mac inference works without a gpu

these fixes were needed to make the skill accurate.

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from 224ae99 to 9b07394 Compare March 19, 2026 09:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec13e9acab

ℹ️ 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".

Comment thread unsloth_cli/commands/studio.py Outdated
Comment on lines +129 to +133
checkout_root = str(_PACKAGE_ROOT)
env = os.environ.copy()
existing = env.get("PYTHONPATH", "")
extra = f"{checkout_root}{os.pathsep}{backend_dir}"
env["PYTHONPATH"] = f"{extra}{os.pathsep}{existing}" if existing else extra

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop prepending an installed site-packages root to PYTHONPATH

_PACKAGE_ROOT is only a checkout root for editable installs; in a normal pip install unsloth it resolves to the caller's site-packages directory. Prepending that whole directory here makes the studio child import outer-environment packages before its own, so a CLI installed under Python 3.9/3.10 (allowed by pyproject.toml) can re-exec into the 3.11-3.13 Studio venv (studio/setup.sh) and then pick up incompatible wheels or stale pure-Python deps from the outer env. This turns the stale-code fix into a cross-environment import bug for packaged installs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 53a4423 — checkout root is now only added to PYTHONPATH for editable installs (detected by checking for pyproject.toml in _PACKAGE_ROOT). For normal pip install unsloth, only studio/backend is added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 53a4423 — _PACKAGE_ROOT is now only prepended to PYTHONPATH for editable installs (detected via .dist-info/direct_url.json). Normal pip installs no longer pollute the Studio venv's import path.

Comment thread skills/unsloth/evals/evals.json Outdated
"id": "setup-fresh",
"prompt": "Install Unsloth from scratch and set up the Studio environment. This is a clean machine with nothing installed.",
"expectations": [
"Runs pip install unsloth (or pip install -e . if in repo)",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept the documented uv install flow in setup-fresh

run_grader() scores this benchmark from the free-form expectations text, and this expectation only treats pip install unsloth / pip install -e . as correct. The repo's own install docs use uv pip install unsloth --torch-backend=auto on a clean machine, so an agent that follows the documented setup path can be graded as failing setup-fresh even though it did the right thing. That makes benchmark.json and the claimed accuracy for this eval unreliable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 53a4423 — setup-fresh expectation now accepts pip install, pip install -e ., and uv pip install unsloth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 53a4423 — setup-fresh eval expectations now accept uv pip install unsloth alongside pip install unsloth.

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from 53a4423 to 18b7d60 Compare March 19, 2026 09:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25169bcf4a

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
"passed": passed,
"failed": total - passed,
"total": total,
"time_seconds": res.get("total_duration_seconds", 0),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve timeout durations in benchmark results

When run_claude() times out it returns only duration_ms, but this summary path records time_seconds from total_duration_seconds and falls back to 0. In timeout/error scenarios, benchmarks therefore underreport runtime (showing zero seconds) and can produce misleading speed deltas. Use duration_ms as a fallback (converted to seconds) for error runs so timeout-heavy iterations are measured accurately.

Useful? React with 👍 / 👎.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +302 to +303
if grading_file.exists():
grading = json.loads(grading_file.read_text())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore stale grading files when grading is skipped

This always loads any existing grading.json for an iteration, even when the current run used --skip-grading (or grading failed and produced no new file). If a user reuses --iteration, old grading data is silently applied to new outputs, so pass/fail metrics can reflect a previous run instead of the current one. Clear/overwrite grading artifacts per run or bypass loading stale grading when no fresh grading step ran.

Useful? React with 👍 / 👎.

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from 25169bc to 79ca5a0 Compare March 26, 2026 21:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfebcb7153

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +95 to +96
if eval_id != "setup-fresh":
ctx += "\n" + ENV_CONTEXT_INSTALLED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude all fresh-install evals from installed-env context

Fresh evidence after the earlier setup-fresh fix: this commit adds setup-fresh-docker and setup-fresh-windows in skills/unsloth/evals/evals.json, but this guard still only exempts setup-fresh. As a result, those fresh-machine evals are told that unsloth and studio setup already exist, which conflicts with their prompts and can let runs skip installation while still being graded, skewing benchmark correctness.

Useful? React with 👍 / 👎.

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +439 to +440
for eval_entry in evals:
eval_id = eval_entry["id"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip Windows-only evals on non-Windows hosts

The runner executes every eval ID unconditionally in this loop, so setup-fresh-windows is attempted on Linux/macOS too. That eval’s note in skills/unsloth/evals/evals.json says it should be skipped outside Windows, so default runs on non-Windows machines include an impossible task and artificially lower pass-rate comparisons unrelated to skill behavior.

Useful? React with 👍 / 👎.

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from cfebcb7 to aabdd5b Compare March 26, 2026 22:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52d05818fe

ℹ️ 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".

Comment thread unsloth_cli/commands/inference.py Outdated
Comment on lines +15 to +16
if system_prompt:
messages.append({"role": "system", "content": system_prompt})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid double-injecting system prompts in standard inference

When --system-prompt is set, this helper adds a system message into messages, and the non-GGUF path also passes system_prompt separately to generate_chat_response. In studio/backend/core/inference/inference.py, that backend prepends system_prompt to messages again, so standard inference receives the same system instruction twice. This can materially skew outputs for prompt-sensitive runs; keep system text in only one channel for the non-GGUF path.

Useful? React with 👍 / 👎.

@TimPietrusky

Copy link
Copy Markdown
Contributor Author

@rolandtannous @danielhanchen Rebased cleanly on latest main — no more conflicts. Changes are now in 3 commits:

  1. CLI venv re-exec, GGUF inference routing, and fixes — adds _in_studio_venv(), _reexec_cli_in_studio_venv(), _stage_setup_script_if_needed() to studio.py, GGUF routing in inference, venv re-exec in train, Optional[List] fix in options, __main__.py
  2. Agent skill with evals and config templates — SKILL.md, YAML templates, eval suite
  3. Fix stale references in skill docs — setup → update, .venv → unsloth_studio

All of main's additions are preserved (stop(), update(), PID tracking, unsloth_studio venv path). All 7 tests pass. Ready for re-review!

@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch from 52d0581 to 3f2b718 Compare April 8, 2026 16:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5acfc61a6e

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +425 to +428
existing = (
sorted(WORKSPACE_DIR.glob("iteration-*")) if WORKSPACE_DIR.exists() else []
)
iteration = len(existing) + 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute next iteration from max existing suffix

The auto-iteration logic uses len(existing) + 1, which can reuse an already existing directory when iteration folders are sparse (for example after deleting older runs or after using --iteration manually). Because iteration_dir.mkdir(..., exist_ok=True) allows reuse, a subsequent run can overwrite/mix artifacts in a prior iteration-* folder and corrupt benchmark history. Parse the numeric suffixes of existing iteration-* directories and pick max + 1 instead of counting entries.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b49be3424b

ℹ️ 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".

Comment thread unsloth_cli/commands/studio.py Outdated
Comment on lines +132 to +135
backend_dir = str(_PACKAGE_ROOT / "studio" / "backend")
env = os.environ.copy()
existing = env.get("PYTHONPATH", "")
extra_paths = [backend_dir]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove outer backend path from re-exec PYTHONPATH

_reexec_cli_in_studio_venv prepends backend_dir built from the caller install (_PACKAGE_ROOT/studio/backend) before launching the Studio venv, so bare imports used throughout backend modules (for example from loggers import ...) resolve from the outer environment first instead of the Studio venv. When the outer unsloth package version differs from ~/.unsloth/studio/unsloth_studio, this mixes module versions in one process and can break train/inference/export after re-exec with hard-to-diagnose import/runtime errors.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen removed the auto-reviewing Auto-review in progress label Apr 12, 2026
@TimPietrusky
TimPietrusky force-pushed the feat/cli-fixes-and-skill branch 2 times, most recently from cc704ab to 39f9467 Compare April 19, 2026 08:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb470e2625

ℹ️ 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".

Comment thread skills/unsloth/evals/run_evals.py Outdated
Comment on lines +439 to +440
for eval_entry in evals:
eval_id = eval_entry["id"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip Docker-only eval when Docker is unavailable

This loop runs every eval ID unconditionally, including setup-fresh-docker, but that eval is explicitly documented as requiring a running Docker daemon. On machines without Docker installed/running, the benchmark now includes an impossible task and depresses pass-rate/token/time comparisons for reasons unrelated to the skill itself. Add an environment gate (or auto-skip) before scheduling Docker-only evals so results remain comparable across hosts.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member

The CLI pieces here have since landed on main (_is_list_type in unsloth_cli/options.py, the GGUF llama-server routing, and the studio/backend path insertion), so could you rebase and narrow this to just skills/unsloth plus its evals? That would make it much quicker to get in.

@danielhanchen danielhanchen added diff-reduce# Shrink to an empty diff and squash-merge so a first-time contributor is credited superseded# labels Sep 8, 2026
Squashed from 5 commit(s); reduced to an empty diff so the contribution is credited on merge.
@danielhanchen
danielhanchen force-pushed the feat/cli-fixes-and-skill branch from b86bedc to 23bd40c Compare September 8, 2026 10:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T10:23:23.013284Z 23bd40c New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

Thanks for the PR! Sorry on the delay as well - we superseded the PR, but we merged the PR for now - appreciate the contribution!

@danielhanchen
danielhanchen merged commit cc9a4ea into unslothai:main Sep 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts# diff-reduce# Shrink to an empty diff and squash-merge so a first-time contributor is credited new-feature# non-studio# refactor# superseded#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants