Skip to content

feat(adapters): P2 fused export for PEFT & mlx-lm LoRA adapters across WeightConverter, UniversalModelConverter, CLI, REST, and ConvertModelSheet (#675) - #785

Merged
goodmai merged 2 commits into
mainfrom
feat/675-peft-fused-export
Nov 25, 2026

Conversation

@goodmai

@goodmai goodmai commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Part of #675 (P2 fused export, building on #730 P0 and #738 P1; satisfies #546 converter parity and #664 REST repo-id boundary).

Summary

  • Sources/BasaltInference/Quantization/LoRAUpdate+PEFT.swift, WeightConverter.swift, PEFTLoRAReader.swift:
    • Extended LoRAUpdate to read both PEFT (adapter_config.json + adapter_model.safetensors, sharing PEFTLoRAReader.prefixRewrites for VLM-style base_model.model.model.language_model.* keys and use_rslora scale) and mlx-lm (adapters.safetensors), refusing DoRA, modules_to_save, rank_pattern/alpha_pattern, base-changing inits, unmatched layers, and unpaired weights.
  • Sources/BasaltCore/ServedAdapterSource.swift & Sources/BasaltInference/Quantization/UniversalModelConverter+Adapter.swift, UniversalModelConverter.swift:
    • Added ServedAdapterSource.parseSingle(_:) & cachedDirectory(for:cacheRoot:) and UniversalModelConverter.resolveAdapterDirectory(_:cacheRoot:requireVerified:) supporting local directories (CLI) and cached/downloaded HF repo ids (org/repo or hf:org/repo).
    • Wired adapter fusion across dense (dense:bf16/dense:fp16), affine-like (affine, nf4, mxfp4, nvfp4, mixed), and calibrated targets (macaq*, flatQuant, lirQuant, qtip*, gsqRCO) via pre-fusion staging.
  • Sources/BasaltCLI/ModelsConvertCommand.swift & +Universal.swift: resolved --adapter <dir | org/repo | hf:org/repo> for both standard and --to conversion flows.
  • Sources/BasaltServer/REST/ModelsController+Convert.swift: accepts HF repo ids (org/repo or hf:org/repo) in POST /v1/models/convert while continuing to reject local filesystem paths with HTTP 400 ([P1] security(server,cloud,core): уязвимости валидации путей, redaction секретов, обхода бюджета и rate-limit #664).
  • Sources/BasaltAppCore/Library/ModelConvertReducer.swift, Sources/BasaltApp/Library/ConvertModelSheet.swift & +Adapter.swift, Localization/{en,ru}.lproj/Localizable.strings: added optional LoRA adapter repo-id field with reducer validation and EN/RU strings; visually verified via offscreen Light, Dark, and Russian renders.
  • Tests/BasaltTests/PEFTFusedExportTests.swift: #228 parity on .qwen35 and .lfm2Moe (float32 fused vs unfused PEFT logits < 1e-4 and exact greedy ids; bf16 fused weights bit-exact to W + s·B·A and bit-identical to mlx-lm fused export; affine 4-bit quantized export parity), rsLoRA & refusal matrix, REST #664 repo-only guard, LibraryReducer validation, and ConvertModelSheet Light/Dark/Russian visual render test.

Local Verification

Gate Result
swift build -Xswiftc -warnings-as-errors PASS (0 warnings)
swift build -c release -Xswiftc -warnings-as-errors PASS (221.00s, 0 warnings)
Targeted tests (PEFTFusedExportTests|PEFTAdapterTests|WeightConverterTests|UniversalConverterTests|AuditSecurityAndCloudRegressionTests) PASS (34/34 in 8 suites, 3.958s)
5× repetition (PEFTFusedExportTests) PASS (25/25, 1.098–1.316s)
check_changed_coverage.swift origin/main PASS (80.6%, 200/248, min 60%)
check_no_new_comments.swift origin/main PASS (0 comments added)
check_concurrency_hatches.swift PASS (0 hatches outside allowlist)
check_size_limits.swift origin/main --impact PASS (max CCN 15, 0 limits exceeded)

@goodmai
goodmai merged commit d099db1 into main Nov 25, 2026
8 checks passed
@goodmai
goodmai deleted the feat/675-peft-fused-export branch November 25, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant