Skip to content

Studio: keep different GGUF quants of the same repo alongside (#19072) - #19122

Open
indrajeetapache wants to merge 1 commit into
unslothai:mainfrom
indrajeetapache:fix/studio-multi-model-same-repo-quants-19072
Open

indrajeetapache wants to merge 1 commit into
unslothai:mainfrom
indrajeetapache:fix/studio-multi-model-same-repo-quants-19072

Conversation

@indrajeetapache

Copy link
Copy Markdown
Contributor

Summary

  • Fixes [Bug] Unable to load 2 models of the same parent name (concurrently) #19072: with Keep multiple models loaded, loading a second GGUF quant of the same HF parent (e.g. UD-Q4_K_XL then UD-Q5_K_S) replaced the first in place — even when pinned to different GPUs.
  • Cause: _select_load_slot treated a bare-repo match as “already serving,” so another quant reused that slot. Routing already supported repo:QUANT (see test_request_model_name_picks_the_backend); only load selection was wrong.
  • Change: drop that same-repo replace shortcut for alongside loads. Explicit repo:QUANT / gguf_variant opens a second slot; bare-repo chat still prefers the primary; a load without alongside still switches the primary.

Test plan

  • Unit: same-repo other quant + alongside=True picks a new slot; without alongside still returns primary
  • Existing routing test: org/A:Q8_0 on a slot next to primary org/A:Q4 still routes by explicit quant
  • Desktop: enable Keep multiple models loaded → Always or When they fit; load two quants of the same parent on different GPUs; both stay loaded
  • Clicking a quant without multi-model / without alongside still switches (replace)

cc @NilayYadav @danielhanchen

…hai#19072)

Multi-model alongside previously forced another quant of the same HF
repo onto the existing slot (bare-repo match), so UD-Q4 then UD-Q5
replaced instead of loading on a second GPU. Route by repo:QUANT for
loads; bare-repo chat still prefers the primary.
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…og (#19125)

## Problem


`studio/backend/tests/test_diffusion_backend.py::test_family_render_cudnn_scope_overrides_an_inherited_benchmark`
is red on `main` in Backend CI `(Python 3.13, diffusion)`. It fails for
every PR based on `main` since #19077, for example #19122:

```
with family_render_cudnn_scope(detect_family("krea/Krea-2-Turbo"), "cuda"):
    assert cudnn.benchmark is True  # a family that keeps the benchmark is left alone
AssertionError: assert False is True
```

## Cause

#19077 is correct. It sets `cudnn_benchmark = False` on Krea-2 on
purpose: the per-process VAE conv pick decoded one fixed latent three
different ways across three fresh L4 homes.

The test is wrong. It used Krea-2 as its hard-coded example of a family
that keeps `cudnn.benchmark` on, so pinning Krea-2 broke it. The same
would happen whenever another family gets pinned.

## Fix

Tests only. The test now reads both lists from `_FAMILIES` instead of
naming a family:

- for every family with `cudnn_benchmark = False`, the scope holds the
flag off inside and restores it after;
- for every family that keeps it, the scope leaves the flag alone;
- the FLUX.2 Klein case and the CPU-device case are unchanged;
- it asserts that both lists are non-empty, so it cannot pass vacuously.

## Verification

- The test passes; the whole file passes serially (694).
- Sabotage A: make `family_render_cudnn_scope` ignore the family flag.
The test fails, naming `qwen-image-2.1`, a family that keeps the
benchmark.
- Sabotage B: make the scope never hold the flag off. The test fails on
the first opt-out.
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…le helper (#19133)

## Problem

Two tests are broken on `main`.

1.
**`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`**
is red in `Repo tests (CPU, rest-2)` for every PR based on `main`, for
example #19122:

   ```
Left contains one more item: 'tests/test_inkling2_support.py:633:
read_text()'
   ```

#19016 added `(_ROOT / "unsloth" / "save.py").read_text()`. It reads a
checked-in file with the platform default encoding, which breaks on
Windows as soon as `save.py` gains a non-ASCII byte. The guard is right
and the new line is wrong.

2.
**`tests/test_inkling2_support.py::test_fastmodel_keeps_inkling2_eager_unless_told_otherwise`**
fails wherever the file runs:

   ```
assert re.search('if os\\.environ\\.get\\("UNSLOTH_COMPILE_DISABLE",
"0"\\) == "0": ...', body)
   AssertionError: None
   ```

It still pins the inline assignment that #19073 replaced with the shared
`_set_partial_compile_disable()` helper. CI does not show it yet: the
file skips below transformers 5.24, and the HF=latest legs are held
below 5.24. It fails locally on 5.24.0, so it would turn red as soon as
that cap lifts.

## Fix

Tests only, in `tests/test_inkling2_support.py`:

- Both reads of checked-in source pass `encoding = "utf-8"`:
  - the `save.py` read the guard flags;
- the loader source read through `__file__`, which the guard does not
see.
- The eager-compile test now pins the current shape:
  - the Inkling 2 branch calls `_set_partial_compile_disable()`;
  - the helper sets `partial` from unset, `0` or `partial`;
- the helper keeps a full disable (`1`, `true`) as `1`, so an explicit
user choice is still left alone.

## Verification

| Check | Result |
| --- | --- |
| `test_source_read_encoding.py`, `main` | 1 failed |
| `test_source_read_encoding.py`, this branch | 16 passed |
| `test_inkling2_support.py`, transformers 5.24.0, `main` | 1 failed, 41
passed |
| `test_inkling2_support.py`, transformers 5.24.0, this branch | 42
passed |
| `test_inkling2_support.py`, transformers 5.17 | module skipped as
before |

Sabotage, each with only the product line changed:

- Drop the helper call from the Inkling 2 branch in `loader.py`: the
test fails on the call check.
- Make the helper always set `partial`: the test fails with `assert
'partial' == '1'` for a full disable.
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…19135)

## Problem


`tests/test_runtime_text_encoding.py::test_shipping_code_names_an_encoding`
is red on `main` in `Repo tests (CPU, rest)`, for example on #19122 and
#19127:

```
4 text read/write call sites in shipping code let the operator's locale decide the encoding
  'unsloth/models/inkling2.py:364: open()'
  'unsloth/models/inkling2.py:532: open()'
  'unsloth/models/inkling2.py:537: open()'
  'unsloth/models/inkling2.py:545: open()'
```

## Cause

The guard is right; the new code is wrong.

#19016 (Inkling 2 merged 16-bit save and GGUF export) added four
text-mode `open()` calls with no encoding:

- reading `model.safetensors.index.json` (`index_path`);
- writing the merged index;
- reading `config.json`;
- writing `config.json`.

On Windows, Python uses the locale code page there. A config or index
with a non-ASCII byte then fails to load, or is written in a codec the
next reader does not expect. The guard has been in the repo since
October; the lines all come from `c69ffd79be`.

## Fix

Pass `encoding = "utf-8"` on all four calls in
`unsloth/models/inkling2.py`. Nothing else changes: the JSON written is
the same on a UTF-8 host.

## Verification

- `tests/test_runtime_text_encoding.py`: 9 passed (`main`: 1 failed,
listing exactly these four sites).
- `tests/test_inkling2_support.py` on transformers 5.24.0, including the
merged-save tests: 42 passed.

This branch has not been deployed

No deployments
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.

[Bug] Unable to load 2 models of the same parent name (concurrently)

2 participants