@@ -112,11 +112,6 @@ def load_platforms(path: Path) -> dict:
112112 return platforms
113113
114114
115- REPO = ROOT .parents [1 ]
116- # launch-script exports that are serving/benchmark plumbing, not kernel selection
117- _RECIPE_ENV_SKIP = re .compile (r"^(AIPERF_|HF_|MODEL|PORT|RESULT|SERVER|LMCACHE|PYTHONHASHSEED|VLLM_ENGINE_READY)" )
118-
119-
120115def family (name : str ) -> str :
121116 """Hardware family of a runner label: 'cluster:mi355x-amds' -> 'mi355x'."""
122117 return name .removeprefix ("cluster:" ).split ("-" )[0 ]
@@ -126,41 +121,6 @@ def is_amd(runner: str) -> bool:
126121 return family (runner ).startswith ("mi" )
127122
128123
129- def recipe_env (script : Path ) -> dict [str , str ]:
130- """The launch script's unconditional top-level `export NAME=value` lines (no expansion)."""
131- env = {}
132- for line in script .read_text ().splitlines ():
133- m = re .fullmatch (r"export ([A-Z_][A-Z0-9_]*)=(['\"]?)([^$`'\"\s]*)\2" , line )
134- if m and not _RECIPE_ENV_SKIP .match (m .group (1 )):
135- env [m .group (1 )] = m .group (3 )
136- return env
137-
138-
139- def load_recipes (keys : set [str ]) -> dict [str , dict ]:
140- """InferenceX recipes (configs/*-master.yaml) by key: image, framework, hardware family,
141- and the env its single-node launch script exports."""
142- import yaml
143-
144- out = {}
145- for vendor in ("amd" , "nvidia" ):
146- configs = yaml .safe_load ((REPO / f"configs/{ vendor } -master.yaml" ).read_text ())
147- for key in keys & configs .keys ():
148- r = configs [key ]
149- hw = family (r ["runner" ])
150- spec = any (s .get ("spec-decoding" ) == "mtp" for sc in (r .get ("scenarios" ) or {}).values ()
151- for s in (sc [0 ].get ("search-space" , []) if isinstance (sc , list ) and sc else []))
152- name = f"{ r ['model-prefix' ]} _{ r ['precision' ]} _{ hw } { '_mtp' if spec else '' } .sh"
153- scripts = [REPO / "benchmarks/single_node" / sub / name for sub in ("agentic" , "" )]
154- script = next ((x for x in scripts if x .is_file ()), None )
155- out [key ] = {"image" : r ["image" ], "framework" : r ["framework" ], "hardware" : hw ,
156- "script" : str (script .relative_to (REPO )) if script else None ,
157- "env" : recipe_env (script ) if script else {}}
158- missing = keys - out .keys ()
159- if missing :
160- raise ValueError (f"unknown InferenceX recipes: { sorted (missing )} " )
161- return out
162-
163-
164124def write_json (path : Path , value : object ) -> None :
165125 path .parent .mkdir (parents = True , exist_ok = True )
166126 temporary = path .with_suffix (path .suffix + ".tmp" )
@@ -177,8 +137,12 @@ def plan(
177137 chunk_size : int ,
178138 platforms : dict [str , dict ],
179139 mode : str = "timing" ,
180- recipes : dict [ str , dict ] | None = None ,
140+ find_recipe = None ,
181141) -> dict :
142+ """Shards for a selection. A case whose source checkpoint InferenceX serves on this
143+ hardware runs under that recipe (find_recipe(framework, hardware, checkpoints),
144+ operatorx.recipes.find): its image, launch env and server arguments."""
145+ from operatorx .recipes import FRAMEWORKS , checkpoints
182146 if runner not in RUNNERS :
183147 raise ValueError (f"unsupported runner: { runner } " )
184148 if mode not in MODES :
@@ -211,6 +175,7 @@ def plan(
211175 if not 1 <= chunk_size <= 500 :
212176 raise ValueError ("chunk size must be between 1 and 500" )
213177 groups = defaultdict (list )
178+ recipes_seen : dict [str , dict ] = {}
214179 excluded = 0
215180 for name , shapes in sorted (testlists .items ()):
216181 for shape in shapes :
@@ -221,24 +186,28 @@ def plan(
221186 if ws not in world_sizes :
222187 excluded += 1
223188 continue
224- # an entry naming an InferenceX recipe for this hardware runs with that recipe's
225- # image and launch env, in its own shard
226- recipe = next (( k for k in shape . get ( "recipes" , ()) if recipes and k in recipes
227- and recipes [ k ][ "hardware" ] == family ( runner )
228- and recipes [ k ][ "framework" ] in backends ), None )
229- groups [(ws , recipe or "" )].append ({"testlist" : name , "shape" : shape })
189+ recipe = next (( r for b in backends if b in FRAMEWORKS and find_recipe
190+ for r in [ find_recipe ( b , family ( runner ), checkpoints ( shape . get ( "sources" )))] if r ),
191+ None )
192+ if recipe :
193+ recipes_seen [ recipe [ "recipe" ]] = recipe
194+ groups [(ws , recipe [ "recipe" ] if recipe else "" )].append ({"testlist" : name , "shape" : shape })
230195 image_groups = defaultdict (list )
231196 for backend in sorted (set (backends )):
232197 image_groups [images [backend ]["image" ]].append (backend )
233198 cells = []
234199 shards = []
235200 for (ws , recipe ), cases in sorted (groups .items ()):
201+ rest = image_groups
236202 if recipe :
237- r = recipes [recipe ]
238- shards .append ((r ["image" ], [r ["framework" ]], ws , cases ,
239- {"recipe" : recipe , "recipe_script" : r ["script" ], "env" : r ["env" ]}))
240- else :
241- shards += [(image , selected , ws , cases , {}) for image , selected in sorted (image_groups .items ())]
203+ r = recipes_seen [recipe ]
204+ framework = next (b for b in backends if b in FRAMEWORKS )
205+ shards .append ((r ["image" ], [framework ], ws , cases ,
206+ {"recipe" : recipe , "checkpoint" : r ["checkpoint" ], "env" : r ["env" ],
207+ "engine_args" : r ["engine_args" ]}))
208+ # the other backends run the same cases on their own images
209+ rest = {i : [b for b in bs if b != framework ] for i , bs in image_groups .items ()}
210+ shards += [(image , selected , ws , cases , {}) for image , selected in sorted (rest .items ()) if selected ]
242211 for image , selected , ws , cases , extra in shards :
243212 for offset in range (0 , len (cases ), chunk_size ):
244213 cell = {
@@ -607,6 +576,7 @@ def interrupted(signum, frame):
607576 OPERATORX_BACKENDS = "," .join (cell ["backends" ]),
608577 OPERATORX_MODE = cell .get ("mode" , "timing" ),
609578 OPERATORX_RECIPE = cell .get ("recipe" , "" ),
579+ OPERATORX_ENGINE_ARGS = json .dumps (cell .get ("engine_args" ) or {}),
610580 OPERATORX_TESTLISTS = "," .join (
611581 sorted ({c ["testlist" ] for c in cell ["cases" ]})
612582 ),
@@ -831,6 +801,8 @@ def main() -> None:
831801 if args .command == "plan" :
832802 import tomllib
833803
804+ from operatorx import recipes
805+
834806 names = args .testlists .split ("," )
835807 if any (not re .fullmatch (r"[A-Za-z0-9_-]+" , n ) for n in names ):
836808 raise ValueError ("invalid testlist name" )
@@ -855,8 +827,7 @@ def main() -> None:
855827 args .chunk_size ,
856828 load_platforms (args .platform_config ),
857829 args .mode ,
858- recipes = load_recipes ({k for shapes in lists .values () for s in shapes for k in s .get ("recipes" , ())})
859- if any (s .get ("recipes" ) for shapes in lists .values () for s in shapes ) else None ,
830+ find_recipe = recipes .find ,
860831 )
861832 digests = {c ["image" ]: "" for c in result ["include" ]}
862833 for image in digests :
0 commit comments