feat(studio): adjustable llama-server parallel slots from the web UI (#7447)
* feat(studio): share the llama-server --parallel bounds as PARALLEL_MIN/MAX
The per-load parallel-slots field needs the same 1..64 range the CLI flag
validates, but models/inference.py cannot import run.py (run.py builds the
app that imports routes that import models). Promote the bounds into this
dependency-free module, which already owns the -np/--parallel semantics, and
record the deliberate mirrors that cannot import it (run.py, the unsloth CLI,
the web UI). The denylist entry stays: the first-class field is now the single
write path for the slot count, so a pass-through would still desync the
committed bookkeeping from llama-server.
* feat(studio): note the per-load override in the --parallel help text
--parallel is now the server-wide default that a per-load n_parallel (the
Studio Parallel Slots run setting) can override, not the definitive slot
count. Point at the new control so a user does not conclude a restart is the
only way to change slots, and record the shared PARALLEL_MIN/MAX mirror
alongside the existing CLI one.
* feat(studio): add n_parallel to LoadRequest and echo the slot counts
LoadRequest.n_parallel (optional, PARALLEL_MIN..PARALLEL_MAX) lets a load pick
its own llama-server --parallel count; omitted, the server-wide launch default
applies. ValidateModelRequest carries it too so the training-coexistence
estimate sizes the KV cache like the follow-up load rather than passing on a
smaller footprint.
LoadResponse and InferenceStatusResponse gain both requested_parallel_slots
(what the load was invoked with) and parallel_slots (what llama-server
actually runs after the fitter's slot reduction), so a client can tell an
honored request from a reduced one. Both are None where --parallel has no
meaning: non-GGUF loads and the diffusion runner.
* feat(studio): record the requested parallel-slot count on the backend
The auto GPU-memory fit may launch fewer slots than requested to keep the
model fully on GPU, so the committed effective count cannot answer "is the
live server what this request asked for?". Store the invoked count separately
(mirroring the _requested_n_ctx pattern) from the pre-reduction pending
kwargs, expose it as requested_parallel_slots, and have _already_in_target_state
compare requested-vs-requested: comparing against the effective count would
reload -- and re-reduce -- forever on an identical Apply.
The comparison sits in the non-diffusion branch, since the diffusion runner
ignores --parallel entirely. The requested value shares the effective count's
lifecycle, so every unload/kill path clears it and a stale count cannot
poison the next load's dedupe.
* feat(studio): honor a per-load parallel-slot count in /load and /validate
Resolve the slot count once per load -- the request field if set, else the
server-wide launch default -- and feed it to every consumer that must agree:
the training-coexistence guard, the llama-server load kwargs, and the reload
dedupe. Without the dedupe comparison a changed slot count would be swallowed
as already_loaded; it compares requested-vs-requested and skips the diffusion
runner, which ignores --parallel.
app.state.llama_parallel_slots is deliberately never written: it stays the
launch intent and the admission-queue fallback, so one load's override cannot
leak into later loads. /validate resolves the same way so its estimate cannot
undercount what the load then allocates.
Both /load returns and /status echo the counts through one helper, which
reports None for diffusion -- its load never commits a count, so echoing the
reset placeholder would fabricate an "invoked with 1 slot".
* feat(studio): accept nParallel in the chat-preset load config
ChatPresetLoadConfig is extra="forbid", so a preset carrying the new parallel
slots knob would 422 the whole settings sync without this field. Bounds come
from the shared PARALLEL_MIN/MAX rather than literals, so a future range
change cannot start rejecting presets the UI still allows.
* test(studio): cover the per-load parallel-slots knob
Pins the behaviors a regression would silently break: the requested-vs-effective
dedupe (comparing against the reduced count would reload forever), the diffusion
skip and its None echo, the requested count's reset lifecycle, and its commit
from the pre-reduction pending kwargs.
Also pins the three bounds mirrors that cannot import PARALLEL_MIN/MAX (run.py,
the unsloth CLI, the web UI) plus the preset model that can, so a range change
cannot leave one of them clamping or rejecting at the old limit.
* test(studio): refresh the --parallel denylist comments for the UI knob
The pinned rationale said the typer flag owns the slot count and pointed users
at a Studio restart. Parallel Slots / LoadRequest.n_parallel is now the other
managed writer, and the 1..64 guard is the shared PARALLEL_MIN/MAX -- a reader
following the old comments would conclude the UI control does not exist.
* feat(studio): note the per-load override in the CLI --parallel help
Both the plain-serve and `unsloth studio run` flags now describe a server-wide
default the Studio Parallel Slots run setting can override per load, matching
the backend help text.
* feat(studio): remember a per-model Parallel Slots override
nParallel joins the per-model config with the same null-means-follow-the-default
convention as the other knobs: null keeps the server-wide --parallel count, so
a blank control never pins a number and isDefaultConfig still deletes an
otherwise-untouched config instead of storing it.
The value is re-clamped to N_PARALLEL_MIN/MAX on every localStorage read and
write (the store is user-editable), and listing it in STORED_CONFIG_FIELDS
keeps it from being dropped as an unknown key. Legacy blobs predate the knob,
so their migration carries null. No schema-version bump: an additive optional
field, like the GPU fields before it.
* feat(studio): bridge nParallel between the per-model config and the store
The config->store, store->config and equality helpers all need the new field:
without the equality arm a slots-only edit reads as unchanged, so Apply is
dropped and the dirty state never lights up.
* feat(studio): track the parallel-slot override in the chat runtime store
nParallel holds the editable override and loadedNParallel the value the last
successful load sent, which the failed-switch rollback re-sends. Both are
per-model: they clear on unload and on a model switch, unlike the standing
preferences (GPU memory mode, speculative type) that survive one.
There is deliberately no backend-echo field for the control: the echo is the
resolved count, so adopting it would pin a blank "follow the server default"
input to an explicit number.
* feat(studio): type n_parallel and the slot-count echoes
The load request gains the optional per-load slot count, and both the load
response and the status payload gain requested_parallel_slots (invoked) and
parallel_slots (actually running after the fitter's reduction). Keys stay
snake_case: the payload is serialized as-is, with no case conversion.
* feat(studio): forward n_parallel to the validate preflight
validateModel builds its own body rather than forwarding the load payload, so
the slot count has to be listed explicitly. Slots scale the KV estimate, and
the preflight exists to refuse a load the training guard would then 409 -- an
unforwarded count would validate a smaller footprint than the load allocates.
* feat(studio): include nParallel in the active model's config
The sidebar assembles the active model's config from individually subscribed
store fields; an unsubscribed field would leave the form showing a stale value
after any external change.
* feat(studio): add the Parallel Slots control to the run settings
A numeric input in the GGUF advanced section, blank meaning "follow the server
default". It clamps on change like the Draft Tokens field rather than using
NumericValueInput, so there is no blur-draft to lose when the user types a
value and immediately clicks Load.
hasNonDefaultAdvanced counts it too, so a remembered override reopens the
advanced section instead of hiding the setting that is actually in effect.
* feat(studio): key the sidebar config form on nParallel too
The signature drives the remount that re-seeds the form; without the new field
an externally changed slot count would leave the sidebar showing the old one.
* feat(studio): send the Parallel Slots override on load
performLoad snapshots the slot count at click time (staged run-settings config
first, else the store) and sends it on both the validate preflight and the
load, so the two size the same footprint. A cross-model switch re-baselines it
like the other per-model knobs -- the previous model's count must not follow
onto the next one -- and the failed-switch rollback re-sends the previous
model's value so a rescue reload cannot silently drop to the server default.
The success path keeps the click-time value rather than the response echo: the
echo is the count the fitter resolved, so adopting it would turn a blank
"follow the server default" control into an explicit pin. Slots are GGUF-only,
so a transformers load sends and records null instead of a phantom override.
* feat(studio): carry the slot override through the compare-pane load
The compare pane builds its own load request, so it needs the field explicitly
or a pane with a remembered override would load at the server default. Its
validate preflight sends the same count, matching the comment above it that
promises validation is sized exactly as the load below.
GGUF-gated on both calls, and the store adopts the pane's own click-time value
rather than the resolved echo, mirroring the single-model path.
* feat(studio): honor the remembered slot override on startup auto-load
The auto-load path reads the per-model config and forwards every other
remembered knob, so a remembered Parallel Slots value was the one setting lost
on the "load last used model" path: llama-server came back at the server-wide
default with the control showing blank, and the first manual Apply afterwards
then forced a needless reload because the counts disagreed.
* feat(studio): seed the slot baseline from the status echo
Only the rollback baseline is seeded, never the editable control: the echo is
the resolved count, so adopting it would pin a blank "follow the server
default" input to a number. Without the seed, loadedNParallel stayed null
after a tab reload or a second tab adopting the running model, and a failed
switch then rolled the previous model back at the server default while every
other knob was restored.
* feat(studio): capture Parallel Slots in chat presets
The knob joins the preset load config end to end: captured from the store,
re-clamped when read back (persisted presets are untrusted input), applied on
switch, and summarized in the preset chip. Its default is null, so
coalesceDefaultLoadKnobs keeps a default-only preset empty rather than
persisting a no-op override.
* feat(studio): re-derive the preset state when Parallel Slots changes
Both preset memos snapshot the store through capturePresetLoadConfig, so
without the new dependency a slots-only edit left the unsaved-changes flag and
the load summary showing the previous value.
* test(studio): pin the Parallel Slots wiring end to end
Source-contract coverage for the hops a refactor can silently drop: the three
/load builders (interactive, compare pane, startup auto-load) and their
validate preflights, per-model persistence and clamping, the UI row, and the
status seed -- including the negative assertion that hydration seeds only the
rollback baseline, never the control, so the resolved echo cannot pin a blank
"server default" input.
* test(studio): pin nParallel in the preset load config
Covers capture, clamped read-back and apply on the frontend, plus the backend
field itself: ChatPresetLoadConfig is extra="forbid", so a missing or drifted
field 422s every settings sync that carries a preset.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fall back to one slot when llama-server lacks --kv-unified for PR #7447
Without --kv-unified an explicit --parallel N makes llama-server give each slot -c/N, so on a build without the flag choosing N slots silently shrinks every context window for a feature that build cannot serve. Clamp to one slot and log why, placed after the requested count is captured so the echo still reports it and before the KV estimates so the fit matches what actually launches.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Clear the slot control on load paths that never send it, and size the training guard for diffusion
Four review findings on the per-load Parallel Slots knob.
The editable nParallel control means "follow the server default" when null, so
any success path that does not send a slot count has to clear it. Three paths
kept a value staged for a different model:
- chat-adapter.ts, cached non-GGUF auto-load: the interactive and compare
builders already clear both fields for a non-GGUF response, this third one
did not. The field never renders for a non-GGUF target, so the stale count
was invisible and unclearable from the UI yet still persisted, and it flips
isDefaultConfig so a user with no overrides silently gets a stored entry.
- chat-adapter.ts, fresh-model fallback: its request omits n_parallel but its
success state resynced every other knob and left the slots alone, so a staged
edit survived against a server running the default and the next Apply
reloaded at a count that load never sent.
- apply-inference-status-to-store.ts: on a model change underneath the tab
every sibling knob adopts the new model's status, but nParallel updated only
its baseline, so the previous model's explicit count followed onto the new
model and saving or reloading there pinned it. Clear the control and keep
seeding the baseline for the rollback.
The training-coexistence guard sized a diffusion GGUF with the requested slot
count. _estimate_kv_cache_bytes scales the SWA cache with slots
(swa_limit = swa * slots + ubatch), but load_model hands a diffusion target to
_start_diffusion_server before the slot plumbing, so that runner is always
single-slot. At the new default of 4 this inflated the estimate and could 409 a
load that fits. An unclassified GGUF keeps the requested count.
Backend base KV depends on -c alone, not on --parallel, which is why only the
SWA term is affected: llama.cpp PR 14363 and discussion 4130.
Tests: three training-guard cases in test_parallel_slots_per_load.py and one
source contract in test_model_picker_contracts.py, each mutation-checked.
174 passed across the backend slot/admission/training suites, 56 across the
frontend contract suites.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Keep the slot control when re-adopting the running model, and never record slots for a diffusion load
Two follow-ups from the latest review round.
The first is a regression from c796393. That commit cleared the slot control
whenever hydratingExistingModel was set, to stop model A's count following onto
model B. But that flag is also set on the resident-model adopt path: when the
store checkpoint is an external provider id and the user re-picks the still
loaded local model, applyActiveModelStatusToStore is called with the external
id as previousCheckpoint, so the flag is unconditionally true. The clear then
wiped the config applyPerModelConfigToRuntime had restored two lines earlier,
and it was the only knob that did, because the siblings re-adopt the status
echo while this one cleared. Gate the clear on the tab's own baseline no longer
matching the running count: a genuine A to B swap still clears, re-adopting the
same model keeps its value.
The second revises an earlier call of mine. I rejected the diffusion phantom as
cosmetic because the backend ignores the value on every send. The sharpened
report is right and my rejection was wrong: capturePresetLoadConfig records
nParallel with no model gate, a Preset carries no model id, and applying one
writes nParallel for whatever model is current. So a count recorded against a
diffusion model, which the backend never applied, rides a saved preset onto a
text GGUF and becomes a real override the user never chose. Record slots only
when the load actually committed them, on all three load builders.
Tests: two source contracts in test_model_picker_contracts.py, both mutation
checked. Frontend typecheck clean, 58 passed across the contract and preset
suites.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Clear the slot baseline when status reports a model without slots
Hydrating from a GGUF to a slotless model left loadedNParallel at the previous
model's count: the seed only runs when the echo is non-null, and the control
clear added earlier touches nParallel alone. The stale baseline is what a
failed-switch rollback re-sends, and preset capture reads it, so it could claim
slots for a model that never used them.
Clear it when status describes a model that cannot have slots. /status omits
the echo entirely for non-GGUF and sends an explicit null for the diffusion
runner, so keying on is_gguf === false or an explicit null covers both while an
absent field on a GGUF, which is how an older backend reports one, still leaves
the baseline alone.
Test mutation checked; frontend typecheck clean against a fresh npm ci.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Distinguish a same-model re-adopt from a model swap, and size the training guard at the slots that launch for PR #7447
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Keep the blank slot control across a failed-switch rollback for PR #7447
* Restore a remembered slot override when hydrating a fresh store for PR #7447
* Tighten comments for PR #7447
* Restore a remembered slot override on a model switch too for PR #7447
* Tighten comments and docstrings for PR #7447
* Take the rollback slot intent from the picker's pre-switch snapshot for PR #7447
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: danielhanchen <danielhanchen@gmail.com>
Co-authored-by: danielhanchen <unslothai@gmail.com>
This commit is contained in:
parent
7ac75c6572
commit
150b5ba25a
25 changed files with 1186 additions and 20 deletions
|
|
@ -68,3 +68,18 @@ def test_backend_chat_preset_accepts_load_config():
|
|||
routes = _read("studio/backend/routes/chat_history.py")
|
||||
assert "class ChatPresetLoadConfig" in routes
|
||||
assert "loadConfig: Optional[ChatPresetLoadConfig]" in routes
|
||||
|
||||
|
||||
def test_preset_load_config_carries_parallel_slots():
|
||||
# Captured, clamped on read, applied, and accepted by the extra="forbid"
|
||||
# backend model (a missing backend field would 422 every settings sync).
|
||||
source = _read("studio/frontend/src/features/chat/presets/preset-load-config.ts")
|
||||
assert '| "nParallel"' in source
|
||||
assert "nParallel: snapshot.nParallel ?? null" in source
|
||||
assert "nParallel: config.nParallel ?? null" in source
|
||||
assert "N_PARALLEL_MAX, Math.round(partial.nParallel)" in source
|
||||
routes = _read("studio/backend/routes/chat_history.py")
|
||||
assert (
|
||||
"nParallel: Optional[int] = Field(default = None, ge = PARALLEL_MIN, le = PARALLEL_MAX)"
|
||||
in routes
|
||||
)
|
||||
|
|
|
|||
|
|
@ -631,6 +631,253 @@ def test_legacy_migration_is_idempotent_and_non_destructive():
|
|||
assert "if (isDefaultConfig(migrated) || Object.hasOwn(map, key)) {" in src
|
||||
|
||||
|
||||
def test_parallel_slots_setting_wired_end_to_end():
|
||||
"""The per-load Parallel Slots knob (llama-server --parallel) must flow from
|
||||
the run-settings form through persistence, every /load builder, the validate
|
||||
preflight and the cross-model reset; a lost hop silently reverts the model to
|
||||
the server-wide slot default."""
|
||||
config = _read("features/model-picker/model-config/per-model-config.ts")
|
||||
# Persisted per model, clamped on every read/write, and null (= server
|
||||
# default) counts as default so blank configs are not stored.
|
||||
assert '"nParallel",' in config
|
||||
assert "N_PARALLEL_MAX, Math.round(partial.nParallel)" in config
|
||||
assert "config.nParallel == null &&" in config
|
||||
page = _read("features/model-picker/components/model-config-page.tsx")
|
||||
# Rendered in the GGUF advanced section, which a remembered override reopens.
|
||||
assert "Parallel Slots" in page
|
||||
assert "config.nParallel != null ||" in page
|
||||
assert 'aria-label="Parallel decode slots"' in page
|
||||
api_types = _read("features/chat/types/api.ts")
|
||||
assert "n_parallel?: number | null;" in api_types
|
||||
runtime = _read("features/chat/hooks/use-chat-model-runtime.ts")
|
||||
# Click-time snapshot, /load body, validate preflight, cross-model reset and
|
||||
# failed-switch rollback all carry the value.
|
||||
assert "pendingLoadConfig?.nParallel" in runtime
|
||||
# GGUF-gated, like the compare pane: a transformers load has no slots.
|
||||
assert "n_parallel: isGguf ? loadNParallel : null," in runtime
|
||||
assert "n_parallel: validateNParallel," in runtime
|
||||
assert "loadNParallel = pendingLoadConfig?.nParallel ?? null;" in runtime
|
||||
assert "n_parallel: stateBeforeUnload.loadedNParallel," in runtime
|
||||
chat_api = _read("features/chat/api/chat-api.ts")
|
||||
assert "n_parallel: payload.n_parallel," in chat_api
|
||||
composer = _read("features/chat/shared-composer.tsx")
|
||||
# The compare pane is a second /load builder; its preflight sizes like its load.
|
||||
assert composer.count("n_parallel: ownConfig.nParallel ?? null,") == 2
|
||||
adapter = _read("features/chat/api/chat-adapter.ts")
|
||||
# The startup auto-load is a third builder reading the remembered config.
|
||||
assert adapter.count("n_parallel: config.nParallel ?? null,") == 2
|
||||
# ... and records it as loaded through the diffusion-gated local below.
|
||||
assert "loadedNParallel: committedSlots," in adapter
|
||||
status = _read("features/chat/lib/apply-inference-status-to-store.ts")
|
||||
# Hydration seeds the rollback BASELINE only; adopting the resolved echo into
|
||||
# the control would pin a blank "server default" to a number.
|
||||
assert "loadedNParallel: status.requested_parallel_slots," in status
|
||||
assert "nParallel: status.requested_parallel_slots," not in status
|
||||
sidebar = _read("features/model-picker/components/sidebar-model-config.tsx")
|
||||
# The sidebar form remounts when an external change lands.
|
||||
assert 'config.nParallel ?? "",' in sidebar
|
||||
|
||||
|
||||
def test_parallel_slots_control_cleared_when_the_load_never_sent_them():
|
||||
"""`nParallel` is the editable control ("blank = follow the server default")
|
||||
and `loadedNParallel` the rollback baseline. A success path that sends no
|
||||
slot count must blank the control, or a value staged for another model shows
|
||||
as applied, is persisted into this model's config (`isDefaultConfig` keys on
|
||||
nParallel) and is re-sent by the next Apply. Each assertion below is the only
|
||||
thing pinning one such path."""
|
||||
status = " ".join(_read("features/chat/lib/apply-inference-status-to-store.ts").split())
|
||||
# A model/variant swap underneath this tab must reset the control like
|
||||
# performLoad's cross-model reset, or model A's count follows onto model B.
|
||||
# Narrowly gated -- see test_hydration_keeps_the_slot_control_when_readopting_the_running_model.
|
||||
assert "...(seedLoadParams && slotsModelChanged && { nParallel: null })," in status
|
||||
# ... while still never adopting the RESOLVED echo into the control.
|
||||
assert "nParallel: status.requested_parallel_slots," not in status
|
||||
|
||||
adapter = _read("features/chat/api/chat-adapter.ts")
|
||||
# Slice the two success branches apart, bounding the second at the shared tail
|
||||
# so it cannot swallow the fresh-default path below and stay green.
|
||||
candidate = adapter.split("async function loadAutoLoadCandidate", 1)[1]
|
||||
gguf_branch, non_gguf_rest = candidate.split('if (candidate.kind === "gguf") {', 1)[1].split(
|
||||
"\n } else {\n", 1
|
||||
)
|
||||
non_gguf_branch = non_gguf_rest.split("if (!(loadResp.is_lora ?? false)) {", 1)[0]
|
||||
# The cached-GGUF branch keeps the remembered override via the gated local...
|
||||
assert "nParallel: committedSlots," in gguf_branch
|
||||
assert "nParallel: null," not in gguf_branch
|
||||
# ... the safetensors fallback sends no slots, so it clears both, or the count
|
||||
# survives on a model whose form does not even render the field.
|
||||
assert "nParallel: null," in non_gguf_branch
|
||||
assert "loadedNParallel: null," in non_gguf_branch
|
||||
|
||||
fresh_default = adapter.split("No downloaded models found. Fetching", 1)[1].split(
|
||||
'showAutoLoadSuccess("Loaded Qwen', 1
|
||||
)[0]
|
||||
# The fresh-default download omits the slots, so its success state clears both,
|
||||
# or the control reads as an unapplied edit against the seeded baseline.
|
||||
assert "n_parallel" not in fresh_default.split("saveSpeculativeType", 1)[0]
|
||||
assert "nParallel: null," in fresh_default
|
||||
assert "loadedNParallel: null," in fresh_default
|
||||
|
||||
|
||||
def test_hydration_clears_the_slot_baseline_for_a_slotless_model():
|
||||
"""The baseline is what a rollback re-sends and what preset capture reads, so
|
||||
a model that cannot have slots must not inherit the previous GGUF's count.
|
||||
/status omits the echo for non-GGUF and sends an explicit null for diffusion;
|
||||
an absent field on a GGUF is an older backend and must NOT wipe it."""
|
||||
src = _read("features/chat/lib/apply-inference-status-to-store.ts")
|
||||
assert (
|
||||
"(status.is_gguf === false || status.requested_parallel_slots === null) && {" in src
|
||||
), "the slotless clear must key on is_gguf or an explicit null echo"
|
||||
clear = src.index("status.is_gguf === false || status.requested_parallel_slots === null")
|
||||
assert "loadedNParallel: null," in src[clear : clear + 200]
|
||||
# Never `!= null`: that also matches the absent field an older backend sends.
|
||||
assert "status.requested_parallel_slots !== null && {" not in src
|
||||
|
||||
|
||||
def test_hydration_keeps_the_slot_control_when_readopting_the_running_model():
|
||||
"""`hydratingExistingModel` is true whenever the incoming status disagrees
|
||||
with what this tab last recorded, which includes RE-ADOPTING a model the tab
|
||||
never lost: the resident-adopt branch restores the model's own per-model
|
||||
config and only then hydrates, passing the EXTERNAL id as
|
||||
`previousCheckpoint`. An ungated clear there wipes the slot count that branch
|
||||
just restored, and the blank persists into `savePerModelConfig`, so a Save
|
||||
the user reads as a no-op erases their remembered override.
|
||||
|
||||
Only that branch knows the model is unchanged, so it says so explicitly.
|
||||
Slot counts cannot stand in: the echo falls back to the server-wide default,
|
||||
so a genuine A->B swap can echo exactly A's explicit count."""
|
||||
status = " ".join(_read("features/chat/lib/apply-inference-status-to-store.ts").split())
|
||||
assert (
|
||||
"const slotsModelChanged = hydratingExistingModel && !options.readoptingSameModel;"
|
||||
in status
|
||||
)
|
||||
assert "...(seedLoadParams && slotsModelChanged && { nParallel: null })," in status
|
||||
# Never a slot-count proxy for "same model".
|
||||
assert "prevState.loadedNParallel === (status.requested_parallel_slots" not in status
|
||||
# The baseline seed stays ungated, or a rollback after a tab reload restores
|
||||
# the model at the server default slots.
|
||||
assert "loadedNParallel: status.requested_parallel_slots," in status
|
||||
|
||||
runtime = " ".join(_read("features/chat/hooks/use-chat-model-runtime.ts").split())
|
||||
resident = runtime.split("if (!forceReload && isExternalModelId(selectedCheckpoint)) {", 1)[
|
||||
1
|
||||
].split("const stopDecision", 1)[0]
|
||||
# What makes the scenario reachable: the branch restores the model's own
|
||||
# config, then hydrates against the external id.
|
||||
assert "applyPerModelConfigToRuntime(selection.previousConfig);" in resident
|
||||
assert "previousCheckpoint: selectedCheckpoint," in resident
|
||||
# Only reachable because the branch matched the id AND the variant first.
|
||||
assert "resolveInferenceCheckpointId(residentStatus) === modelId" in resident
|
||||
assert "readoptingSameModel: true," in resident
|
||||
# The refresh() hydrate must NOT claim it: there the model really can change.
|
||||
poll = runtime.split("setModels(listRes.models.map(toChatModelSummary));", 1)[1].split(
|
||||
"} else if (!statusRes.active_model", 1
|
||||
)[0]
|
||||
assert "applyActiveModelStatusToStore(statusRes, {" in poll
|
||||
assert "readoptingSameModel" not in poll
|
||||
|
||||
|
||||
def test_parallel_slots_are_never_recorded_for_a_diffusion_load():
|
||||
"""A DiffusionGemma GGUF answers ``is_gguf: true``, but its runner ignores
|
||||
``--parallel``, so ``_parallel_slot_echo`` reports null slots for it. The
|
||||
three load success paths must gate on ``is_diffusion`` too, or they record a
|
||||
click-time count the load never committed.
|
||||
|
||||
That phantom does not stay put: ``capturePresetLoadConfig`` snapshots
|
||||
``nParallel`` with no model gate and a preset carries no model identity, so
|
||||
applying it over a TEXT GGUF sends the count as a real ``n_parallel``.
|
||||
"""
|
||||
runtime = " ".join(_read("features/chat/hooks/use-chat-model-runtime.ts").split())
|
||||
# One gated local feeds the control and the baseline, so they cannot drift.
|
||||
assert "(loadResponse.is_gguf ?? false) && !(loadResponse.is_diffusion ?? false)" in runtime
|
||||
assert "nParallel: committedSlots," in runtime
|
||||
assert "loadedNParallel: committedSlots," in runtime
|
||||
|
||||
adapter = " ".join(_read("features/chat/api/chat-adapter.ts").split())
|
||||
assert (
|
||||
"const committedSlots = (loadResp.is_diffusion ?? false) ? null "
|
||||
": (config.nParallel ?? null);" in adapter
|
||||
)
|
||||
assert "nParallel: committedSlots," in adapter
|
||||
assert "loadedNParallel: committedSlots," in adapter
|
||||
|
||||
composer = " ".join(_read("features/chat/shared-composer.tsx").split())
|
||||
assert "targetIsGguf && !(resp.is_diffusion ?? false)" in composer
|
||||
assert "nParallel: committedSlots," in composer
|
||||
assert "loadedNParallel: committedSlots," in composer
|
||||
|
||||
|
||||
def test_hydration_restores_a_remembered_slot_override():
|
||||
"""The control is never seeded from the status echo, so a model running on a
|
||||
remembered override shows a BLANK slot control after a browser reload or a
|
||||
tab move to another GGUF. `ModelConfigPage.resolveInitial` prefers the live
|
||||
store for the active model, so that blank is what the form edits: the next
|
||||
Apply reloads at the server default and a Save writes the blank over the
|
||||
remembered count.
|
||||
|
||||
The seed is deliberately narrow: storage is read only on a fresh store or a
|
||||
model change, never on a steady poll, and the value is adopted only when the
|
||||
server already runs that exact count, which proves it is this model's own.
|
||||
"""
|
||||
src = _read("features/chat/lib/apply-inference-status-to-store.ts")
|
||||
status = " ".join(src.split())
|
||||
assert (
|
||||
"resolveInitialConfig(checkpointId, status.gguf_variant ?? null)" in status
|
||||
), "the remembered override comes from per-model storage, not the echo"
|
||||
assert (
|
||||
"const slotsUnseeded = prevState.loadedNParallel === null && "
|
||||
"prevState.nParallel === null;" in status
|
||||
)
|
||||
assert (
|
||||
"status.is_gguf && (slotsUnseeded || slotsModelChanged)" in status
|
||||
), "storage is read on a fresh store or a model change, never on a steady poll"
|
||||
assert (
|
||||
"...(seedLoadParams && (slotsUnseeded || slotsModelChanged) &&" in status
|
||||
), "the seed fires in both cases the clear leaves the control blank"
|
||||
assert (
|
||||
"rememberedNParallel != null && rememberedNParallel === "
|
||||
"status.requested_parallel_slots && { nParallel: rememberedNParallel, }" in status
|
||||
)
|
||||
# Both cases trip the model-change clear, so the seed only survives by
|
||||
# being spread after it.
|
||||
assert src.index("slotsModelChanged && { nParallel: null }") < src.index(
|
||||
"nParallel: rememberedNParallel,"
|
||||
)
|
||||
|
||||
|
||||
def test_failed_switch_rollback_restores_the_slot_intent_not_the_resolved_count():
|
||||
"""`loadedNParallel` holds a RESOLVED count even for a load that sent no
|
||||
slots (the echo falls back to the server-wide default), so it is the right
|
||||
value to re-send when recreating the previous server and the wrong one to put
|
||||
back in the control: it turns "follow the server default" into an explicit
|
||||
override that a later Save or preset capture pins. The outer catch only
|
||||
repairs that for a staged config, so a plain string pick keeps the phantom.
|
||||
|
||||
The intent comes from the picker's own pre-switch snapshot when there is one:
|
||||
chat-page pre-applies the TARGET's config before calling selectModel, so the
|
||||
live control describes the outgoing model only for a bare pick."""
|
||||
runtime = " ".join(_read("features/chat/hooks/use-chat-model-runtime.ts").split())
|
||||
assert (
|
||||
'const previousNParallel = typeof selection !== "string" && '
|
||||
"selection.previousConfig ? (selection.previousConfig.nParallel ?? null) "
|
||||
": useChatRuntimeStore.getState().nParallel;" in runtime
|
||||
)
|
||||
assert runtime.index("const previousNParallel") < runtime.index(
|
||||
"applyPerModelConfigToRuntime(pendingLoadConfig);"
|
||||
), "a config staged on the selection must not replace it either"
|
||||
picker = " ".join(_read("features/chat/chat-page.tsx").split())
|
||||
assert (
|
||||
"const previousConfig = currentRuntimePerModelConfig({ includeMaxSeqLength: true, }); "
|
||||
"const hasAppliedConfig = applyModelLoadConfigToRuntime(" in picker
|
||||
), "the snapshot must be taken before the target's config is applied"
|
||||
rollback = runtime.split("const rollbackSpeculativeType", 1)[1]
|
||||
assert "nParallel: previousNParallel," in rollback
|
||||
# Baseline and reload payload keep the resolved count, or the rollback
|
||||
# recreates the previous model at a different slot count.
|
||||
assert "loadedNParallel: stateBeforeUnload.loadedNParallel ?? null," in rollback
|
||||
assert "n_parallel: stateBeforeUnload.loadedNParallel," in runtime
|
||||
|
||||
|
||||
def test_vulkan_inference_devices_are_the_pickable_set():
|
||||
"""GGUF loads run through llama-server, so on a Vulkan build the picker must
|
||||
offer the inference inventory (ggml ordinals, the space `--device Vulkan<i>`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue