okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""The serving profile of a four-card AMD box: 4 x Radeon AI PRO R9700 (32 GB, gfx1201) running Qwen3.8-Flash-Next IQ3_S. 2 3Measured on that box (docs/BATCHING.md, "Four R9700 cards: the serving profile"): the cards hold the whole model, so what limits 4them is how many requests decode together and how the four stages are fed, not memory. The profile sets 5 6* 32 slots in 4 pipelined groups (one group per card), instead of the launcher's 4 requests at a time; 7* the layer split 13,26,39: the output head costs about four layers on the last card, so it gets 9 layers and the others 13; 8* a 2048-token prompt chunk: a smaller chunk reads long prompts faster beside the decodes of the other slots; 9* the three batch switches STRATA_QSA_SLOTS, STRATA_BATCH_SELF_COMMIT and STRATA_SLOT_COPY_DIRECT, which change how the work is 10scheduled and copied, not what is computed (tools/batch_test.py: every slot decodes the tokens it decodes alone). 11 12Recommend, never force: a setting the person made (the config, `--parallel`, `--layer-split`, an advanced flag, an environment 13variable) always wins, the profile only fills what is not set, and `STRATA_FOUR_CARD_PROFILE=0` (or "four_card_profile": false in 14the run config) turns it off. Only this hardware class is touched; every other computer gets exactly what it got before. 15 16Pure functions, no I/O (the callers pass the cards and the run config). 17""" 18 19from __future__import annotations 20 21import os 22 23PARALLEL = 32 # slots (requests decoding together) 24GROUPS = 4 # pipelined groups: one per card 25LAYER_SPLIT = "13,26,39" # Qwen3.8-Flash-Next has 48 layers: 13 / 13 / 13 / 9 (the output head sits on the last card) 26PREFILL_CHUNK = "2048" 27BATCH_ENV = {"STRATA_QSA_SLOTS" :"1" ,"STRATA_BATCH_SELF_COMMIT" :"1" ,"STRATA_SLOT_COPY_DIRECT" :"1" } 28PROMPT_CACHE_OFF = False # --prompt-cache 0 is not part of the default: see docs/BATCHING.md 29MIN_CARD_GB = 28.0 # a 32 GB card reports a little less than its name 30CARDS = 4 31OFF_VALUES = ("0" ,"off" ,"no" ,"false" ) 32 33 34def disabled (cfg :dict | None = None )-> bool : 35"""The person turned the profile off: STRATA_FOUR_CARD_PROFILE=0 in the environment, or "four_card_profile": false in the config.""" 36if str (os .environ .get ("STRATA_FOUR_CARD_PROFILE" ,"" )).strip ().lower ()in OFF_VALUES : 37return True 38return bool (cfg )and cfg .get ("four_card_profile" )is False 39 40 41def card_class (cards :list [dict ])-> bool : 42"""Exactly four AMD cards of one kind, each with at least MIN_CARD_GB: the Radeon AI PRO R9700 (the 32 GB gfx12 card this was 43measured on).""" 44if len (cards )!= CARDS : 45return False 46names = {str (c .get ("name" )or "" )for c in cards } 47if len (names )!= 1 or "R9700" not in next (iter (names )).upper ().replace (" " ,"" ): 48return False 49return all (str (c .get ("vendor" )or "amd" ).lower ()== "amd" and float (c .get ("vram_gb" )or 0.0 )>= MIN_CARD_GB for c in cards ) 50 51 52def model_ok (cfg :dict )-> bool : 53"""The measured model: Qwen3.8-Flash-Next at IQ3_S (48 layers; the pack that fits whole on four 32 GB cards).""" 54text = " " .join ([str (cfg .get ("model_name" )or "" )]+ [str (a )for a in cfg .get ("args" )or []]).lower ().replace ("-" ,"_" ).replace ("." ,"_" ) 55return "qwen3_8" in text and "iq3_s" in text 56 57 58def applies (cards :list [dict ],cfg :dict )-> bool : 59args = [str (a )for a in cfg .get ("args" )or []] 60return (not disabled (cfg ))and card_class (cards )and cfg .get ("backend" ,"hip" )== "hip" and model_ok (cfg ) \ 61and "--peer-device" not in args and not cfg .get ("replicas" ) 62 63 64def apply (cards :list [dict ],cfg :dict ,* ,parallel_given :bool = False )-> list [str ]: 65"""Fill the profile into the run config `cfg` (in place) where the person has not chosen; returns the plain lines to show. 66`parallel_given`: the person named a number of requests (--parallel): then only the split, the chunk and the switches are 67filled (the engine groups the slots itself).""" 68if not applies (cards ,cfg ): 69return [] 70args = [str (a )for a in cfg .get ("args" )or []] 71env = dict (cfg .get ("env" )or {}) 72notes :list [str ]= [] 73if str (cfg .get ("layer_split" )or "auto" )== "auto" and "--layer-split" not in args : 74cfg ["layer_split" ]= LAYER_SPLIT 75notes .append (f"layer split { LAYER_SPLIT } : the last card also holds the output head, so it takes fewer layers" ) 76if "--prefill" not in args : 77args .extend (["--prefill" ,PREFILL_CHUNK ]) 78elif args [args .index ("--prefill" )+ 1 :args .index ("--prefill" )+ 2 ]== ["auto" ]:# "auto" is what setup writes, not a choice 79args [args .index ("--prefill" )+ 1 ]= PREFILL_CHUNK 80if PROMPT_CACHE_OFF and "--prompt-cache" not in args : 81args .extend (["--prompt-cache" ,"0" ]) 82for k ,v in BATCH_ENV .items (): 83if k not in os .environ :# an environment variable of the person's own wins 84env .setdefault (k ,v ) 85if not parallel_given and "parallel" not in cfg and not {"--batch" ,"--slots" }& set (args ): 86cfg ["parallel" ]= PARALLEL 87if "--batch-groups" not in args : 88args .extend (["--batch-groups" ,str (GROUPS )]) 89notes .append (f" { PARALLEL } requests at once in { GROUPS } groups, one group per card (--parallel N changes it)" ) 90cfg ["args" ]= args 91cfg ["env" ]= env 92return notes