Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(generation): span concept weight sliders over the LoRA's saved bounds (#10346)

Josh Corbett2e85ecbcace3
diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
index 41e5289ce6..0313fb1a79 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
@@ -643,6 +643,12 @@ export const getDefaultLoraWeight = (model: LoraModelConfig): number => {
: DEFAULT_LORA_WEIGHT_CONFIG.initial;
};
+/** The weight slider's track; an unset bound falls back like the backend's effective-range validator. */
+export const getLoraWeightSliderRange = (model: LoraModelConfig): { max: number; min: number } => ({
+ max: model.default_settings?.weight_max ?? DEFAULT_LORA_WEIGHT_CONFIG.sliderMax,
+ min: model.default_settings?.weight_min ?? DEFAULT_LORA_WEIGHT_CONFIG.sliderMin,
+});
+
const areModelSnapshotsEqual = (a: unknown, b: unknown): boolean => {
if (a === b) {
return true;
diff --git a/invokeai/frontend/webv2/src/features/generation/core/types.ts b/invokeai/frontend/webv2/src/features/generation/core/types.ts
index ac49ce1403..5c5d210e99 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/types.ts
@@ -92,6 +92,8 @@ export type LoraModelConfig = ModelIdentifierConfig & {
trigger_phrases?: string[] | null;
default_settings?: {
weight?: number | null;
+ weight_max?: number | null;
+ weight_min?: number | null;
} | null;
variant?: string | null;
};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
index 87063ac0b5..d5b7d7e807 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
@@ -214,6 +214,13 @@ describe('ConceptRow', () => {
expect(onRemove).toHaveBeenCalledWith('lora-1');
});
+ it("spans the weight track over the concept's saved slider bounds", async () => {
+ const row = await render(makeLora({ default_settings: { weight: 0, weight_max: 3, weight_min: -2 } }));
+ const slider = row.querySelector<HTMLElement>('[role="slider"]')!;
+
+ expect([slider.getAttribute('aria-valuemin'), slider.getAttribute('aria-valuemax')]).toEqual(['-2', '3']);
+ });
+
it('offers model, weight, toggle, and removal actions from the row context menu', async () => {
const onUpdate = vi.fn();
const onRemove = vi.fn();
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
index e37da60fc4..794a47dbc1 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.tsx
@@ -4,7 +4,11 @@ import type { GenerateLora } from '@features/generation/core/types';
import type { MouseEvent, ReactNode } from 'react';
import { Avatar, Badge, Box, chakra, Flex, Icon, Menu, Portal } from '@chakra-ui/react';
-import { DEFAULT_LORA_WEIGHT_CONFIG, getDefaultLoraWeight } from '@features/generation/core/settings';
+import {
+ DEFAULT_LORA_WEIGHT_CONFIG,
+ getDefaultLoraWeight,
+ getLoraWeightSliderRange,
+} from '@features/generation/core/settings';
import { useDebouncedDraftValue } from '@features/generation/ui/useDebouncedDraftValue';
import { useRegisterDraftFlusher } from '@platform/react/draftRegistry';
import { useExitRetainedValue } from '@platform/react/useExitRetainedValue';
@@ -30,6 +34,7 @@ import { useTranslation } from 'react-i18next';
import { GenerateFieldContextMenu } from './GenerateFieldContextMenu';
import { GenerateRowSwitch } from './GenerateToggleSwitch';
+// The track drops marks outside a concept's custom range.
const WEIGHT_MARKS = [-1, 0, 1, 2];
/** The model catalog's helpers a concept row needs; the caller supplies them through its own UI port. */
@@ -130,6 +135,7 @@ interface ConceptWeightFieldProps {
label: string;
onChange: (value: number) => void;
onReset: () => void;
+ range: { max: number; min: number };
resetLabel: string;
value: number;
}
@@ -142,6 +148,7 @@ const ConceptWeightField = ({
label,
onChange,
onReset,
+ range,
resetLabel,
value,
}: ConceptWeightFieldProps) => (
@@ -162,8 +169,8 @@ const ConceptWeightField = ({
inputMin={DEFAULT_LORA_WEIGHT_CONFIG.numberInputMin}
label={label}
marks={WEIGHT_MARKS}
- max={DEFAULT_LORA_WEIGHT_CONFIG.sliderMax}
- min={DEFAULT_LORA_WEIGHT_CONFIG.sliderMin}
+ max={range.max}
+ min={range.min}
step={DEFAULT_LORA_WEIGHT_CONFIG.coarseStep}
value={value}
onChange={onChange}
@@ -276,6 +283,7 @@ const ConceptRowContent = ({
const isActive = lora.isEnabled && isCompatible;
const isSplitWeight = lowNoiseWeight !== undefined;
const defaultWeight = getDefaultLoraWeight(lora.model);
+ const weightRange = getLoraWeightSliderRange(lora.model);
const menu = useContextMenu();
// Kept through the exit animation: the anchor clears the moment the menu closes.
const { release: releaseMenu, value: shownAnchor } = useExitRetainedValue(menu.anchor);
@@ -387,6 +395,7 @@ const ConceptRowContent = ({
value={weight}
onChange={handleWeightChange}
onReset={handleReset}
+ range={weightRange}
/>
<ConceptWeightField
copyValue={copyLowNoiseWeight}
@@ -398,6 +407,7 @@ const ConceptRowContent = ({
value={lowNoiseWeight}
onChange={handleLowNoiseWeightChange}
onReset={handleResetLowNoise}
+ range={weightRange}
/>
</Flex>
) : (
@@ -411,6 +421,7 @@ const ConceptRowContent = ({
value={weight}
onChange={handleWeightChange}
onReset={handleReset}
+ range={weightRange}
/>
)
}