File tree Expand file tree Collapse file tree 7 files changed +79
-6
lines changed
invokeai/frontend/web/src/features
components/Parameters/Noise Expand file tree Collapse file tree 7 files changed +79
-6
lines changed Original file line number Diff line number Diff line change 11import { log } from 'app/logging/useLogger' ;
22import { RootState } from 'app/store/store' ;
33import { NonNullableGraph } from 'features/nodes/types/types' ;
4+ import { initialGenerationState } from 'features/parameters/store/generationSlice' ;
45import {
56 ImageDTO ,
67 ImageResizeInvocation ,
@@ -42,16 +43,19 @@ export const buildCanvasImageToImageGraph = (
4243 steps,
4344 img2imgStrength : strength ,
4445 clipSkip,
45- iterations,
46- seed,
47- shouldRandomizeSeed,
46+ shouldUseCpuNoise,
47+ shouldUseNoiseSettings,
4848 } = state . generation ;
4949
5050 // The bounding box determines width and height, not the width and height params
5151 const { width, height } = state . canvas . boundingBoxDimensions ;
5252
5353 const model = modelIdToMainModelField ( currentModel ?. id || '' ) ;
5454
55+ const use_cpu = shouldUseNoiseSettings
56+ ? shouldUseCpuNoise
57+ : initialGenerationState . shouldUseCpuNoise ;
58+
5559 /**
5660 * The easiest way to build linear graphs is to do it in the node editor, then copy and paste the
5761 * full graph here as a template. Then use the parameters from app state and set friendlier node
@@ -78,6 +82,7 @@ export const buildCanvasImageToImageGraph = (
7882 [ NOISE ] : {
7983 type : 'noise' ,
8084 id : NOISE ,
85+ use_cpu,
8186 } ,
8287 [ MAIN_MODEL_LOADER ] : {
8388 type : 'main_model_loader' ,
Original file line number Diff line number Diff line change 11import { RootState } from 'app/store/store' ;
22import { NonNullableGraph } from 'features/nodes/types/types' ;
3+ import { initialGenerationState } from 'features/parameters/store/generationSlice' ;
34import { addControlNetToLinearGraph } from '../addControlNetToLinearGraph' ;
45import { modelIdToMainModelField } from '../modelIdToMainModelField' ;
56import { addDynamicPromptsToGraph } from './addDynamicPromptsToGraph' ;
@@ -30,16 +31,19 @@ export const buildCanvasTextToImageGraph = (
3031 scheduler,
3132 steps,
3233 clipSkip,
33- iterations,
34- seed,
35- shouldRandomizeSeed,
34+ shouldUseCpuNoise,
35+ shouldUseNoiseSettings,
3636 } = state . generation ;
3737
3838 // The bounding box determines width and height, not the width and height params
3939 const { width, height } = state . canvas . boundingBoxDimensions ;
4040
4141 const model = modelIdToMainModelField ( currentModel ?. id || '' ) ;
4242
43+ const use_cpu = shouldUseNoiseSettings
44+ ? shouldUseCpuNoise
45+ : initialGenerationState . shouldUseCpuNoise ;
46+
4347 /**
4448 * The easiest way to build linear graphs is to do it in the node editor, then copy and paste the
4549 * full graph here as a template. Then use the parameters from app state and set friendlier node
@@ -68,6 +72,7 @@ export const buildCanvasTextToImageGraph = (
6872 id : NOISE ,
6973 width,
7074 height,
75+ use_cpu,
7176 } ,
7277 [ TEXT_TO_LATENTS ] : {
7378 type : 't2l' ,
Original file line number Diff line number Diff line change 11import { log } from 'app/logging/useLogger' ;
22import { RootState } from 'app/store/store' ;
33import { NonNullableGraph } from 'features/nodes/types/types' ;
4+ import { initialGenerationState } from 'features/parameters/store/generationSlice' ;
45import {
56 ImageCollectionInvocation ,
67 ImageResizeInvocation ,
@@ -48,6 +49,8 @@ export const buildLinearImageToImageGraph = (
4849 width,
4950 height,
5051 clipSkip,
52+ shouldUseCpuNoise,
53+ shouldUseNoiseSettings,
5154 } = state . generation ;
5255
5356 const {
@@ -75,6 +78,10 @@ export const buildLinearImageToImageGraph = (
7578
7679 const model = modelIdToMainModelField ( currentModel ?. id || '' ) ;
7780
81+ const use_cpu = shouldUseNoiseSettings
82+ ? shouldUseCpuNoise
83+ : initialGenerationState . shouldUseCpuNoise ;
84+
7885 // copy-pasted graph from node editor, filled in with state values & friendly node ids
7986 const graph : NonNullableGraph = {
8087 id : IMAGE_TO_IMAGE_GRAPH ,
@@ -102,6 +109,7 @@ export const buildLinearImageToImageGraph = (
102109 [ NOISE ] : {
103110 type : 'noise' ,
104111 id : NOISE ,
112+ use_cpu,
105113 } ,
106114 [ LATENTS_TO_IMAGE ] : {
107115 type : 'l2i' ,
Original file line number Diff line number Diff line change 11import { RootState } from 'app/store/store' ;
22import { NonNullableGraph } from 'features/nodes/types/types' ;
3+ import { initialGenerationState } from 'features/parameters/store/generationSlice' ;
34import { addControlNetToLinearGraph } from '../addControlNetToLinearGraph' ;
45import { modelIdToMainModelField } from '../modelIdToMainModelField' ;
56import { addDynamicPromptsToGraph } from './addDynamicPromptsToGraph' ;
@@ -29,10 +30,16 @@ export const buildLinearTextToImageGraph = (
2930 width,
3031 height,
3132 clipSkip,
33+ shouldUseCpuNoise,
34+ shouldUseNoiseSettings,
3235 } = state . generation ;
3336
3437 const model = modelIdToMainModelField ( currentModel ?. id || '' ) ;
3538
39+ const use_cpu = shouldUseNoiseSettings
40+ ? shouldUseCpuNoise
41+ : initialGenerationState . shouldUseCpuNoise ;
42+
3643 /**
3744 * The easiest way to build linear graphs is to do it in the node editor, then copy and paste the
3845 * full graph here as a template. Then use the parameters from app state and set friendlier node
@@ -71,6 +78,7 @@ export const buildLinearTextToImageGraph = (
7178 id : NOISE ,
7279 width,
7380 height,
81+ use_cpu,
7482 } ,
7583 [ TEXT_TO_LATENTS ] : {
7684 type : 't2l' ,
Original file line number Diff line number Diff line change 1+ import { createSelector } from '@reduxjs/toolkit' ;
2+ import { stateSelector } from 'app/store/store' ;
3+ import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
4+ import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions' ;
5+ import IAISwitch from 'common/components/IAISwitch' ;
6+ import { shouldUseCpuNoiseChanged } from 'features/parameters/store/generationSlice' ;
7+ import { ChangeEvent } from 'react' ;
8+ import { useTranslation } from 'react-i18next' ;
9+
10+ const selector = createSelector (
11+ stateSelector ,
12+ ( state ) => {
13+ const { shouldUseNoiseSettings, shouldUseCpuNoise } = state . generation ;
14+ return {
15+ isDisabled : ! shouldUseNoiseSettings ,
16+ shouldUseCpuNoise,
17+ } ;
18+ } ,
19+ defaultSelectorOptions
20+ ) ;
21+
22+ export const ParamCpuNoiseToggle = ( ) => {
23+ const dispatch = useAppDispatch ( ) ;
24+ const { isDisabled, shouldUseCpuNoise } = useAppSelector ( selector ) ;
25+
26+ const { t } = useTranslation ( ) ;
27+
28+ const handleChange = ( e : ChangeEvent < HTMLInputElement > ) =>
29+ dispatch ( shouldUseCpuNoiseChanged ( e . target . checked ) ) ;
30+
31+ return (
32+ < IAISwitch
33+ isDisabled = { isDisabled }
34+ label = "Use CPU Noise"
35+ isChecked = { shouldUseCpuNoise }
36+ onChange = { handleChange }
37+ />
38+ ) ;
39+ } ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import IAICollapse from 'common/components/IAICollapse';
77import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus' ;
88import { memo } from 'react' ;
99import { useTranslation } from 'react-i18next' ;
10+ import { ParamCpuNoiseToggle } from './ParamCpuNoise' ;
1011import ParamNoiseThreshold from './ParamNoiseThreshold' ;
1112import { ParamNoiseToggle } from './ParamNoiseToggle' ;
1213import ParamPerlinNoise from './ParamPerlinNoise' ;
@@ -40,6 +41,7 @@ const ParamNoiseCollapse = () => {
4041 >
4142 < Flex sx = { { gap : 2 , flexDirection : 'column' } } >
4243 < ParamNoiseToggle />
44+ < ParamCpuNoiseToggle />
4345 < ParamPerlinNoise />
4446 < ParamNoiseThreshold />
4547 </ Flex >
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export interface GenerationState {
5555 seamlessXAxis : boolean ;
5656 seamlessYAxis : boolean ;
5757 clipSkip : number ;
58+ shouldUseCpuNoise : boolean ;
5859}
5960
6061export const initialGenerationState : GenerationState = {
@@ -90,6 +91,7 @@ export const initialGenerationState: GenerationState = {
9091 seamlessXAxis : false ,
9192 seamlessYAxis : false ,
9293 clipSkip : 0 ,
94+ shouldUseCpuNoise : true ,
9395} ;
9496
9597const initialState : GenerationState = initialGenerationState ;
@@ -239,6 +241,9 @@ export const generationSlice = createSlice({
239241 setClipSkip : ( state , action : PayloadAction < number > ) => {
240242 state . clipSkip = action . payload ;
241243 } ,
244+ shouldUseCpuNoiseChanged : ( state , action : PayloadAction < boolean > ) => {
245+ state . shouldUseCpuNoise = action . payload ;
246+ } ,
242247 } ,
243248 extraReducers : ( builder ) => {
244249 builder . addCase ( configChanged , ( state , action ) => {
@@ -298,6 +303,7 @@ export const {
298303 setSeamlessXAxis,
299304 setSeamlessYAxis,
300305 setClipSkip,
306+ shouldUseCpuNoiseChanged,
301307} = generationSlice . actions ;
302308
303309export default generationSlice . reducer ;
You can’t perform that action at this time.
0 commit comments