Skip to content

Studio: let Laya fine-tunes answer from their GGUF export - #16511

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:serve-laya-gguf-fine-tunes
Nov 4, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:serve-laya-gguf-fine-tunes

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

A Laya fine-tune could be exported to GGUF from the Export page, which says the file is for llama.cpp's decision server, but the Decision API never used it. The fine-tune kept answering on PyTorch, even with the runtime set to llama.cpp, so the export did nothing.

A Laya fine-tune with a current export now answers through llama.cpp when the runtime is set to llama.cpp, and the Decision settings show the Runtime row for it. Auto stays on PyTorch, so existing fine-tunes keep the same answers unless llama.cpp is chosen. On llama.cpp, a state past the model's window is refused, and so is a question over the option or instruction budget, which llama.cpp would otherwise cut without saying so. Long options are answered as on PyTorch.

Exports of multilingual fine-tunes remain a dead end. llama.cpp refuses the mmBERT tokenizer, so choosing llama.cpp for one returns a 503 with the reason, and the Export page still offers them. confidence also differs by runtime: the same fine-tune and question gave 0.97 on llama.cpp and 0.87 on PyTorch. The stock Laya models stay on PyTorch, Laya GGUF is unchanged, and a fine-tune with no export or a stale one works as before.

Merge after #16496, which asks blank Laya questions by their id the way llama.cpp already does.

Before / after

Settings > API > Decision, with a Laya fine-tune that has a current GGUF export and the runtime set to llama.cpp. Before, there is no Runtime row and the fine-tune answers on PyTorch. After, the Runtime row shows llama.cpp, and the settings API reports effective_backend: llama.cpp, has_gguf_form: true.

Decision API settings before and after

@NilayYadav NilayYadav self-assigned this Nov 2, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-04T10:55:01.239128Z e042840 Manual request
ℹ️ 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.

@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: 633ce206e8

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

try:
tokenizer, mask = _export_tokenizer(checkpoint)
except Exception as exc:
_unloadable.add((_binary_key(resolve_binary()), checkpoint))

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 permanently caching tokenizer read failures

If a tokenizer file is temporarily missing or unreadable, this turns a recoverable read failure into a process-lifetime refusal. Repairing tokenizer.json or tokenizer_config.json does not change the cached checkpoint key, whose revision covers only the GGUF files, and unload() does not clear _unloadable. I verified that tokenizer validation succeeds after repair, but subsequent select() calls still return 503 even after unloading. Keep these read failures retryable, or invalidate the refusal when the tokenizer changes, so recovery does not require restarting Studio or re-exporting the GGUF.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: the tokenizer folder comes from the training run and is required for the folder to be listed, so a missing or broken one is a broken fine-tune that PyTorch cannot load either. Hand-repairing it in place without a re-export is not a path we support, and Auto still falls back to PyTorch.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

I cancelled the CI runs on this PR for now, since Codex hasn't converged at the current head yet: the latest push hasn't been reviewed by Codex yet. CI here runs on the team's shared runner pool, and it's backed up right now (380+ runs queued), so runs on code that's still changing push everyone else's back.

Once Codex says "Didn't find any major issues" on the head commit, one push or a re-run brings CI back. A small ask going forward: hold the push until Codex is clean, and batch follow-up fixes into a single push. Thanks!

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: b988fde743

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

tokenizer.encode(text.replace(mask, " "), add_special_tokens = False).ids
)
config = Path(checkpoint.source).expanduser() / "rl_agent_config.json"
head_max_len = int(json.loads(config.read_text(encoding = "utf-8")).get("head_max_len", 192))

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 Bound question validation by the exported head-token limit

For local Laya checkpoints whose raw head_max_len is reduced during export, this guard accepts questions that llama.cpp will silently truncate. unsloth/models/decision_gguf.py::_laya_max_head_tokens() writes _served_lengths()'s normalized limit to the GGUF: an encoder window of 384 with max_len=384, head_max_len=256, for example, exports a 192-token head. An instruction of about 200 tokens with short noul options passes this 256-token check and fits the 384-token context, yet exceeds the server's actual question budget, so it gets answered with part of the instruction missing instead of returning 422. Bound validation by the exported limit as well as the source configuration.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not reachable for Laya: every Laya encoder (ModernBERT-large, mmBERT) has 8192 positions, so the exported head limit is max(head_max_len, 256) and never below the raw head_max_len this checks. The check can only be stricter than llama.cpp, which matches what the PyTorch path refuses.

@danielhanchen danielhanchen self-assigned this Nov 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@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: f26e03afae

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

from .gguf_export_contract import served_files

files = served_files(Path(checkpoint.source).expanduser(), "clef")
files = served_files(Path(checkpoint.source).expanduser(), checkpoint.layout)

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 Resolve Laya exports under the selected subfolder

For a local Laya configured with UNSLOTH_SYSTEMONE_SUBFOLDER, catalog.default_checkpoint() preserves the subfolder and the PyTorch loader uses it, but this lookup and _native_files() search only checkpoint.source. If the root has its own current GGUF export, choosing llama.cpp silently serves that different model under the configured checkpoint's name; a subfolder-only export is ignored entirely. Resolve the effective checkpoint directory (source / subfolder) consistently for the export, configuration, and tokenizer reads.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 5e8edb9: the export, rl_agent_config.json and tokenizer are now read from source/subfolder, with a test that a root export is not served for a subfolder checkpoint.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 5e8edb9257

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

@danielhanchen

Copy link
Copy Markdown
Member

Cross-platform CI on ubuntu-latest fails at collection on this branch:

studio/backend/tests/test_decision_native.py:28: in <module>
    from tokenizers import Tokenizer
E   ModuleNotFoundError: No module named 'tokenizers'

That job installs the backend test requirements without tokenizers, and the new module-level import takes the whole file down, including the tests that were already passing on main. Moving the tokenizers imports into the tests that build the export folder, behind pytest.importorskip("tokenizers"), keeps the rest of the file running there. The laya_runtime.py import is already lazy, so only the test needs the change.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 4, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: e04284068c

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

@danielhanchen

Copy link
Copy Markdown
Member

pre-commit.ci run

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 4, 2026
@danielhanchen
danielhanchen merged commit 8bf2d3c into unslothai:main Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants