Skip to content

Studio: choose the Engram table precision for Qwen3.8-Flash-Next and DeepSeek-V4.1 GGUFs - #17641

Merged
danielhanchen merged 14 commits into
unslothai:mainfrom
oobabooga:engram-precision
Nov 13, 2026
Merged

danielhanchen merged 14 commits into
unslothai:mainfrom
oobabooga:engram-precision

Conversation

@oobabooga

@oobabooga oobabooga commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Problem: The Qwen3.8-Flash-Next and DeepSeek-V4.1-Flash-1017 guides let people swap the Engram table for another precision, but only by hand: download engram/*-engram-<PRECISION>.gguf_file, stamp it with set_split.py, and rename it over one of the quant's files. Studio had no way to do this.

Change: A new "Engram Table" setting picks the table per model and quant. Studio downloads the chosen table, skips the quant's own table when it is not on disk yet, and starts llama-server with --ple <table>.

Status: Tested live on Qwen3.8-Flash-Next UD-IQ1_S. DeepSeek was checked against its Hub listing only (its smallest quant is 233 GB).

Before and after

Run settings, Memory group: main has no Engram control; this PR adds the Engram Table select

The Engram Table menu and a pick: each published table with its size, the built-in one marked, and the download note

The second image is this PR only: main has no counterpart.

How it works

  • No renaming. llama.cpp b12233 added --ple (feat: external PLE file loading ggml-org/llama.cpp#31185), which loads a separate table in place of the model's own and allows the quant's table file to be missing.
  • Finding the quant's own table. It sits in one split shard, not always the last. That shard is exactly the size of the standalone table of the same precision, which matches both repos' engram/README.md for all 22 quants. A wrong match cannot load wrong weights: llama.cpp refuses a set that is not exactly one table short.
  • Downloads. The chosen table is downloaded and the quant's own table is skipped, saving 28.8 to 202.8 GB. The choice is stored with the download job, so retries, the Xet-to-HTTP fallback and page reloads fetch the same table, and the transport is chosen by the table's size.
  • Loads. engram_precision on /api/inference/load and unsloth run --engram. Naming the quant's own table is the same as naming none. An unpublished precision, a non-GGUF model, or a llama.cpp build without --ple is refused with a clear message, before the loaded model is touched.
  • The choice is saved per model and quant, shown in /status, and changing it reloads the model.

Not changed

  • The memory estimate still prices the quant's own table. The table is read from disk as needed, so the fit hardly changes.
  • The Download button on the Hub model page fetches the quant's own table. Loading from chat uses the saved choice.
  • Offline, the setting is hidden because the table list comes from the Hub. A saved choice still loads from the cache.

Testing

  • Live: UD-IQ1_S with Q5_1 chosen downloaded 81 GB instead of 110 GB, started llama-server with --ple, and chatted normally. The two tables give different token probabilities from the first token.
  • Live load sequence, 30 random steps (table switches, repeated loads, unloads, concurrent loads, bad values): llama-server restarted exactly when the table changed. No failures.
  • Live bad input, 340 requests across load, download, progress, saved settings and the model list, with and without a model loaded: all refused without starting a load or a download.
  • Live recovery with forced Xet stalls: every retry and the HTTP fallback kept the table, and a 54.4 GB table was kept off HTTP.
  • A manual click-through in the UI (pick a table, load, chat, download, reload mid-download, cancel) found that the memory planner sized the quant's own table instead of the chosen one, so the first load ran out of GPU memory and retried. That is fixed: the load now succeeds first time in about 67 s instead of 125 s.
  • New tests: test_engram_tables.py, test_engram_tables_fuzz.py (property tests), and frontend engram-precision-setting, download-engram-table and download-engram-matching. Existing backend and frontend suites pass, except three tests that fail the same way on main.

UI check at 0597255

Run settings for unsloth/Qwen3.8-Flash-Next-GGUF UD-IQ1_S, two separate Studio installs (merge base 480fd26 vs this PR), nothing loaded or downloaded.

Memory group: before has no Engram row; after shows Engram Table with IQ4_NL, the quant's own table

After: the menu lists BF16 102.4 GB, Q8_0 54.4 GB, Q5_1 38.4 GB and IQ4_NL 28.8 GB built-in; picking Q5_1 shows the download note

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T11:09:11.915611Z edcc1a3 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[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@oobabooga

Copy link
Copy Markdown
Member 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: c8d38da701

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

or _is_imatrix_filename(name)
)
)
or engram_table_precision(name) is not None,

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 Preserve tables used by quants in other cache roots

When a quant in cache B reuses cache A's standalone table through _download_engram_table(), deleting A's last local quant reaches this cleanup because _has_remaining_main_gguf(target_repo) only inspects A. This unlinks the shared table and its blob even though B's backbone remains cached. Since B intentionally skipped its bundled table shard, deleting an unrelated quant makes B unloadable offline and forces another table download online. Check remaining dependencies across remembered cache roots before reclaiming standalone tables.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this. It needs a quant in one cache root that reuses a table cached in a different root, which only happens after the cache location changes. Deletion keeps the per-repo-folder rule that every other companion file follows.

Comment on lines +20165 to +20166
if skip_shard and skip_shard in gguf_extra_shards:
gguf_extra_shards = [shard for shard in gguf_extra_shards if shard != skip_shard]

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 skipped table shards from the saved-KV identity

With keep-KV enabled, Engram downloads that omit the bundled shard cannot preserve their resident KV cache. _gguf_file_identity() still stats every numbered file in the original split, so the omitted shard makes it return None; save_slots_for_resume() then immediately returns without saving. Adding the external table to _slot_launch_fingerprint() only addresses launches where the original shard is also present. Build the GGUF identity from the files the Engram launch actually reads so shard-skipped downloads retain the existing KV-preservation behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not a correctness bug. With the table shard absent, _gguf_file_identity returns None and save_slots_for_resume declines, so stale KV is never restored and the load starts cold. Keeping KV across reloads for these sets would be an enhancement.

@danielhanchen

Copy link
Copy Markdown
Member

(Python 3.13, m-r) fails one existing test:

studio/backend/tests/test_offload_planner_seam.py::test_the_layout_cache_notices_a_gguf_replaced_in_place
core/inference/llama_cpp.py:35842: in _tensor_spill_layout
E   AttributeError: '_CacheStub' object has no attribute '_ple_path_for'

_tensor_spill_layout now calls self._ple_path_for(...), and that test drives it with a minimal _CacheStub that only has the attributes the method used before. Giving the stub a _ple_path_for that returns None (no PLE table), or reading it with getattr(self, "_ple_path_for", None) in _tensor_spill_layout, should let the test check what it was written for again.

@oobabooga

Copy link
Copy Markdown
Member 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: 54f3bc2419

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

# The table is one of this download's own weights, so a partial of it is purged like the
# shards' before a transport resumes. The shard's hash stays: dropping it would let a
# stale-copy reclaim treat a cached built-in table as foreign.
main_hashes = self.main_hashes | ({table.sha256} if table.sha256 else set()),

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 Track shared Engram-table transport independently of the quant

With resumable .incomplete files and two quants selecting the same table, an HTTP attempt for quant A followed by a cancelled Xet attempt for quant B leaves A's per-variant transport marker set to HTTP. On A's next HTTP retry, prepare_cache_for_transport() retains B's sparse table partial because this hash is only in main_hashes; the size-only verification can then accept corrupted table weights. Track the table's writer with shared transport provenance, as is already done for companions, and reconstruct that ownership on manifest resumes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this. It needs two different quants that share one table, downloaded alternately over HTTP and a cancelled Xet attempt, and then an HTTP retry of the first. A table is purged like a main shard whenever its own job switches transport, which covers the reachable cases.

Comment on lines +23945 to +23946
engram_swap = _resolve_engram_swap(
engram_repo, hf_variant, hf_token, engram_precision

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 the request token for cached-path Engram loads

For a cached-path load of a private or gated Hub repo without an ambient token, this passes None to _resolve_engram_swap() even when the request supplies a valid hf_token: _gguf_request_intent() only copies that field when source.hf_repo is set. Recovering just engram_repo therefore makes model_info() fail with RepositoryNotFoundError or GatedRepoError, which is rethrown before consulting the cached table. A fully cached, authorized model consequently fails to reload solely because it is addressed by its cached path. Preserve the request token when recovering cached Hub provenance.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this. Only the two public unsloth repos publish standalone Engram tables, so a private or gated repo with tables that is loaded by its cache path does not occur.

@oobabooga

Copy link
Copy Markdown
Member 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: 54f3bc2419

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

downloaded = _is_fully_downloaded(v) and not is_partial
engram_ready = _engram_ready(requirement, downloaded)
# A quant whose own table shard was skipped for a cached standalone table is on disk too.
downloaded = downloaded or (bool(engram_ready) and not is_partial)

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 unused bundled-table partials from readiness

With resumable HTTP partials, canceling a normal download during its bundled-table shard and then completing the same quant over HTTP with another Engram table leaves the unused bundled .incomplete file cached: prepare_cache_for_transport() preserves same-transport resumable partials. The partial scan above still checks the unswapped requirement.main_hashes, so that leftover sets is_partial even though _engram_ready() confirms the complete backbone and external table. This gate consequently reports downloaded=false, partial=true; after refreshing, the picker offers another download/resume for a completed model, and retrying the same swapped plan cannot clear the flag because it never fetches that shard. Exclude unused bundled-table partials from this verdict when an Engram-ready set is present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member 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 quant still loads with its saved table, and the partial flag is accurate: a resumable partial of the quant's own table shard is still on disk, and switching back to the built-in table resumes it. Hiding the flag would hide that disk use rather than fix anything.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

One more red on the latest run, (Python 3.13, rest):

studio/backend/tests/test_tp_vision_regression.py:756 test_layer_min_gpus_bound_before_gpu_selection_try
E   assert 64964 < -1

The test locates the GPU-selection try body in LlamaCppBackend.load_model by the anchor gguf_size = self._get_gguf_size_bytes. This PR changes that line to gguf_size = self._gguf_read_bytes(model_path), so find returns -1. The code is fine; the anchor in the test just needs to follow the rename (for example gguf_size = self._gguf_read_bytes), keeping the check that _layer_min_gpus = 1 is bound before it. It passes on main.

@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@unslothai unslothai deleted a comment from oobabooga Nov 13, 2026
@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 13, 2026

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

ℹ️ 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 on lines +23955 to +23958
with _hf_offline_if_unreachable():
engram_swap = _resolve_engram_swap(
engram_repo, hf_variant, hf_token, engram_precision
)

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 Validate Engram choices before unloading other inference backends

When /api/inference/load receives an unpublished Engram precision while a Transformers or NPU model is resident, this validation is too late: routes/inference.py:19886–19899 unloads those runtimes before _run_gguf_load_attempt() reaches load_model(). _resolve_engram_swap() then raises, leaving the previously healthy model unloaded even though the request could have been rejected without a teardown. Run the Engram preflight before the route’s cross-backend unload, rather than only before llama.cpp’s own teardown.

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.

Not changing this: the UI and unsloth run --engram only offer published tables, so an unpublished precision needs a hand-written API call, and it then ends like any other GGUF load that fails after the cross-backend switch (download error, OOM): the old runtime was going to be replaced by this load anyway.

Comment on lines +4199 to +4201
tables = engram_tables(sizes.items())
table = find_engram_table(tables, precision)
if table is None:

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 Allow offline loads that explicitly name the built-in table

When a normal download has cached all UD-IQ1_S shards of unsloth/Qwen3.8-Flash-Next-GGUF but no standalone tables, a load with engram_precision="IQ4_NL" correctly becomes a no-op online. Repeating the identical request offline uses cached_sizes(), so tables is empty and this branch raises before recognizing the bundled IQ4_NL table. The model is fully present and needs no download, yet explicitly naming its built-in precision makes it unloadable offline. Recognize that precision from cached quant metadata before requiring a standalone copy.

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.

Not changing this: the UI stores the built-in table as no choice, so this needs an explicit offline --engram <built-in>; the refusal names the cached tables and dropping --engram loads the quant. Inferring the precision from tensor types offline is not worth the extra path.

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

ℹ️ 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 on lines +20779 to +20780
free_bytes = shutil.disk_usage(cache_dir).free
if table.size_bytes > free_bytes:

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 Credit resumable table bytes in the disk-space preflight

For HTTP caches that support partial resumes, retrying a load after an interrupted table download can fail despite sufficient disk space. For example, a 38.4 GB Q5_1 table with 30 GB already in .incomplete needs only 8.4 GB more, but this check rejects it with 10 GB free before hf_hub_download_with_xet_fallback() can resume. The user must unnecessarily free additional space or delete the partial and restart the download. Credit validated resumable bytes in the selected cache root, as the download worker's _preflight_disk_space() already does.

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.

Not changing this: it matches the in-process GGUF shard preflight on main (_download_gguf credits only whole cached blobs, not .incomplete bytes), and it needs an interrupted table download plus a disk with less free space than the whole table. Freeing the space or using the Hub download (which credits partials) both work.

@danielhanchen
danielhanchen merged commit 9c6291e into unslothai:main Nov 13, 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.

2 participants