Skip to content

Commit c165dbb

Browse files
authored
feat: add new settings for GPU promotion (#1869)
* feat: add new settings for GPU promotion Relates to #1591 Signed-off-by: Jeff MAURY <jmaury@redhat.com>
1 parent 8a1b041 commit c165dbb

File tree

11 files changed

+95
-62
lines changed

11 files changed

+95
-62
lines changed

packages/backend/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@
5656
"default": false,
5757
"description": "Display InstructLab Tuning screens (experimental)",
5858
"hidden": true
59+
},
60+
"ai-lab.showGPUPromotion": {
61+
"type": "boolean",
62+
"default": true,
63+
"description": "Display GPU promotion banner",
64+
"hidden": true
5965
}
66+
6067
}
6168
},
6269
"icons": {

packages/backend/src/managers/modelsManager.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ beforeEach(() => {
129129
experimentalTuning: false,
130130
apiPort: 0,
131131
experimentalGPU: false,
132+
showGPUPromotion: false,
132133
});
133134

134135
mocks.isCompletionEventMock.mockReturnValue(true);
@@ -1016,6 +1017,7 @@ describe('uploadModelToPodmanMachine', () => {
10161017
experimentalTuning: false,
10171018
apiPort: 0,
10181019
experimentalGPU: false,
1020+
showGPUPromotion: false,
10191021
});
10201022

10211023
const manager = new ModelsManager(

packages/backend/src/registries/ConfigurationRegistry.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import { ConfigurationRegistry } from './ConfigurationRegistry';
2222
const fakeConfiguration = {
2323
get: vi.fn(),
2424
has: vi.fn(),
25+
update: vi.fn(),
2526
} as unknown as Configuration;
2627

2728
const webviewMock = {
28-
postMessage: vi.fn(),
29+
postMessage: vi.fn().mockResolvedValue(true),
2930
} as unknown as Webview;
3031

3132
vi.mock('@podman-desktop/api', async () => {
@@ -58,3 +59,13 @@ test('dispose should dispose listener', () => {
5859
registry.dispose();
5960
expect(disposeMock).toHaveBeenCalled();
6061
});
62+
63+
test('update should trigger configuration update', async () => {
64+
const registry = new ConfigurationRegistry(webviewMock, 'appdir');
65+
vi.mocked(fakeConfiguration.has).mockReturnValue(true);
66+
vi.mocked(fakeConfiguration.update).mockResolvedValue(undefined);
67+
68+
registry.init();
69+
await registry.updateExtensionConfiguration({ modelsPath: '' });
70+
expect(fakeConfiguration.update).toHaveBeenCalledWith('models.path', '');
71+
});

packages/backend/src/registries/ConfigurationRegistry.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import { Messages } from '@shared/Messages';
2222
import path from 'node:path';
2323

2424
const CONFIGURATION_SECTIONS: string[] = [
25-
'ai-lab.models.path',
26-
'ai-lab.experimentalGPU',
27-
'ai-lab.apiPort',
28-
'ai-lab.experimentalTuning',
29-
'ai-lab.modelUploadDisabled',
25+
'models.path',
26+
'experimentalGPU',
27+
'apiPort',
28+
'experimentalTuning',
29+
'modelUploadDisabled',
30+
'showGPUPromotion',
3031
];
3132

3233
const API_PORT_DEFAULT = 10434;
@@ -51,9 +52,25 @@ export class ConfigurationRegistry extends Publisher<ExtensionConfiguration> imp
5152
apiPort: this.#configuration.get<number>('apiPort') ?? API_PORT_DEFAULT,
5253
experimentalTuning: this.#configuration.get<boolean>('experimentalTuning') ?? false,
5354
modelUploadDisabled: this.#configuration.get<boolean>('modelUploadDisabled') ?? false,
55+
showGPUPromotion: this.#configuration.get<boolean>('showGPUPromotion') ?? true,
5456
};
5557
}
5658

59+
private getFieldName(section: string): keyof Partial<ExtensionConfiguration> {
60+
return section.replace(/\.(\w)/, (match, char) => char.toUpperCase()) as keyof Partial<ExtensionConfiguration>;
61+
}
62+
63+
async updateExtensionConfiguration(update: Partial<ExtensionConfiguration>): Promise<void> {
64+
for (const section of CONFIGURATION_SECTIONS) {
65+
const fieldName = this.getFieldName(section);
66+
const value = update[fieldName];
67+
if (value !== undefined) {
68+
await this.#configuration.update(section, value);
69+
}
70+
}
71+
this.notify(); //https://github.com/containers/podman-desktop/issues/9194
72+
}
73+
5774
private getModelsPath(): string {
5875
const value = this.#configuration.get<string>('models.path');
5976
if (value && value.length > 0) {
@@ -68,7 +85,7 @@ export class ConfigurationRegistry extends Publisher<ExtensionConfiguration> imp
6885

6986
init(): void {
7087
this.#configurationDisposable = configuration.onDidChangeConfiguration(event => {
71-
if (CONFIGURATION_SECTIONS.some(section => event.affectsConfiguration(section))) {
88+
if (CONFIGURATION_SECTIONS.some(section => event.affectsConfiguration(`ai-lab.${section}`))) {
7289
this.notify();
7390
}
7491
});

packages/backend/src/studio-api-impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ export class StudioApiImpl implements StudioAPI {
122122
return this.configurationRegistry.getExtensionConfiguration();
123123
}
124124

125+
async updateExtensionConfiguration(update: Partial<ExtensionConfiguration>): Promise<void> {
126+
return this.configurationRegistry.updateExtensionConfiguration(update);
127+
}
128+
125129
async getSnippetLanguages(): Promise<Language[]> {
126130
return this.snippetManager.getLanguageList();
127131
}

packages/backend/src/workers/provider/LlamaCppPython.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ beforeEach(() => {
9898
apiPort: 10434,
9999
experimentalTuning: false,
100100
modelUploadDisabled: false,
101+
showGPUPromotion: false,
101102
});
102103
vi.mocked(podmanConnection.findRunningContainerProviderConnection).mockReturnValue(dummyConnection);
103104
vi.mocked(podmanConnection.getContainerProviderConnection).mockReturnValue(dummyConnection);
@@ -277,6 +278,7 @@ describe('perform', () => {
277278
apiPort: 10434,
278279
experimentalTuning: false,
279280
modelUploadDisabled: false,
281+
showGPUPromotion: false,
280282
});
281283

282284
vi.mocked(gpuManager.collectGPUs).mockResolvedValue([
@@ -318,6 +320,7 @@ describe('perform', () => {
318320
apiPort: 10434,
319321
experimentalTuning: false,
320322
modelUploadDisabled: false,
323+
showGPUPromotion: false,
321324
});
322325

323326
vi.mocked(gpuManager.collectGPUs).mockResolvedValue([
@@ -352,6 +355,7 @@ describe('perform', () => {
352355
apiPort: 10434,
353356
experimentalTuning: false,
354357
modelUploadDisabled: false,
358+
showGPUPromotion: false,
355359
});
356360

357361
vi.mocked(gpuManager.collectGPUs).mockResolvedValue([

packages/frontend/src/lib/notification/ContainerConnectionWrapper.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ beforeEach(() => {
6969
experimentalTuning: false,
7070
modelsPath: '',
7171
modelUploadDisabled: false,
72+
showGPUPromotion: false,
7273
});
7374
});
7475

packages/frontend/src/pages/CreateService.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ beforeEach(() => {
154154
experimentalTuning: false,
155155
modelsPath: '',
156156
modelUploadDisabled: false,
157+
showGPUPromotion: false,
157158
});
158159

159160
window.HTMLElement.prototype.scrollIntoView = vi.fn();

packages/shared/src/StudioAPI.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export abstract class StudioAPI {
177177
* Get the extension configuration (preferences)
178178
*/
179179
abstract getExtensionConfiguration(): Promise<ExtensionConfiguration>;
180+
abstract updateExtensionConfiguration(update: Partial<ExtensionConfiguration>): Promise<void>;
180181

181182
/**
182183
* Return the list of supported languages to generate code from.

packages/shared/src/models/IExtensionConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export interface ExtensionConfiguration {
2222
apiPort: number;
2323
experimentalTuning: boolean;
2424
modelUploadDisabled: boolean;
25+
showGPUPromotion: boolean;
2526
}

0 commit comments

Comments
 (0)