feat(lora): per LoRA-model configurable weight range#9154
Conversation
Adds optional `weight_min` and `weight_max` to the LoRA model's default settings so slider LoRAs that operate at non-standard scales (e.g. -10..+10) can be tuned without bumping into the previously hard-coded -1..+2 slider range. The model edit panel exposes them alongside the starting weight, and the LoRA card slider in the canvas honors whatever range the user saved on the model. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JPPhoto
left a comment
There was a problem hiding this comment.
-
invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelPanel/LoRAModelDefaultSettings/LoRAModelDefaultSettings.tsx:45: partial LoRA range defaults are validated only when bothweightMinandweightMaxare enabled, and the backend mirrors that atinvokeai/backend/model_manager/configs/lora.py:49. Saving onlyweight_min=3is accepted, butLoRACardfalls back tosliderMax=2atinvokeai/frontend/web/src/features/lora/components/LoRACard.tsx:61and then renders a slider withmin={3}andmax={2}atinvokeai/frontend/web/src/features/lora/components/LoRACard.tsx:95. The same failure happens with onlyweight_max <= -1. This persists an invalid model setting that can break or misrender the LoRA weight control. To expose this issue, add a test that saves onlyweight_minabove the default max, or onlyweight_maxbelow the default min, and asserts the API or UI rejects it before persistence. -
invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelPanel/LoRAModelDefaultSettings/LoRAModelDefaultSettings.tsx:58: the submittedweightis never validated against the effective slider range before being saved. The model form computes effective bounds inDefaultWeight.tsx, butonSubmitstill accepts any enabledweightand the backend removed the oldge=-1, le=2constraint atinvokeai/backend/model_manager/configs/lora.py:42. A model can therefore persistdefault_settings={ weight: 10, weight_min: -1, weight_max: 2 }; adding that LoRA uses the out-of-range default atinvokeai/frontend/web/src/features/controlLayers/store/lorasSlice.ts:41, whileLoRACardrenders a slider limited to-1..2atinvokeai/frontend/web/src/features/lora/components/LoRACard.tsx:95. To expose this issue, add a test that saves a starting weight outside the enabled/effective min/max and asserts it is rejected or the saved range is expanded consistently.
Address review feedback on partial-bound and weight-out-of-range cases: - Backend LoraModelDefaultSettings now computes an effective slider range using frontend-matching defaults (-1, 2) when one bound is unset, and rejects saves where effective_min >= effective_max or where the starting weight falls outside that range. Previously, saving only weight_min=3 (or weight_max<=-1) was accepted and produced an inverted slider in LoRACard, and weight=10 with bounds [-1, 2] was persisted unchanged. - Mirror the same checks in LoRAModelDefaultSettings.tsx onSubmit so invalid configurations are surfaced inline before the API call. - Add backend tests covering partial bounds and out-of-range weight. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the careful review @JPPhoto — both findings are real bugs. Fixed in c976a53. Backend (
Frontend ( Mirrored both checks in Tests ( Added 17 cases against
All 17 pass. |
…nge' into feat/lora-weight-range
|
This addressed the problems! It looks like you need to run python scripts/generate_openapi_schema.py > invokeai/frontend/web/openapi.json |
Summary
weight_minandweight_maxfields toLoraModelDefaultSettings, exposes them in the model edit panel as toggleable spinners (alongside a re-labeled "Starting Weight" spinner), and makes the canvas LoRA card's slider honor whatever range the user saved on the model. The previous -1..+2 hard cap onweightis removed.Setting the min and max weights from within the Model Manager:
The LoRA slider with custom min and max ranges
Changes
invokeai/backend/model_manager/configs/lora.py):LoraModelDefaultSettingsgainsweight_minandweight_max(both optional, defaultNone); a model validator rejectsweight_min >= weight_max. Removed thege=-1, le=2constraint onweight.loraConfig.default_settings.weight_min/max, falling back to the global defaults (-1..+2 slider, -10..+10 number input).zLoRA.weightzod schema from.gte(-10).lte(10)to plainz.number()so persisted values within a user-set wide range aren't rejected on rehydration.services/api/schema.ts; added en locale strings.Test plan
pnpm lint:tsc,pnpm lint:eslint,pnpm lint:prettier,pnpm lint:knip,pnpm lint:dpdmpnpm test:no-watch(1097 passed)pytest tests/app/routers/test_model_manager.py tests/backend/model_manager/configs/(45 passed)🤖 Generated with Claude Code