Repair three defects the main merge left behind

Git merged all three files without a conflict, but the result was wrong in
each case. The tests only started failing once the merged tree was run.

routes/inference.py duplicated the GGUF load block: this branch had moved
the gguf_load_in_flight marker and the _hub_download_blocks_gguf_load guard
under "if config.is_gguf and config.gguf_hf_repo", and the conflict
resolution re-added main's copy at the old position, so both ran. Dropped
main's copy; the earlier placement is the deliberate one, so a 409 from the
hub guard cannot tear down a resident Images or Video pipeline.

test_gpu_selection.py still called _hf_offline_if_dns_dead, which main
renamed to _hf_offline_if_unreachable_for (#7591). Disjoint edits, so no
conflict, but four route-error tests referenced a function that no longer
exists.

test_gguf_load_cache_reuse.py anchored its ordering assertion with rindex
over "if config.is_gguf:", taking the last one before the load marker. That
only held while _resolve_inherited_extra_args sat above every such line;
main has since hoisted it above the gpu_ids preflight, so the anchor landed
between the call and the marker and the assertion compared against an
unrelated later call site. The ordering it checks is a property of
_load_model_impl as a whole, so it now anchors on the function.

The ordering itself is intact: _resolve_inherited_extra_args, then the
gguf_load_in_flight marker, then the hub guard, then the chat handoff, then
unload_model.
This commit is contained in:
Daniel Han 2026-07-31 12:06:52 +00:00
parent c05574666c
commit 9541cc535a
3 changed files with 11 additions and 34 deletions

View file

@ -6126,33 +6126,6 @@ async def _load_model_impl(
llama_backend = get_llama_cpp_backend()
unsloth_backend = get_inference_backend()
if config.gguf_hf_repo:
from core.inference.llama_cpp import gguf_load_in_flight
gguf_load_stack.enter_context(gguf_load_in_flight(config.gguf_hf_repo))
# Block cache writes that would race the download manager. This runs
# after pass-through argument inheritance so a carried --no-mmproj
# changes the companion requirement exactly as it does for the load.
if config.gguf_hf_repo:
from core.inference.llama_cpp import _hub_download_blocks_gguf_load
if await asyncio.to_thread(
_hub_download_blocks_gguf_load,
config.gguf_hf_repo,
config.gguf_variant,
require_mmproj = bool(
config.is_vision and not extra_args_disable_mmproj(extra_llama_args)
),
hf_token = request.hf_token,
):
raise HTTPException(
status_code = 409,
detail = (
f"'{model_log_label}' is currently being downloaded "
"by the download manager. Wait for the download to "
"finish (or cancel it), then load the model."
),
)
# Fast path only: a swap can still be reserved during the drain.
_raise_if_sidecar_swap_in_progress()

View file

@ -831,11 +831,15 @@ class TestLoadHubDownloadExclusion:
source = (Path(__file__).resolve().parent.parent / "routes" / "inference.py").read_text(
encoding = "utf-8"
)
# _load_model_impl has more than one `if config.is_gguf:`, so anchor on
# the branch that actually owns the load marker rather than the first
# one in the file, which belongs to an earlier check.
# Anchor on the enclosing function, not on a nearby `if config.is_gguf:`. The previous
# anchor took the last such line before the load marker, which only worked while
# _resolve_inherited_extra_args happened to sit above every one of them; main since
# hoisted that call above the gpu_ids preflight ("resolve inherited extras once before
# command-dependent preflights"), so the rindex started landing BETWEEN the call and the
# marker and the first assertion compared against a later, unrelated call site. The
# ordering being asserted is a property of _load_model_impl as a whole.
marker = source.index("enter_context(gguf_load_in_flight")
gguf_branch_start = source.rindex("if config.is_gguf:", 0, marker)
gguf_branch_start = source.rindex("async def _load_model_impl", 0, marker)
gguf_branch = source[gguf_branch_start:]
# One chain, in this order:

View file

@ -1425,7 +1425,7 @@ class TestRouteErrors(unittest.TestCase):
),
patch.object(inference_route, "_guard_chat_load_against_training", return_value = None),
patch.object(inference_route.asyncio, "to_thread", new = _inline_to_thread),
patch.object(inference_route, "_hf_offline_if_dns_dead", nullcontext),
patch.object(inference_route, "_hf_offline_if_unreachable_for", nullcontext),
# The chat handoff passes a `register` hook (the in-flight marker), so accept it.
patch.object(arb, "acquire_for", lambda owner, register = None: acquired.append(owner)),
):
@ -1480,7 +1480,7 @@ class TestRouteErrors(unittest.TestCase):
patch.object(inference_route, "_guard_chat_load_against_training", return_value = None),
patch.object(inference_route, "_resolve_inherited_extra_args", lambda *a, **k: None),
patch.object(inference_route.asyncio, "to_thread", new = _inline_to_thread),
patch.object(inference_route, "_hf_offline_if_dns_dead", nullcontext),
patch.object(inference_route, "_hf_offline_if_unreachable_for", nullcontext),
patch.object(llama_cpp, "_hub_download_blocks_gguf_load", lambda *a, **k: True),
patch.object(arb, "acquire_for", lambda *a, **k: acquired.append(a[0])),
):
@ -1544,7 +1544,7 @@ class TestRouteErrors(unittest.TestCase):
patch.object(inference_route, "_guard_chat_load_against_training", return_value = None),
patch.object(inference_route, "_resolve_inherited_extra_args", lambda *a, **k: None),
patch.object(inference_route.asyncio, "to_thread", new = _inline_to_thread),
patch.object(inference_route, "_hf_offline_if_dns_dead", nullcontext),
patch.object(inference_route, "_hf_offline_if_unreachable_for", nullcontext),
patch.object(llama_cpp, "_hub_download_blocks_gguf_load", lambda *a, **k: False),
patch.object(arb, "acquire_for", _acquire),
):