Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { createSelector, createSlice, type PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from 'app/store/store';
import type { SliceConfig } from 'app/store/types';
import type { NumericalParameterConfig } from 'app/types/invokeai';
import { paramsReset } from 'features/controlLayers/store/paramsSlice';
import { type LoRA, zLoRA } from 'features/controlLayers/store/types';
import { zModelIdentifierField } from 'features/nodes/types/common';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/system/store/configSlice';
import type { LoRAModelConfig } from 'services/api/types';
import { v4 as uuidv4 } from 'uuid';
import z from 'zod';

export const DEFAULT_LORA_WEIGHT_CONFIG: NumericalParameterConfig = {
initial: 0.75,
sliderMin: -1,
sliderMax: 2,
numberInputMin: -10,
numberInputMax: 10,
fineStep: 0.01,
coarseStep: 0.05,
};

const zLoRAsState = z.object({
loras: z.array(zLoRA),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover';
import {
buildSelectLoRA,
DEFAULT_LORA_WEIGHT_CONFIG,
loraDeleted,
loraIsEnabledChanged,
loraWeightChanged,
} from 'features/controlLayers/store/lorasSlice';
import type { LoRA } from 'features/controlLayers/store/types';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/system/store/configSlice';
import { memo, useCallback, useMemo } from 'react';
import { PiTrashSimpleBold } from 'react-icons/pi';
import { useGetModelConfigQuery } from 'services/api/endpoints/models';

const MARKS = [-1, 0, 1, 2];

export const LoRACard = memo((props: { id: string }) => {
const selectLoRA = useMemo(() => buildSelectLoRA(props.id), [props.id]);
const lora = useAppSelector(selectLoRA);
Expand Down Expand Up @@ -81,7 +83,8 @@ const LoRAContent = memo(({ lora }: { lora: LoRA }) => {
min={DEFAULT_LORA_WEIGHT_CONFIG.sliderMin}
max={DEFAULT_LORA_WEIGHT_CONFIG.sliderMax}
step={DEFAULT_LORA_WEIGHT_CONFIG.coarseStep}
marks={DEFAULT_LORA_WEIGHT_CONFIG.marks.slice()}
fineStep={DEFAULT_LORA_WEIGHT_CONFIG.fineStep}
marks={MARKS}
defaultValue={DEFAULT_LORA_WEIGHT_CONFIG.initial}
isDisabled={!lora.isEnabled}
/>
Expand All @@ -91,6 +94,7 @@ const LoRAContent = memo(({ lora }: { lora: LoRA }) => {
min={DEFAULT_LORA_WEIGHT_CONFIG.numberInputMin}
max={DEFAULT_LORA_WEIGHT_CONFIG.numberInputMax}
step={DEFAULT_LORA_WEIGHT_CONFIG.coarseStep}
fineStep={DEFAULT_LORA_WEIGHT_CONFIG.fineStep}
w={20}
flexShrink={0}
defaultValue={DEFAULT_LORA_WEIGHT_CONFIG.initial}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNil } from 'es-toolkit/compat';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/system/store/configSlice';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/controlLayers/store/lorasSlice';
import { useMemo } from 'react';
import type { LoRAModelConfig } from 'services/api/types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { CompositeNumberInput, CompositeSlider, Flex, FormControl, FormLabel } from '@invoke-ai/ui-library';
import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/controlLayers/store/lorasSlice';
import { SettingToggle } from 'features/modelManagerV2/subpanels/ModelPanel/SettingToggle';
import { DEFAULT_LORA_WEIGHT_CONFIG } from 'features/system/store/configSlice';
import { memo, useCallback, useMemo } from 'react';
import type { UseControllerProps } from 'react-hook-form';
import { useController } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

import type { LoRAModelDefaultSettingsFormData } from './LoRAModelDefaultSettings';

const MARKS = [-1, 0, 1, 2];

type DefaultWeight = LoRAModelDefaultSettingsFormData['weight'];

export const DefaultWeight = memo((props: UseControllerProps<LoRAModelDefaultSettingsFormData, 'weight'>) => {
Expand Down Expand Up @@ -51,7 +53,7 @@ export const DefaultWeight = memo((props: UseControllerProps<LoRAModelDefaultSet
step={DEFAULT_LORA_WEIGHT_CONFIG.coarseStep}
fineStep={DEFAULT_LORA_WEIGHT_CONFIG.fineStep}
onChange={onChange}
marks={DEFAULT_LORA_WEIGHT_CONFIG.marks.slice()}
marks={MARKS}
isDisabled={isDisabled}
/>
<CompositeNumberInput
Expand Down
14 changes: 2 additions & 12 deletions invokeai/frontend/web/src/features/system/store/configSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ import type { PayloadAction, Selector } from '@reduxjs/toolkit';
import { createSelector, createSlice } from '@reduxjs/toolkit';
import type { RootState } from 'app/store/store';
import type { SliceConfig } from 'app/store/types';
import { getDefaultAppConfig, type PartialAppConfig, zAppConfig } from 'app/types/invokeai';
import type { PartialAppConfig } from 'app/types/invokeai';
import { getDefaultAppConfig, zAppConfig } from 'app/types/invokeai';
import { merge } from 'es-toolkit/compat';
import z from 'zod';

export const DEFAULT_LORA_WEIGHT_CONFIG = {
initial: 0.75,
sliderMin: -1,
sliderMax: 2,
marks: [-1, 0, 1, 2],
numberInputMin: -1,
numberInputMax: 2,
fineStep: 0.01,
coarseStep: 0.05,
} as const;

const zConfigState = z.object({
...zAppConfig.shape,
didLoad: z.boolean(),
Expand Down