Studio diffusion: fix static compile shape registration and prequant path validation
Register the dims the forward actually compiled with: image-conditioned workflows (img2img, inpaint, upscale, edit) run at the input image's size, not the slider's, so recording the slider values marked never-compiled shapes as covered and warm restarts kept paying compile for the real one. Validate a request-supplied transformer_prequant_path (existence plus the UNSLOTH_ALLOW_LOCAL_PREQUANT_PATH allowlist) before treating prequant as available at the resident-fit re-check: an unusable path skipped the dense fit check up front and then fell back to materializing dense bf16 after the previous pipeline was evicted, recreating the post-eviction OOM path. Shared as usable_prequant_source, also used by the auto-policy planner.
This commit is contained in:
parent
316c8b5a81
commit
e1fa4fec04
5 changed files with 216 additions and 12 deletions
|
|
@ -75,6 +75,52 @@ def test_local_prequant_path_ready(tmp_path, monkeypatch):
|
|||
assert pq.local_prequant_path_ready(str(ckpt)) is False
|
||||
|
||||
|
||||
# ── usable_prequant_source ───────────────────────────────────────────────────────
|
||||
def test_usable_source_missing_path_is_none(tmp_path, monkeypatch):
|
||||
# An allowlisted but ABSENT request-supplied path must not count as a prequant
|
||||
# source: load_prequantized_transformer would find no file and fall back to the
|
||||
# dense bf16 build after the resident pipeline was already evicted, so the memory
|
||||
# planner must run the dense fit checks up front instead.
|
||||
import os
|
||||
|
||||
monkeypatch.setattr(pq, "_allowed_prequant_roots", lambda: [os.path.realpath(str(tmp_path))])
|
||||
fam = _fam(prequant_repos = (("fp8", "org/hosted-fp8"),))
|
||||
missing = str(tmp_path / "missing.pt")
|
||||
assert pq.usable_prequant_source(fam, "fp8", path_override = missing) is None
|
||||
|
||||
|
||||
def test_usable_source_disallowed_path_is_none(tmp_path, monkeypatch):
|
||||
# A path OUTSIDE the UNSLOTH_ALLOW_LOCAL_PREQUANT_PATH allowlist (including the
|
||||
# default empty allowlist) is refused by the loader, so it must resolve to None
|
||||
# here even when the file exists.
|
||||
ckpt = tmp_path / "model.pt"
|
||||
ckpt.write_bytes(b"x")
|
||||
monkeypatch.setattr(pq, "_allowed_prequant_roots", lambda: [])
|
||||
fam = _fam(prequant_repos = (("fp8", "org/hosted-fp8"),))
|
||||
assert pq.usable_prequant_source(fam, "fp8", path_override = str(ckpt)) is None
|
||||
|
||||
|
||||
def test_usable_source_allowed_present_path_wins(tmp_path, monkeypatch):
|
||||
# Allowlisted AND present: the override is usable and takes priority over the
|
||||
# hosted repo, exactly like resolve_prequant_source.
|
||||
import os
|
||||
|
||||
ckpt = tmp_path / "model.pt"
|
||||
ckpt.write_bytes(b"x")
|
||||
monkeypatch.setattr(pq, "_allowed_prequant_roots", lambda: [os.path.realpath(str(tmp_path))])
|
||||
fam = _fam(prequant_repos = (("fp8", "org/hosted-fp8"),))
|
||||
src = pq.usable_prequant_source(fam, "fp8", path_override = str(ckpt))
|
||||
assert src == PrequantSource(kind = "path", location = str(ckpt), filename = None)
|
||||
|
||||
|
||||
def test_usable_source_repo_unaffected_by_allowlist(monkeypatch):
|
||||
# Hosted-repo sources are first-party and keep resolving with no allowlist at all.
|
||||
monkeypatch.setattr(pq, "_allowed_prequant_roots", lambda: [])
|
||||
fam = _fam(prequant_repos = (("fp8", "org/hosted-fp8"),))
|
||||
src = pq.usable_prequant_source(fam, "fp8")
|
||||
assert src is not None and src.kind == "repo" and src.location == "org/hosted-fp8"
|
||||
|
||||
|
||||
# ── load_prequantized_transformer ────────────────────────────────────────────────
|
||||
class _FakeTransformer:
|
||||
calls: dict = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue