mstar.engine.resources.lora#
- class mstar.engine.resources.lora.AdapterInfo(rank, unmapped, misfits=())[source]#
Bases:
NamedTupleWhat validation needs to know about an adapter checkpoint, read without its weights.
rankcovers every LoRA module in the file, those left to another spec included.misfitsnames modules whose shapes do not fit their target (an adapter trained on another size of the model).
- class mstar.engine.resources.lora.LoraBaseOnly(key=None)[source]#
Bases:
objectThe capture key of a step none of whose rows names an adapter: the node’s own
cg_key_info(key), wrapped. A node serving adapters captures each bucket under both keys, and the base-only graph records no LoRA kernel: at decode width the launches of a delta that adds zero cost about what the work does.- Parameters:
key (Any)
- class mstar.engine.resources.lora.LoraModuleRef(target, layer, shard_id=None)[source]#
Bases:
NamedTupleWhere one checkpoint module’s adapter lands: a target, a stack layer, and the stacked-shard id of its slice (None for a single-slice target).
- class mstar.engine.resources.lora.LoraReqConfig(adapter=None)[source]#
Bases:
ResourceReqConfigThe adapter a request runs under; None runs the base model.
- Parameters:
adapter (str | None)
- class mstar.engine.resources.lora.LoraSpec(resource_key, nodes, num_layers, targets, module_map, max_slots=4, max_rank=16, cpu_capacity=16, adapters=<factory>, adapter_digests=<factory>, dtype=None, backend='auto', convert_keys=None, ignored_modules=None, dropped_targets=<factory>)[source]#
Bases:
NodeResourceSpecPer-request LoRA adapters for the linears named in
targets.max_slotsadapters are resident on the device at once, beside a zero adapter that base-model rows use, and up tocpu_capacityare kept pinned on the host.adaptersmaps the names requests ask for to safetensors paths.module_mapplaces each checkpoint module on a target; a node’s spec comes frommodule_lora_spec(mstar.model.components.lora.modules), whoseModuleLoraMapis what binds the node’s modules (a spec with any other resolver is refused as the deployment’s specs are declared,declared_lora_specs).convert_keysrewrites a model-native checkpoint layout first.- Parameters:
- adapter_info(name)[source]#
Rank and unmapped modules of a configured adapter, read once and cached.
- Parameters:
name (str)
- Return type:
- add_adapter(name, path, digest=None)[source]#
Serve
namefrompath, whose weights digest todigest, from now on (a runtime load).
- apply_yaml_overrides(max_slots=None, max_rank=None, cpu_capacity=None, adapters=None, adapter_digests=None, targets=None)[source]#
How many adapters stay resident, the largest rank served, and which adapters this deployment serves.
targetskeeps only those of the model’s targets (one list for every LoRA spec of the model, so a name another spec declares is not an error here;serving_resourceschecks the list as a whole): dropping the LM head and embedding saves their vocabulary-sized slots, and an adapter that touches a dropped target is refused.Every value is checked before any is set, so a refused override leaves the spec as declared.
- check_adapter(name, info)[source]#
Refuse an adapter this deployment cannot serve: no LoRA layers, a rank above
max_rank, or a module outside the declared targets.- Parameters:
name (str)
info (AdapterInfo)
- Return type:
None
- module_map: Callable[[str], LoraModuleRef | None]#
- remove_adapter(name)[source]#
Stop serving
name(a runtime unload).- Parameters:
name (str)
- Return type:
None
- property resource_class: type[Resource]#
What builds this spec. Imported inside the property, so declaring a resource stays free of the manager and its kernels.
The builder, not necessarily the class built: an attention spec names AttentionManager, whose build picks a backend subclass.
- stop_ignoring(modules)[source]#
Refuse, rather than ignore, the checkpoint modules
modulesmatches: those of another node’s spec the deployment does not build, which no spec loads now.
- targets: dict[str, LoraTarget]#
- class mstar.engine.resources.lora.LoraStep(segments=None)[source]#
Bases:
ResourceStepOne step’s rows: a segment per request, its
spanthe tokens that request puts through the LoRA’d linears this step, in the order they are packed.
- class mstar.engine.resources.lora.LoraTarget(in_features, out_slices, parallel='column', slice_names=(), slice_units=None, slice_packs=None, slice_align=None, layers=None, kind='linear', per_segment=False, token_fold=1)[source]#
Bases:
objectOne family of linears an adapter may touch, e.g. every layer’s fused
qkv_proj.Shapes are the unsharded linear’s.
out_sliceslists the output widths of a fused projection in order ((q, k, v)); each slice has its own A and B, named in a checkpoint by the stacked-shard id inslice_names. A single linear has one slice.parallelsays how the base linear is split across tensor-parallel ranks:"column": output rows are split, so A is replicated and B is sharded by output rows of each slice. The delta lands on this rank’s rows of the output."row": input columns are split, so A is sharded along the input and B replicated.x @ A_r^Tis then a partial sum over this rank’s input columns, and so is the expanded delta: add it to the partial base output before the layer’s all-reduce, which sums both. LoRA adds no collective."none": every rank holds the whole adapter and adds the whole delta to an output that is already whole (after the base layer’s own collective).
slice_unitscounts the shardable units (heads) of each slice. A slice with fewer units than ranks is replicated across groups of ranks rather than split, asQKVParallelLineardoes with GQA’s K/V heads. None treats every row as a unit.slice_packsnames checkpoint modules that pack several slices into one tensor: a gated delta-net’sin_proj_qkvis[q | k | v], three outputs the base shards across ranks on their own. Such a module has one A, which each of its slices takes, and a B whose rows are those slices’ in order.slice_alignrounds each slice’s rank-local width up to a multiple, for a base linear that pads its fused output per rank so the next slice starts aligned. The padding rows follow the slice’s own, and B is zero there.layersnames the stack layer indices this target exists on (a hybrid stack has attention on some layers only); None means all of the spec’snum_layers.kind="embedding"is a token embedding:in_featuresis the vocabulary, a row’s input is its token id, and the shrink gathers A’s column for it (x @ A^Tof the token’s one-hot), as PEFT’slora_embedding_A/_Bdefine it.Which rows the linear sees, for the per-row adapter choice: one per token of the step (the default), one per segment (
per_segment, e.g. an LM head over each row’s last token), or one pertoken_foldconsecutive tokens of a segment (a patch merger that folds 2x2 patches into one row).- Parameters:
- local_width(slice_idx, world_size)[source]#
Rows of slice
slice_idxin one rank’s base output, padding included.
- module_slices(shard_id)[source]#
The slices a checkpoint module lands on, in the order its B’s rows hold them: several for a
slice_packsname, else the oneslice_indexgives.
- property row_grouping: int#
1 per token,
kperkfolded tokens, 0 per segment.- Type:
Which addressing the linear reads
- shard(world_size)[source]#
This target as one rank of
world_sizesees it: its slices the widths they have in that rank’s base output, alignment padding included.- Parameters:
world_size (int)
- Return type:
- shard_pair(slice_idx, a, b, rank, world_size)[source]#
rank’s share of one slice’sa [r, in]andb [out_slice, r].
- mstar.engine.resources.lora.lora_enabled(model_config)[source]#
Whether a deployment’s YAML turns LoRA on (a
resources: lora:block). Aresources:value that is not a mapping turns nothing on: the conductor’svalidate_deploymentreports it with the deployment’s other problems.
- mstar.engine.resources.lora.node_capture_key(key)[source]#
The node’s own
cg_key_infoin a capture key, without itsLoraBaseOnly.
- mstar.engine.resources.lora.resolve_adapter_path(path)[source]#
The safetensors file an adapter path names: the path itself, or a PEFT directory’s
adapter_model.safetensors(what vLLM’slora_pathnames).
- mstar.engine.resources.lora.served_lora_adapters(model_config)[source]#
The adapter names a deployment’s YAML serves; empty when it does not turn LoRA on.
Modules
Kernels that add a batch's LoRA deltas: shrink |
|
Reading LoRA checkpoints: shared by the static merge and the per-request adapter pool. |
|
What a model declares about per-request LoRA adapters. |
|
Which weights an adapter name stands for, as the prefix cache keys them. |
|
The LoRA shrink and expand as custom ops, so |
|
Per-request LoRA adapters resident in a fixed set of device slots. |
|
Which LoRA specs a deployment builds from its serving config's |
|
The host tier of the adapter pool: adapters read, sharded for this rank, and pinned. |