DeepSeek on several AMD cards uses every card when none was named: setup's own pick is no longer 'asked'; old configs of that pick move to every card at the start; the launcher and the app stop keeping it
This commit is contained in:
1 parent
f93ec8a924
commit
6f7f763ce5
5 files changed
+212
-17
No files matched your search
@@ -278,7 +278,7 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
|
||||
const resources=args.resourceProfile&&!ownEngine(config)?resourceSettings({...base0,[USER_KEY]:mine,vision},snapshot.hardware,args.resourceProfile,modelArena(args.model),values0):null;
|
||||
const cfg={...config,...visionPreferences,...(resources?{...resources,ui_resource_profile:args.resourceProfile}:{}),host:'127.0.0.1',open_browser:false,...validateNativeSettings(args.values??{}),vision};
|
||||
/* The app's suggested cards only fill a gap: a model whose settings file already names its GPUs ("gpu": [1, 0], with "gpu_order": "as_given") keeps them (#3256). A card the person picked in the screen always wins. */
|
||||
const namedInFile=(Array.isArray(config.gpu)?config.gpu.length>0:config.gpu!==undefined&&config.gpu!==null&&config.gpu!=='')||!!config.gpu_roles;
|
||||
const namedInFile=((Array.isArray(config.gpu)?config.gpu.length>0:config.gpu!==undefined&&config.gpu!==null&&config.gpu!=='')||!!config.gpu_roles)&&!setupPickedOneCard(config,snapshot.hardware);
|
||||
/* Roles chosen in the screen (Main / Helper / Off per card, gpu-roles.mjs): the card list is the roles' mirror - Helpers first, the Main card LAST, Off cards left out - with "gpu_roles" beside it. Every card Off is allowed: the server says plainly what the engine can do. */
|
||||
if(args.gpuRoles!==undefined){const make=snapshot.hardware?.engine_vendor,cards=(snapshot.hardware?.gpus??[]).filter(g=>!make||!g.vendor||g.vendor===make),named=parseRoles(args.gpuRoles);if(!named)throw new Error('Choose Main, Helper or Off for each graphics card, with one Main.');const known=new Set(cards.map(g=>g.index));if(Object.keys(named).some(k=>!known.has(Number(k))))throw new Error('Choose detected graphics cards.');const roles=Object.fromEntries(cards.map(g=>[g.index,named[g.index]??'off'])),m=mirrorRoles(roles,cards);for(const k of ['gpu','gpu_order','gpu_none','gpu_roles','gpu_cards','hip_ordinal'])delete cfg[k];Object.assign(cfg,m);const count=Array.isArray(m.gpu)?m.gpu.length:m.gpu_none?0:1;cfg.layer_split=count>1?validateNativeSettings({layer_split:args.layerSplit??'auto'}).layer_split:'auto';if(cfg.layer_split!=='auto'&&cfg.layer_split.split(',').length!==count-1)throw new Error('Choose one layer split point between each pair of GPUs.');}
|
||||
else if(args.gpus!==undefined&&!(args.gpusFromRecommendation&&namedInFile)){const detected=new Set((snapshot.hardware?.gpus??[]).map(g=>g.index));if(!Array.isArray(args.gpus)||!args.gpus.length||new Set(args.gpus).size!==args.gpus.length||args.gpus.some(g=>!Number.isInteger(g)||!detected.has(g)))throw new Error('Choose distinct detected GPUs. CPU-only text inference is not supported by this native adapter.');cfg.gpu=args.gpus.length===1?args.gpus[0]:args.gpus;for(const k of ['gpu_roles','gpu_cards','gpu_none'])delete cfg[k];delete cfg.hip_ordinal;cfg.layer_split=args.gpus.length>1?validateNativeSettings({layer_split:args.layerSplit??'auto'}).layer_split:'auto';if(cfg.layer_split!=='auto'&&cfg.layer_split.split(',').length!==args.gpus.length-1)throw new Error('Choose one layer split point between each pair of GPUs.');}
|
||||
@@ -593,3 +593,13 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
|
||||
async function localPreview(path){if(!packaged)throw new Error('Checking local model files is part of the Strata app.');if(typeof path!=='string'||!path.trim()||[...path].some(c=>c.charCodeAt(0)<32))throw new Error('Choose a folder.');return control.importPlan(path.trim());}
|
||||
return {state:publicState,tuneStatus,tuneEffective,tuneOff,tunePresets:{list:()=>autotuner.list(),action:(kind,id,extra)=>autotuner.action(kind,id,extra),undoFor:async args=>autotuner.undoFor(tuneConfig(args).path)},refresh,localPreview,configure,setDownloadDirectory,planModelsFolder,startModelsFolder,interruptedMove,finishInterruptedMove,leaveInterruptedMove,plan,settings,save,settingsFile,openSettingsFile,operation,cancel,unload,resolveInstance,poll,logs:()=>logs.slice(),benchmarkReport:()=>readJson(join(directory,'native-benchmark.json'),null),setDefault(id){defaultId=resolveInstance(id).id;emit();return publicState();},hasLive:()=>[...instances.values()].some(i=>i.status==='ready'),readyInstances:()=>[...instances.values()].filter(i=>i.status==='ready'),defaultInstanceId:()=>defaultId,close};
|
||||
}
|
||||
/* A DeepSeek config on AMD written by setup 0.2.8 or earlier names ONE card and marks it "asked", though setup picked it itself (strata_control/gpu_pick.py): it must not stop the app's recommended cards from applying. A card setup named for itself is the first of the usable cards, largest memory first; another card number was the person's. Roles and a "gpus_by" marker are always honoured. */
|
||||
export function setupPickedOneCard(config,hardware){
|
||||
if(!config||config.arch!=='deepseek41'||config.backend!=='hip'||config.gpus_by||config.gpu_roles||!config.gpus_asked)return false;
|
||||
const one=Array.isArray(config.gpu)?(config.gpu.length===1?config.gpu[0]:null):config.gpu;if(!Number.isInteger(Number(one))||one===null||one==='')return false;
|
||||
const cards=(hardware?.gpus??[]).filter(g=>(g.vendor==='amd')&&g.usable!==false),shares=g=>!!(g.uma||g.integrated||g.unified_gb),vram=g=>Number(g.vram_gb)||0;
|
||||
const real=cards.some(g=>!shares(g)&&vram(g)>=4),keep=cards.filter(g=>!(shares(g)&&real)&&vram(g)>=8);
|
||||
if(process.platform==='win32'||keep.length<2)return false;
|
||||
const first=[...keep].sort((a,b)=>Math.round(vram(b))-Math.round(vram(a))||a.index-b.index)[0];
|
||||
return Number(one)===first.index;
|
||||
}
|
||||
@@ -6496,7 +6496,7 @@ def write_config(path: Path, cfg: dict):
|
||||
# "args_written" (strata_control/user_args.py) is setup's own; "user_args" is not in SETUP_KEYS on purpose: carry_over keeps it,
|
||||
# then applies the person's options over the generated ones
|
||||
SETUP_KEYS = frozenset({"exe", "args", "cwd", "tokenizer", "model_name", "log", "lib_dirs", "port", "backend", "env",
|
||||
"gpu", "gpus_asked", "layer_split", "host", "api_key", "draft_vocab", "vision", "args_written"})
|
||||
"gpu", "gpus_asked", "gpus_by", "layer_split", "host", "api_key", "draft_vocab", "vision", "args_written"})
|
||||
SETUP_ENV = frozenset({"STRATA_HIPBLASLT_TUNING", "STRATA_ROCBLAS_TUNING", "STRATA_RESIDENT_PIN", "STRATA_NO_ARENA_THP", "STRATA_MMQ_KQ", "STRATA_HC_Q8",
|
||||
"STRATA_ROUTE_TAIL_SKIP"}) | frozenset(GFX1103_SWITCHES) | frozenset(GFX1150_SWITCHES) # the "env" entries setup writes (the gfx1103 switches are setup's too: a re-run refreshes them, they do not linger)
|
||||
# 0.1.44 added these three, written for Unsloth's files only (unsloth_default_env). In any other model's config they are the
|
||||
@@ -7078,6 +7078,31 @@ def settings_summary(cfg: dict, port=None) -> str:
|
||||
return " ".join(out) + ("; " if out else "") + "server " + ", ".join(srv)
|
||||
|
||||
|
||||
def widen_setups_one_card(cfg_path: Path, cfg: dict, amd: list) -> dict:
|
||||
"""A DeepSeek run config on AMD that names one card and was written by setup 0.2.8 or earlier (the card was setup's own pick, marked "asked"
|
||||
by mistake) moves to every card that counts, here at the start, with its pack and files untouched. A card the person named
|
||||
(strata_control/gpu_pick.py) stays. Linux only: several AMD cards sharing a model is not supported on Windows."""
|
||||
if WIN or not isinstance(cfg, dict) or cfg.get("gpus_by") or not cfg.get("gpus_asked"):
|
||||
return cfg
|
||||
try:
|
||||
from strata_control import gpu_pick
|
||||
usable = amd_usable_cards(amd)
|
||||
if not gpu_pick.looks_like_setups_pick(cfg, usable):
|
||||
return cfg
|
||||
cards = [c["index"] for c in dsv41_auto_cards(amd, ROOT / "engine")]
|
||||
if len(cards) < 2:
|
||||
return cfg
|
||||
was = gpu_pick.single_card(cfg)
|
||||
new = gpu_pick.widened(cfg, cards)
|
||||
write_config(cfg_path, new)
|
||||
ok(f"DeepSeek now uses all {len(cards)} of your AMD cards (it was set up on GPU {was} alone by an earlier Strata). Nothing is rebuilt. "
|
||||
f"To keep it on one card: ./setup.sh --gpu {was}")
|
||||
return new
|
||||
except Exception as e: # noqa: BLE001 - never stop a start over this
|
||||
warn(f"could not check which cards this model should use ({e})")
|
||||
return cfg
|
||||
|
||||
|
||||
def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_browser=True, yes=False,
|
||||
layer_split=None, keep=None) -> int:
|
||||
"""Start the model. Nothing is installed, downloaded or compiled while it starts (strata_control/acquisition.py):
|
||||
@@ -7132,13 +7157,15 @@ def _start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open
|
||||
if miss:
|
||||
fail("the installed engine has no code for " + ", ".join(f"{x['name']} ({x['arch']})" for x in miss),
|
||||
"set it up for these cards: ./setup.sh --setup --backend hip --gpus " + ",".join(map(str, gpu)))
|
||||
cfg["gpu"], cfg["gpus_asked"] = gpu, True
|
||||
cfg["gpu"], cfg["gpus_asked"], cfg["gpus_by"] = gpu, True, "person"
|
||||
cfg["layer_split"] = layer_split or cfg.get("layer_split") or "auto"
|
||||
split_budget(cfg, yes, True) # #498: before it is saved (asks when the RAM is short, #737)
|
||||
write_config(cfg_path, cfg)
|
||||
gpu = None
|
||||
elif gpu is not None:
|
||||
cmd += ["--gpu", str(gpu)]
|
||||
else:
|
||||
cfg = widen_setups_one_card(cfg_path, cfg, amd) # a DeepSeek config from setup 0.2.8 and earlier: setup's own one-card pick
|
||||
found = []
|
||||
use = gpu if gpu is not None else cfg.get("gpu")
|
||||
if isinstance(use, list):
|
||||
@@ -8133,7 +8160,7 @@ def dsv41_manual_steps(eng: Path) -> str:
|
||||
"and run it again. Strata checks it before it is used.")
|
||||
|
||||
|
||||
def get_dsv41_engine(eng: Path, hip: bool, package: str | None = None, feed: str | None = None) -> Path | None:
|
||||
def get_dsv41_engine(eng: Path, hip: bool, package: str | None = None, feed: str | None = None, archs=None) -> Path | None:
|
||||
"""The DeepSeek engine package next to the engine `eng`: one the person gave (--dsv41-package) or put in engine-dsv41/ by hand, else downloaded from
|
||||
the signed feed `feed` (--feed; else STRATA_UPDATE_FEED, a remembered https feed, or the release's). Checked first either way; its
|
||||
strata-dsv41, or None when it cannot be had."""
|
||||
@@ -8157,6 +8184,8 @@ def get_dsv41_engine(eng: Path, hip: bool, package: str | None = None, feed: str
|
||||
if hip:
|
||||
from strata_control import updater
|
||||
hw = {**updater.detect_hardware(), "backend": "hip", "backend_source": "requested"}
|
||||
if archs: # the package is chosen for the cards this model runs on, not for every card in the PC
|
||||
hw["gfx"] = sorted({str(x) for x in archs})
|
||||
exe = dsv41_engine.install(root, source, hardware=hw, emit=lambda m: say(" " + m))
|
||||
if exe is None:
|
||||
warn("no DeepSeek engine package could be fetched (see above)")
|
||||
@@ -8384,6 +8413,50 @@ def dsv41_smoke(exe: Path, pack: Path, lib_dirs, gpus=None, timeout: int = 5400)
|
||||
return r.returncode == 0, text[-1500:].encode(enc, "replace").decode(enc, "replace")
|
||||
|
||||
|
||||
def cards_named(a, hip: bool = False) -> bool:
|
||||
"""Did the person name the cards (--gpu / --gpus)? On AMD setup's own pick is written into a.gpu further on (other steps rely on it), so
|
||||
the AMD branch records the answer first (a._cards_named); NVIDIA keeps its way (choose_gpus sets a.gpu to the cards in use)."""
|
||||
named = getattr(a, "_cards_named", None)
|
||||
return bool(named) if (hip and named is not None) else bool(a.gpu is not None or a.gpus)
|
||||
|
||||
|
||||
def amd_usable_cards(amd) -> list:
|
||||
"""The AMD cards that count for a model (gpu_fit.usable_cards: no integrated chip beside a card with memory of its own, none under 8 GB)."""
|
||||
from strata_control import gpu_fit
|
||||
return gpu_fit.usable_cards([{**g, "vendor": "amd", "usable": amd_problem(g) is None} for g in amd])[0]
|
||||
|
||||
|
||||
def dsv41_covered_archs(eng) -> tuple:
|
||||
"""The AMD architectures the installed DeepSeek engine package holds code for (its manifest), else what the release's package is built for."""
|
||||
from strata_control import dsv41_fit
|
||||
try:
|
||||
from strata_control import engine_component as ec
|
||||
exe = dsv41_exe(Path(eng))
|
||||
if exe is not None and (exe.parent / ec.MANIFEST).is_file():
|
||||
archs = ec.read_manifest(exe.parent).hip_archs
|
||||
if archs:
|
||||
return tuple(archs)
|
||||
except Exception: # noqa: BLE001 - the release's list is the fallback
|
||||
pass
|
||||
return tuple(dsv41_fit.DSV41_HIP_ARCHS)
|
||||
|
||||
|
||||
def dsv41_auto_cards(amd, eng) -> list:
|
||||
"""DeepSeek on AMD with no card named: every card that counts and the engine package can run (one card on Windows: several AMD cards sharing
|
||||
a model is Linux-only). The same rule as `strata launch --plan` (strata_control/dsv41_fit.run_cards). What is left out is said."""
|
||||
from strata_control import dsv41_fit
|
||||
# only real AMD cards (gfx...): sycl/setup_intel.py runs this same branch with its Intel cards in `amd` (arch "xe" / "i915"), and the DeepSeek
|
||||
# engine has no Intel package: those keep the one card setup picked
|
||||
pool = [{**g, "vendor": "amd", "usable": amd_problem(g) is None} for g in amd
|
||||
if amd_problem(g) is None and str(g.get("arch") or "").startswith("gfx")]
|
||||
keep, left = dsv41_fit.run_cards(pool, "amd", windows=WIN, covered=dsv41_covered_archs(eng))
|
||||
byid = {g["index"]: g for g in amd}
|
||||
for c in left:
|
||||
if c.get("why_ignored") and not str(c["why_ignored"]).startswith("it shares the system memory"):
|
||||
say(f" Not used for DeepSeek: GPU {c.get('index')} ({c.get('name')}): {c['why_ignored']}.")
|
||||
return [byid[c["index"]] for c in keep]
|
||||
|
||||
|
||||
def dsv41_cards(gpu: dict, all_cards: list | None, asked: bool) -> list:
|
||||
"""The cards the model runs on: the ones asked for (--gpu / --gpus), else every card setup can use (recommend: the model is
|
||||
larger than any one card, so the more graphics memory the more of its experts stay off the CPU)."""
|
||||
@@ -8431,7 +8504,8 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
udlow = md.get("recipe") == "udlow" # Unsloth's UD-IQ1_S / UD-IQ1_M: packed and checked like the IST-DAS sets; shard 5 is the Engram
|
||||
ista = md.get("recipe") in ("ista", "udlow")
|
||||
tag = fam["tag"] + model
|
||||
cards = dsv41_cards(gpu, all_cards, bool(a.gpu is not None or a.gpus))
|
||||
named = cards_named(a, hip)
|
||||
cards = dsv41_cards(gpu, all_cards, named)
|
||||
ctx = a.context or DSV41_CONTEXT
|
||||
if dsv41_context.problem(ctx): # 8K to 1M: the model reads 1,048,576 positions (Project Maya #442); a size it cannot address stops here, before any download
|
||||
fail(dsv41_context.problem(ctx), "--context takes 8192 up to 1048576 (8K, 32K, 64K, 128K, 256K, 512K, 1M); the default is 8192")
|
||||
@@ -8461,7 +8535,8 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
for f in [*shards, *shared]) / 1e9
|
||||
probe = folder if folder.exists() else (folder.parent if folder.parent.exists() else Path(a.models_dir))
|
||||
free = free_gb(probe)
|
||||
plan = dsv41_fit.plan([{**c, "vram_gb": float(c.get("vram_gb") or 0)} for c in cards], ram, free if left else None, ctx, model=model)
|
||||
plan = dsv41_fit.plan([{**c, "vram_gb": float(c.get("vram_gb") or 0)} for c in cards], ram, free if left else None, ctx, model=model,
|
||||
named=True) # `cards` are decided above (dsv41_auto_cards / the person's): the plan describes them
|
||||
say()
|
||||
for line in plan["lines"]:
|
||||
say(" " + line)
|
||||
@@ -8523,7 +8598,8 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
fail("Strata can't reach GitHub to download the DeepSeek engine.",
|
||||
"Check the internet connection and run the same command again. " + dsv41_manual_steps(eng))
|
||||
if exe is None and not getattr(a, "build", False):
|
||||
get_dsv41_engine(eng, hip, getattr(a, "dsv41_package", None), getattr(a, "feed", None))
|
||||
get_dsv41_engine(eng, hip, getattr(a, "dsv41_package", None), getattr(a, "feed", None),
|
||||
archs=[c.get("arch") for c in cards if c.get("arch")] if hip else None)
|
||||
exe = dsv41_exe(eng)
|
||||
if (exe is not None and not getattr(a, "dsv41_package", None) and not getattr(a, "build", False)
|
||||
and not (os.environ.get("STRATA_DSV41_EXE") or "").strip() and exe.parent.parent == dsv41_engine_dir(eng)):
|
||||
@@ -8531,6 +8607,12 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
if exe is not None and exe.parent != Path(eng):
|
||||
from strata_control import dsv41_engine
|
||||
lib_dirs = [*lib_dirs, *dsv41_engine.lib_dirs(exe)] # its own package, and the rocm/bin an AMD package keeps the ROCm DLLs in
|
||||
if hip and exe is not None and named: # cards the person named that this package holds no code for: said, never refused
|
||||
covered = dsv41_covered_archs(eng)
|
||||
for c in cards:
|
||||
if c.get("arch") and c["arch"] not in covered:
|
||||
warn(f"GPU {c['index']} ({c['name']}, {c['arch']}): this DeepSeek engine package holds code for {', '.join(covered)} only, so it may "
|
||||
"not start on that card. Leave it out (--gpus ...) to be sure.")
|
||||
if exe is None:
|
||||
if os.environ.get("STRATA_VERBOSE") == "1" or "--verbose" in sys.argv:
|
||||
say(" Details for developers: build it with cmake -DSTRATA_BUILD_DSV41=ON -DCMAKE_CUDA_ARCHITECTURES=<your card: 86 RTX 30, 89 RTX 40, 120 RTX 50> "
|
||||
@@ -8612,7 +8694,7 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
warn("the 16-word test run was skipped (STRATA_DSV41_NO_SMOKE=1)")
|
||||
else:
|
||||
say(" Testing the model with a short question (a few minutes: the engine reads the first experts from the disk) ...")
|
||||
good, why = dsv41_smoke(exe, pack, lib_dirs, [c["index"] for c in cards] if (a.gpu is not None or a.gpus) else None)
|
||||
good, why = dsv41_smoke(exe, pack, lib_dirs, [c["index"] for c in cards] if (named or (hip and len(cards) > 1)) else None)
|
||||
if not good:
|
||||
fail("the model does not answer sensibly after the preparation: " + (why.splitlines()[-1] if why else "no answer"),
|
||||
f"delete {pack} and run setup again so the pack is built fresh; if the test fails again, "
|
||||
@@ -8649,9 +8731,14 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
|
||||
if mac:
|
||||
cfg["backend"] = "metal"
|
||||
idx = [c["index"] for c in cards]
|
||||
if len(idx) > 1 or a.gpu is not None or a.gpus:
|
||||
if len(idx) > 1 or named:
|
||||
cfg["gpu"] = idx if len(idx) > 1 else idx[0]
|
||||
cfg["gpus_asked"] = True
|
||||
if hip: # who chose them (strata_control/gpu_pick.py): setup's own pick is not "asked"
|
||||
cfg["gpus_by"] = "person" if named else "setup"
|
||||
if named:
|
||||
cfg["gpus_asked"] = True
|
||||
else:
|
||||
cfg["gpus_asked"] = True
|
||||
if a.host:
|
||||
cfg["host"] = a.host
|
||||
if a.api_key:
|
||||
@@ -9194,7 +9281,14 @@ def main() -> int:
|
||||
a.gpus = a.gpus or ",".join(str(g) for g in ch["gpu"])
|
||||
a.layer_split = a.layer_split or ch.get("layer_split")
|
||||
else:
|
||||
a.gpu = a.gpu if a.gpu is not None else ch.get("gpu")
|
||||
try: # a card setup picked itself is not a choice to carry over (strata_control/gpu_pick.py)
|
||||
from strata_control import gpu_pick
|
||||
earlier = json.loads(prev.read_text(encoding="utf-8-sig"))
|
||||
keep_card = gpu_pick.chosen_by_person(earlier, amd_usable_cards(amd_gpus()))
|
||||
except (OSError, ValueError):
|
||||
keep_card = True
|
||||
if keep_card:
|
||||
a.gpu = a.gpu if a.gpu is not None else ch.get("gpu")
|
||||
a.yes = True
|
||||
global GPU_PICK, OLD_GPUS
|
||||
# starting an installed model: --gpus 0,2 (or all) saves those cards for it and starts on them (it used to start
|
||||
@@ -9308,6 +9402,7 @@ def main() -> int:
|
||||
"your user in the render and video groups)")
|
||||
if not usable:
|
||||
fail("no AMD GPU Strata can use", f"the AMD backend runs on {AMD_CARDS}")
|
||||
a._cards_named = bool(a.gpu is not None or a.gpus) # before setup's own pick is written into a.gpu below
|
||||
if a.gpus: # a layer split across these cards, the first one the main
|
||||
chosen = amd_parse_gpus(a.gpus, amd)
|
||||
gpu = chosen[0]
|
||||
@@ -9503,7 +9598,7 @@ def main() -> int:
|
||||
if family in OWN_PATH_FAMILIES: # Qwen3.6: its own engine path, its own steps 2-7
|
||||
return install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted)
|
||||
if family in MULTI_FILE_FAMILIES: # DeepSeek-V4.1-Flash: nine shards, its own engine, several cards
|
||||
all_cards = amd_ok if hip else [g for g in found if gpu_problem(g) is None]
|
||||
all_cards = (None if (WIN or getattr(a, "_cards_named", False)) else dsv41_auto_cards(amd, ROOT / "engine")) if hip else [g for g in found if gpu_problem(g) is None]
|
||||
gpu = {**gpu, "cards": chosen}
|
||||
return install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted, all_cards)
|
||||
fam = FAMILIES[family]
|
||||
|
||||
@@ -356,11 +356,15 @@ def apply_cards(cfg: dict, gpus: "list[int] | dict | None") -> None:
|
||||
cfg.pop("layer_split", None)
|
||||
|
||||
|
||||
def installed_cards(base: dict | None) -> list[int] | None:
|
||||
def installed_cards(base: dict | None, usable: list[dict] | None = None) -> list[int] | None:
|
||||
"""The cards the installed model's own config names after a choice (setup --gpu / --gpus, the app's card pick: "gpus_asked"), in its order;
|
||||
None when it names none or was never asked."""
|
||||
None when it names none or was never asked, or when setup picked them itself (strata_control/gpu_pick.py: a DeepSeek config of setup 0.2.8
|
||||
and earlier marks setup's one-card pick as asked; `usable`: the cards that count on this PC, needed to tell the two apart)."""
|
||||
if not isinstance(base, dict) or not (base.get("gpus_asked") or base.get("gpu_roles")):
|
||||
return None
|
||||
from strata_control import gpu_pick
|
||||
if not gpu_pick.chosen_by_person(base, usable):
|
||||
return None
|
||||
g = base.get("gpu")
|
||||
if g is None or g == "":
|
||||
return None
|
||||
@@ -387,7 +391,11 @@ def cards_for_launch(s: S.LaunchSettings, catalog, ram_gb: float | None = None,
|
||||
return None
|
||||
if s.gpus:
|
||||
return [int(g) for g in s.gpus]
|
||||
if installed_cards(base) or (isinstance(base, dict) and base.get("gpu_roles")):
|
||||
try:
|
||||
usable_now = catalog.computer().usable_gpus
|
||||
except Exception: # noqa: BLE001 - without the card list a saved card is kept, as before
|
||||
usable_now = None
|
||||
if installed_cards(base, usable_now) or (isinstance(base, dict) and base.get("gpu_roles")):
|
||||
return None
|
||||
try:
|
||||
from strata_control import gpu_roles
|
||||
@@ -948,7 +956,11 @@ class Runner:
|
||||
roles = base.get("gpu_roles")
|
||||
if isinstance(roles, dict) and roles:
|
||||
return ["--gpu-roles", ",".join(f"{k}={v}" for k, v in sorted(roles.items(), key=lambda kv: int(kv[0])))]
|
||||
cards = installed_cards(base)
|
||||
try:
|
||||
usable_now = self.catalog.computer().usable_gpus
|
||||
except Exception: # noqa: BLE001
|
||||
usable_now = None
|
||||
cards = installed_cards(base, usable_now)
|
||||
if cards:
|
||||
return ["--gpus", ",".join(str(g) for g in cards)] if len(cards) > 1 else ["--gpu", str(cards[0])]
|
||||
except Exception: # noqa: BLE001 - never block a launch over remembering the cards
|
||||
|
||||
@@ -620,7 +620,7 @@ class CardsScreen(Base):
|
||||
"""The cards the installed model was set to by a person's choice (kept unless this launch names others)."""
|
||||
from strata_cli.launch.runner import installed_cards
|
||||
try:
|
||||
return installed_cards(self.ctx.base_config())
|
||||
return installed_cards(self.ctx.base_config(), self.ctx.computer.usable_gpus)
|
||||
except Exception: # noqa: BLE001
|
||||
return None
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
"""Who chose the graphics cards of an installed model: the person, or setup's own pick.
|
||||
|
||||
Setup used to write "gpus_asked": true for every single-card run config, also when setup had picked the card itself (a DeepSeek run on a PC
|
||||
with several AMD cards: setup took the first card, called it asked, and every later launch handed that "choice" back, so four cards ran
|
||||
on one). New configs say who chose in "gpus_by" ("person" or "setup"). A config without it is judged here:
|
||||
|
||||
* roles ("gpu_roles") and card lists of two or more are the person's (setup never wrote a list unless the cards were named or all used);
|
||||
* a single card is setup's pick when the model is DeepSeek on AMD, the PC has more than one card that counts, and the card is the one setup
|
||||
would have taken (the first of the usable cards, largest memory first). A person who named another card (``--gpu 2``) keeps it;
|
||||
one who named exactly the card setup would have taken cannot be told from setup's own pick and is moved to all cards once, with a plain
|
||||
line saying how to keep one card (``--gpu N``, remembered from then on).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
ASKED_BY_PERSON = "person"
|
||||
PICKED_BY_SETUP = "setup"
|
||||
|
||||
|
||||
def _is_deepseek_amd(cfg: dict) -> bool:
|
||||
return str(cfg.get("arch") or "") == "deepseek41" and str(cfg.get("backend") or "") == "hip"
|
||||
|
||||
|
||||
def single_card(cfg: dict) -> int | None:
|
||||
g = cfg.get("gpu")
|
||||
if isinstance(g, bool) or g is None or g == "":
|
||||
return None
|
||||
if isinstance(g, (list, tuple)):
|
||||
return int(g[0]) if len(g) == 1 and str(g[0]).strip().lstrip("-").isdigit() else None
|
||||
return int(str(g).strip()) if str(g).strip().lstrip("-").isdigit() else None
|
||||
|
||||
|
||||
def setup_pick_index(usable: list[dict]) -> int | None:
|
||||
"""The card setup takes when nothing is named: the usable cards, largest memory first, then the lower number."""
|
||||
if not usable:
|
||||
return None
|
||||
first = min(usable, key=lambda c: (-round(float(c.get("vram_gb") or 0)), int(c.get("index", 0))))
|
||||
return int(first.get("index", 0))
|
||||
|
||||
|
||||
def chosen_by_person(cfg: dict | None, usable: list[dict] | None = None) -> bool:
|
||||
"""True when the cards in `cfg` are the person's choice (keep them); False when setup picked them (they may be widened).
|
||||
`usable`: the cards that count on this PC (strata_control.gpu_fit.usable_cards), needed only to judge a legacy single AMD card."""
|
||||
if not isinstance(cfg, dict):
|
||||
return False
|
||||
if cfg.get("gpu_roles"):
|
||||
return True
|
||||
by = cfg.get("gpus_by")
|
||||
if by in (ASKED_BY_PERSON, PICKED_BY_SETUP):
|
||||
return by == ASKED_BY_PERSON
|
||||
if not cfg.get("gpus_asked"):
|
||||
return False
|
||||
return not looks_like_setups_pick(cfg, usable)
|
||||
|
||||
|
||||
def looks_like_setups_pick(cfg: dict, usable: list[dict] | None) -> bool:
|
||||
"""A config from setup 0.2.8 and earlier: DeepSeek on AMD, one card, on a PC where more than one card counts, and the card setup would have taken."""
|
||||
if not _is_deepseek_amd(cfg) or cfg.get("gpus_by") or cfg.get("gpu_roles"):
|
||||
return False
|
||||
one = single_card(cfg)
|
||||
if one is None or not usable or len(usable) < 2:
|
||||
return False
|
||||
return one == setup_pick_index(usable)
|
||||
|
||||
|
||||
def widened(cfg: dict, cards: list[int]) -> dict:
|
||||
"""`cfg` with setup's own pick of `cards` (two or more): card list, no 'asked' mark, and the marker that setup chose them."""
|
||||
out = dict(cfg)
|
||||
out["gpu"] = list(cards) if len(cards) > 1 else cards[0]
|
||||
out.pop("gpus_asked", None)
|
||||
out["gpus_by"] = PICKED_BY_SETUP
|
||||
out.pop("hip_ordinal", None)
|
||||
return out
|
||||
|
||||
|
||||
def describe(cfg: dict, usable: list[dict] | None) -> dict[str, Any]:
|
||||
return {"by_person": chosen_by_person(cfg, usable), "legacy": not cfg.get("gpus_by") and bool(cfg.get("gpus_asked"))}
|
||||
Reference in new issue
Block a user