mstar.engine.resources.lora.checkpoint#
Reading LoRA checkpoints: shared by the static merge and the per-request adapter pool.
Accepted checkpoint layouts (.safetensors):
diffusers / PEFT:
[transformer.]<module>.lora_A.weight+.lora_B.weight(also thebase_model.model.prefix), optionally<module>.alpha; without an alpha the scaling comes from anadapter_config.json/config.jsonnext to the weights when there is one (lora_alpha/r, per-modulealpha_pattern/rank_pattern, anduse_rsloraforlora_alpha / sqrt(r), as PEFT applies them), else it is1(lora_alpha = r).Kohya-style naming
lora_down/lora_upfor A / B.model-native layouts (e.g. the BFL
double_blocks.N.img_attn.qkvkeys of FLUX.2) through a model-suppliedconvert_keyshook that rewrites them to the reference module paths.
<module> is a reference-library module path; the model’s checkpoint remap (the same one the
weight loader uses) and its stacked-shard rules turn it into the native parameter and, for
fused projections, the shard it lands on (the model side’s ModuleLoraMap, and the static
merge’s resolve_lora_module).
Functions
|
|
|
A raw checkpoint key in reference-library naming: known prefixes stripped, Kohya's |
|
Group raw LoRA tensors into per-module |
|
|
|
|
|
|
Classes
|
|
|
One adapter checkpoint: a safetensors path and its strength. |
|
One module's adapter: |
|
|
- class mstar.engine.resources.lora.checkpoint.LoraAdapter(layers=<factory>)[source]#
Bases:
objectmodule path -> LoraLayerin reference-library naming.
- class mstar.engine.resources.lora.checkpoint.LoraFile(path, scale=1.0)[source]#
Bases:
objectOne adapter checkpoint: a safetensors path and its strength.
- class mstar.engine.resources.lora.checkpoint.LoraLayer(a, b, alpha)[source]#
Bases:
NamedTupleOne module’s adapter:
W += scale * alpha / r * b @ a.
- class mstar.engine.resources.lora.checkpoint.SidecarScaling(lora_alpha, rslora, alpha_pattern, rank_pattern)[source]#
Bases:
object(module, rank) -> alphafrom a PEFT adapter config:lora_alpha(None:alpha = r), unless analpha_patternnames the module;rslorafolds PEFT’salpha / sqrt(r)into the alpha. A module arank_patternnames must be that rank.
- mstar.engine.resources.lora.checkpoint.normalize_lora_key(key)[source]#
A raw checkpoint key in reference-library naming: known prefixes stripped, Kohya’s
lora_down/lora_uprenamed tolora_A/lora_B.
- mstar.engine.resources.lora.checkpoint.normalize_lora_state_dict(state_dict, convert_keys=None, default_alpha=None)[source]#
Group raw LoRA tensors into per-module
(A, B, alpha)triples in reference-library naming.
- mstar.engine.resources.lora.checkpoint.parse_lora_key(key)[source]#
(module, "A" | "B" | "alpha")of a normalized key; raises on anything else.
- mstar.engine.resources.lora.checkpoint.read_lora_file(path, convert_keys=None)[source]#
normalize_lora_state_dictover a safetensors file, with its sidecar’s scaling.
- mstar.engine.resources.lora.checkpoint.sidecar_default_alpha(path)[source]#
(module, rank) -> alphareproducing PEFT’s scaling for an adapter whose safetensors has no alpha keys.PEFT reads
lora_alpha(anduse_rslora) from the adapter’s config, soload_lora_weightsapplieslora_alpha / r— orlora_alpha / sqrt(r)for rank-stabilized adapters — where the bare weights would suggest1; a module analpha_patternnames takes that alpha instead, and one arank_patternnames has that rank (which its weights must have). Looks foradapter_config.jsonthenconfig.jsonnext topathand accepts the training-config spellings too (alpha,lora_rank/rank). None when there is nothing to read.