Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add enable partial load setting to GUI #31

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/main/invoke-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class InvokeManager {
env.INVOKEAI_HOST = '0.0.0.0';
}

if (this.store.get('enablePartialLoading')) {
env.INVOKEAI_ENABLE_PARTIAL_LOADING = '1';
}

// Some torch operations are not yet supported on MPS. This tells torch to use CPU for those operations.
// See: https://pytorch.org/docs/stable/mps_environment_variables.html
if (process.platform === 'darwin') {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/features/SettingsModal/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { useStore } from '@nanostores/react';
import { memo, useCallback } from 'react';

import { SettingsModalEnablePartialLoading } from '@/renderer/features/SettingsModal/SettingsModalEnablePartialLoading';
import { SettingsModalNotifyForPrereleaseUpdates } from '@/renderer/features/SettingsModal/SettingsModalNotifyForPrereleaseUpdates';
import { SettingsModalResetButton } from '@/renderer/features/SettingsModal/SettingsModalResetButton';
import { SettingsModalServerMode } from '@/renderer/features/SettingsModal/SettingsModalServerMode';
Expand All @@ -36,6 +37,8 @@ export const SettingsModal = memo(() => {
<SettingsModalServerMode />
<Divider />
<SettingsModalNotifyForPrereleaseUpdates />
<Divider />
<SettingsModalEnablePartialLoading />
</ModalBody>
<ModalFooter pt={16}>
<SettingsModalResetButton />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Checkbox, Flex, FormControl, FormHelperText, FormLabel } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react';
import type { ChangeEvent } from 'react';
import { memo, useCallback } from 'react';

import { persistedStoreApi } from '@/renderer/services/store';

export const SettingsModalEnablePartialLoading = memo(() => {
const { enablePartialLoading } = useStore(persistedStoreApi.$atom);
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
persistedStoreApi.setKey('enablePartialLoading', e.target.checked);
}, []);

return (
<FormControl orientation="vertical">
<Flex w="full" alignItems="center" justifyContent="space-between">
<FormLabel>Enable Partial Loading</FormLabel>
<Checkbox isChecked={enablePartialLoading} onChange={onChange} />
</Flex>
<FormHelperText>
When loading models, if it won&apos;t fit in the available VRAM, it will be loaded by layer. This prevents out
of memory errors at the cost of generation speed.
</FormHelperText>
<FormHelperText>
When disabled, if a model will not fit in VRAM, you will get an out of memory error.
</FormHelperText>
</FormControl>
);
});
SettingsModalEnablePartialLoading.displayName = 'SettingsModalEnablePartialLoading';
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Checkbox, Flex, FormControl, FormHelperText, FormLabel } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react';
import type { ChangeEvent } from 'react';
import { memo, useCallback } from 'react';

import { persistedStoreApi } from '@/renderer/services/store';

export const SettingsModalNotifyForPrereleaseUpdates = memo(() => {
const { notifyForPrereleaseUpdates } = useStore(persistedStoreApi.$atom);
const onChange = useCallback(() => {
persistedStoreApi.setKey('notifyForPrereleaseUpdates', !persistedStoreApi.$atom.get().notifyForPrereleaseUpdates);
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
persistedStoreApi.setKey('notifyForPrereleaseUpdates', e.target.checked);
}, []);

return (
Expand Down
5 changes: 5 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type StoreData = {
notifyForPrereleaseUpdates: boolean;
launcherWindowProps?: WindowProps;
appWindowProps?: WindowProps;
enablePartialLoading?: boolean;
};

// The electron store uses JSON schema to validate its data.
Expand Down Expand Up @@ -90,6 +91,10 @@ export const schema: Schema<StoreData> = {
type: 'boolean',
default: true,
},
enablePartialLoading: {
type: 'boolean',
default: true,
},
launcherWindowProps: winSizePropsSchema,
appWindowProps: winSizePropsSchema,
};
Expand Down
Loading