core.inference.shards_spec#
Parser and typed representation (:class:InferenceShardSpec) for the
--inference-shards shard-layout string.
Module Contents#
Classes#
One inference shard’s parallelism – the canonical shard-layout type. |
Functions#
Coerce the public shard-spec input (a spec string, a list of |
|
Whether a shard spec tags any shard with a |
|
Parse + validate the |
|
Assert the shards partition the world exactly. |
Data#
API#
- core.inference.shards_spec.VALID_INT_KEYS#
(‘tp’, ‘pp’, ‘ep’, ‘expt_tp’, ‘dp’, ‘cp’)
- core.inference.shards_spec.VALID_ROLES#
(‘prefill’, ‘decode’)
- core.inference.shards_spec.VALID_KEYS#
()
- class core.inference.shards_spec.InferenceShardSpec#
One inference shard’s parallelism – the canonical shard-layout type.
Frozen and self-validating:
expt_tpdefaults totp(resolved at construction), the expert decomposition is checked to tile within the shard, androle("prefill"/"decode"for disaggregation, elseNone) is validated. A list of these, produced by :func:normalize_shard_specs, is what every inference-shard consumer (the PG builder, the disaggregation setup) operates on.- tp: int#
1
- pp: int#
1
- ep: int#
1
- dp: int#
1
- cp: int#
1
- expt_tp: Optional[int]#
None
- role: Optional[str]#
None
- __post_init__()#
- property world_size: int#
Number of ranks this shard occupies (
tp * pp * dp).
- to_dict() dict#
Plain-dict form (e.g. for serialization or external consumers).
- core.inference.shards_spec.normalize_shard_specs(
- shards: Union[str, Sequence[core.inference.shards_spec.InferenceShardSpec], Sequence[dict]],
- world_size: int,
Coerce the public shard-spec input (a spec string, a list of
- Class:
InferenceShardSpec, or a list of raw dicts) into the validated list of :class:InferenceShardSpecthe shard builders consume.
- core.inference.shards_spec.spec_declares_disaggregation(spec_str: str) bool#
Whether a shard spec tags any shard with a
role=(prefill/decode).A role tag is what marks the layout as a prefill->decode handoff rather than plain multi-shard / data-parallel inference. Cheap and world_size- free, so it can be checked at arg-validation time; full parsing + validation is :func:
parse_inference_shards_spec.
- core.inference.shards_spec.parse_inference_shards_spec(
- spec_str: str,
- world_size: int,
Parse + validate the
--inference-shardsstring.- Parameters:
spec_str – Raw CLI value, e.g.
"tp=2,dp=1+tp=1,dp=2"or with disaggregation roles"tp=2,role=prefill+tp=1,role=decode".world_size – Total number of ranks. Specs must partition it exactly (no idle ranks; see note below).
- Returns:
List of :class:
InferenceShardSpec, one per shard. Order matches the input (left-to-right corresponds to ascendingrank_offset).- Raises:
AssertionError – on syntax errors, unknown keys, or a rank-count mismatch with
world_size. Idle ranks are rejected to keep the partition explicit — any world-collective consumer must be able to enumerate every rank’s shard membership from the parsed list alone.ValueError –
on an expert-grid mismatch within a shard (raised by
- class:
InferenceShardSpec).
- core.inference.shards_spec._finalize_and_validate(
- specs: List[core.inference.shards_spec.InferenceShardSpec],
- world_size: int,
Assert the shards partition the world exactly.
Shared by the string parser and the object path (:func:
normalize_shard_specs). Per-shard defaults and expert-grid validation live in- Class:
InferenceShardSpec; this only enforces the cross-shard total. Idle ranks are rejected so any world-collective consumer can enumerate every rank’s shard membership from the list alone.