-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gui): add state migrations for new unet/vae params (#427)
- Loading branch information
Showing
10 changed files
with
128 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
export const BLEND_SOURCES = 2; | ||
|
||
/** | ||
* Default parameters for the inpaint brush. | ||
* | ||
* Not provided by the server yet. | ||
*/ | ||
export const DEFAULT_BRUSH = { | ||
color: 255, | ||
size: 8, | ||
strength: 0.5, | ||
}; | ||
|
||
/** | ||
* Default parameters for the image history. | ||
* | ||
* Not provided by the server yet. | ||
*/ | ||
export const DEFAULT_HISTORY = { | ||
/** | ||
* The number of images to be shown. | ||
*/ | ||
limit: 4, | ||
|
||
/** | ||
* The number of additional images to be kept in history, so they can scroll | ||
* back into view when you delete one. Does not include deleted images. | ||
*/ | ||
scrollback: 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable camelcase */ | ||
import { ServerParams } from '../../config.js'; | ||
import { BaseImgParams } from '../../types/params.js'; | ||
import { OnnxState, STATE_VERSION } from '../full.js'; | ||
import { Img2ImgSlice } from '../img2img.js'; | ||
import { InpaintSlice } from '../inpaint.js'; | ||
import { Txt2ImgSlice } from '../txt2img.js'; | ||
import { UpscaleSlice } from '../upscale.js'; | ||
|
||
export const REMOVE_KEYS = ['tile', 'overlap'] as const; | ||
|
||
export type RemovedKeys = typeof REMOVE_KEYS[number]; | ||
|
||
// TODO: can the compiler calculate this? | ||
export type AddedKeysV11 = 'unet_tile' | 'unet_overlap' | 'vae_tile' | 'vae_overlap'; | ||
|
||
export type BaseImgParamsV7<T extends BaseImgParams> = Omit<T, AddedKeysV11> & { | ||
overlap: number; | ||
tile: number; | ||
}; | ||
|
||
export type OnnxStateV7 = Omit<OnnxState, 'img2img' | 'txt2img'> & { | ||
img2img: BaseImgParamsV7<Img2ImgSlice['img2img']>; | ||
inpaint: BaseImgParamsV7<InpaintSlice['inpaint']>; | ||
txt2img: BaseImgParamsV7<Txt2ImgSlice['txt2img']>; | ||
upscale: BaseImgParamsV7<UpscaleSlice['upscale']>; | ||
}; | ||
|
||
export type PreviousState = OnnxStateV7; | ||
export type CurrentState = OnnxState; | ||
export type UnknownState = PreviousState | CurrentState; | ||
|
||
export function applyStateMigrations(params: ServerParams, previousState: UnknownState, version: number): OnnxState { | ||
// eslint-disable-next-line no-console | ||
console.log('applying migrations from %s to %s', version, STATE_VERSION); | ||
|
||
if (version < STATE_VERSION) { | ||
return migrateDefaults(params, previousState as PreviousState); | ||
} | ||
|
||
return previousState as CurrentState; | ||
} | ||
|
||
export function migrateDefaults(params: ServerParams, previousState: PreviousState): CurrentState { | ||
// add any missing keys | ||
const result: CurrentState = { | ||
...params, | ||
...previousState, | ||
img2img: { | ||
...previousState.img2img, | ||
unet_overlap: params.unet_overlap.default, | ||
unet_tile: params.unet_tile.default, | ||
vae_overlap: params.vae_overlap.default, | ||
vae_tile: params.vae_tile.default, | ||
}, | ||
inpaint: { | ||
...previousState.inpaint, | ||
unet_overlap: params.unet_overlap.default, | ||
unet_tile: params.unet_tile.default, | ||
vae_overlap: params.vae_overlap.default, | ||
vae_tile: params.vae_tile.default, | ||
}, | ||
txt2img: { | ||
...previousState.txt2img, | ||
unet_overlap: params.unet_overlap.default, | ||
unet_tile: params.unet_tile.default, | ||
vae_overlap: params.vae_overlap.default, | ||
vae_tile: params.vae_tile.default, | ||
}, | ||
upscale: { | ||
...previousState.upscale, | ||
unet_overlap: params.unet_overlap.default, | ||
unet_tile: params.unet_tile.default, | ||
vae_overlap: params.vae_overlap.default, | ||
vae_tile: params.vae_tile.default, | ||
}, | ||
}; | ||
|
||
// TODO: remove extra keys | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters