Repository navigation
feat(adapters): read PEFT LoRA adapters — harness-hub layout, VLM-style keys, rsLoRA, named refusals (#675 P0) - #730
Merged
Merged
Conversation
…-style key mapping, rsLoRA and named refusals (#675 P0) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
This was referenced Nov 23, 2026
goodmai
added a commit
that referenced
this pull request
Nov 23, 2026
…pter check before download, base-changing inits refused, float LoRA on microscaled bases (#749) * fix(adapters): only hf:org/repo names a Hugging Face repo, and its file list must show an adapter before anything downloads (review) * fix(adapters): refuse base-changing PEFT inits and a non-positive alpha, keep LoRA weights in a float type on microscaled bases, separate config and weights errors (review)
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#675 P0: basalt reads PEFT LoRA adapters, the format of the
harness-hubcheckpoints (adapter_config.json+adapter_model.safetensors).--adapter name=dirandX-Basalt-Adapter([P3] lora: per-request LoRA adapters on one resident base model (X-Basalt-Adapter) #179);adapter_applywith a directory.LoRAContainerthe mlx-lm path does.PEFTLoRAReader(Sources/BasaltInference/Adapters/PEFTLoRAReader.swift):adapter_config.jsonhaspeft_typetakes this path. Anything else keeps the mlx-lm path.lora_alpha / r, orlora_alpha / √rwithuse_rslora.peft_typeother than LORA;use_dora;modules_to_save;rank_patternoralpha_pattern;lora_Anorlora_B;lora_Aorlora_B;checkShapes).base_model.model., the reader tries the path as is, then the variants [P2] feat(adapters): harness adapters — PEFT LoRA import, per-harness routing, fused export (HF harness-adapters-at-scale) #675 lists. The first one that names aLinearof the loaded model wins:model.language_model.→language_model.model.,model.orlanguage_model.;model.→language_model.model..lora_A [r, in]/lora_B [out, r]are transposed to mlx-lmlora_a [in, r]/lora_b [r, out]and cast to the layer's dtype. That is the scales' dtype for a quantized layer; the files ship in F32.The fork already has
LoRAContainer.fromPEFTfrom upstream. It is not used here because it has no rsLoRA, no refusals, keeps F32, and keeps PEFT paths that do not match basalt's module paths.One difference from the issue text. Layers are wrapped per layer-relative key across all layers (
LoRAContainer.load), not per module path. A layer that has the key but no weights gets a zerolora_b, so its output does not change; it only costs one more small matmul per token. For the harness-hub adapters this never happens: Qwen 3.8'sself_attn.*exist only in full-attention layers, LFM'sconv.*only in conv layers, andmlp.*/feed_forward.*are adapted wherever they exist. A PEFT adapter withlayers_to_transformwould pay it. If needed, a per-path wrapper is a follow-up.Tests (
PEFTAdapterTests, #228).qwen35(hybrid: full-attentionq_proj/o_proj, all-layerdown_proj),.lfm2Moe(conv.in_proj,self_attn.q_proj, densefeed_forward.w1).qwen35.qwen35modules_to_save,rank_pattern, an unmatched key, a lonelora_A, a wrong rank; nothing stays wrapped.qwen35throughModelOrchestratorActor.loadAdaptersPEFTAdapterTests|AdapterServingTests|LabGateTests|PHMAdapterTests|OFTAdapterTests: 40 tests in 7 suites pass locally.swift build -Xswiftc -warnings-as-errors,check_no_new_commentsandcheck_size_limits --impact: clean.Swift 6.4.2 crashed in SILGen on
try Self.merged(...)(tokens, cache: nil), a call on the existential returned by a throwing call. The test binds the model first instead.Not in this PR (later phases of #675)
--adapter, harness routing (HarnessRoute), thinking off by default with a harness adapter.models convert --adapter).Part of #675.
🤖 Generated with Claude Code
https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh