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

[OPENVINO CODE] add device options on Frontend and Backend for choosing a preferred device while running a model #889

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 2 deletions modules/openvino_code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion modules/openvino_code/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"publisher": "OpenVINO",
"name": "openvino-code-completion",
"version": "0.0.11",
"version": "0.0.12",
"displayName": "OpenVINO Code Completion",
"description": "VSCode extension for AI code completion with OpenVINO",
"icon": "media/logo.png",
Expand Down Expand Up @@ -199,6 +199,17 @@
],
"description": "Which model to use for code generation."
},
"openvinoCode.device": {
"order": 0,
"type": "string",
"default": "GPU",
"enum": [
"CPU",
"GPU",
"NPU"
],
"description": "Which device to use for code generation."
},
"openvinoCode.serverUrl": {
"order": 1,
"type": "string",
Expand Down
7 changes: 7 additions & 0 deletions modules/openvino_code/server/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from src.utils import get_parser, setup_logger
import logging



# Logger should be set up before other imports to propagate logging config to other packages
setup_logger()
logger = logging.getLogger("")


import uvicorn # noqa: E402

Expand All @@ -14,6 +18,9 @@ def main():
args = get_parser().parse_args()

# temporary solution for cli args passing

logger.error(args.model)
logger.error(args.device)
generator_dependency = get_generator_dependency(args.model, args.device, args.tokenizer_checkpoint, args.assistant)
app.dependency_overrides[get_generator_dummy] = generator_dependency

Expand Down
2 changes: 1 addition & 1 deletion modules/openvino_code/server/src/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class OVGenerator(GeneratorFunctor):
def __init__(
self,
checkpoint: str,
device: str = "CPU",
device: str = "GPU",
tokenizer_checkpoint: Optional[str] = None,
assistant_checkpoint: Optional[str] = None,
summarize_stop_tokens: Optional[Container[str]] = SUMMARIZE_STOP_TOKENS,
Expand Down
1 change: 1 addition & 0 deletions modules/openvino_code/shared/side-panel-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum SidePanelMessageTypes {
GENERATE_COMPLETION_CLICK = `${sidePanelMessagePrefix}.generateCompletionClick`,
SETTINGS_CLICK = `${sidePanelMessagePrefix}.settingsClick`,
MODEL_CHANGE = `${sidePanelMessagePrefix}.modelChange`,
DEVICE_CHANGE = `${sidePanelMessagePrefix}.deviceChange`,
}

export interface ISidePanelMessage<P = unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import './ServerSection.css';
import { ModelSelect } from './ModelSelect/ModelSelect';
import { ModelName } from '@shared/model';
import { DeviceSelect } from './DeviceSelect/DeviceSelect';

Check failure on line 10 in modules/openvino_code/side-panel-ui/src/components/sections/ServerSection/ServerSection.tsx

View workflow job for this annotation

GitHub Actions / check_extension

Unable to resolve path to module './DeviceSelect/DeviceSelect'

Check failure on line 10 in modules/openvino_code/side-panel-ui/src/components/sections/ServerSection/ServerSection.tsx

View workflow job for this annotation

GitHub Actions / check_extension

Missing file extension for "./DeviceSelect/DeviceSelect"
import { DeviceName } from '@shared/device';

Check failure on line 11 in modules/openvino_code/side-panel-ui/src/components/sections/ServerSection/ServerSection.tsx

View workflow job for this annotation

GitHub Actions / check_extension

Unable to resolve path to module '@shared/device'


interface ServerSectionProps {
state: IExtensionState | null;
Expand Down Expand Up @@ -46,6 +49,15 @@
});
};

const handleDeviceChange = (deviceName: DeviceName) => {
vscode.postMessage({
type: SidePanelMessageTypes.DEVICE_CHANGE,
payload: {
deviceName,

Check failure on line 56 in modules/openvino_code/side-panel-ui/src/components/sections/ServerSection/ServerSection.tsx

View workflow job for this annotation

GitHub Actions / check_extension

Unsafe assignment of an `any` value
},
});
};

if (!state) {
return <>Extension state is not available</>;
}
Expand All @@ -64,6 +76,13 @@
supportedFeatures={state.features.supportedList}
serverStatus={state.server.status}
></ModelSelect>
<DeviceSelect
disabled={!isServerStopped}
onChange={handleDeviceChange}
selectedDeviceName={state.config.device}

Check failure on line 82 in modules/openvino_code/side-panel-ui/src/components/sections/ServerSection/ServerSection.tsx

View workflow job for this annotation

GitHub Actions / check_extension

Unsafe assignment of an `any` value
supportedFeatures={state.features.supportedList}
serverStatus={state.server.status}
></DeviceSelect>
{isServerStarting && <StartingStages currentStage={state.server.stage}></StartingStages>}
<div className="button-group">
{isServerStopped && <button onClick={handleStartServerClick}>Start Server</button>}
Expand Down
2 changes: 2 additions & 0 deletions modules/openvino_code/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ModelName } from '@shared/model';
import { DeviceName } from '@shared/device';

Check failure on line 2 in modules/openvino_code/src/configuration.ts

View workflow job for this annotation

GitHub Actions / check_extension

Unable to resolve path to module '@shared/device'
import { WorkspaceConfiguration, workspace } from 'vscode';
import { CONFIG_KEY } from './constants';

Expand All @@ -7,6 +8,7 @@
*/
export type CustomConfiguration = {
model: ModelName;
device: DeviceName;
serverUrl: string;
serverRequestTimeout: number;
streamInlineCompletion: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import { MODEL_NAME_TO_ID_MAP, ModelName } from '@shared/model';
import { extensionState } from '../state';
import { clearLruCache } from '../lru-cache.decorator';
import { DEVICE_NAME_TO_ID_MAP, DeviceName } from '@shared/device';

Check failure on line 16 in modules/openvino_code/src/python-server/python-server-runner.ts

View workflow job for this annotation

GitHub Actions / check_extension

Unable to resolve path to module '@shared/device'

const SERVER_STARTED_STDOUT_ANCHOR = 'OpenVINO Code Server started';

interface ServerHooks {
onStarted: () => void;
}

async function runServer(modelName: ModelName, config: PythonServerConfiguration, hooks?: ServerHooks) {
async function runServer(modelName: ModelName, deviceName: DeviceName, config: PythonServerConfiguration, hooks?: ServerHooks) {
const { serverDir, proxyEnv, abortSignal, logger } = config;
logger.info('Starting server...');

Expand All @@ -40,8 +41,9 @@
}

const model = MODEL_NAME_TO_ID_MAP[modelName];
const device = DEVICE_NAME_TO_ID_MAP[deviceName];

Check failure on line 44 in modules/openvino_code/src/python-server/python-server-runner.ts

View workflow job for this annotation

GitHub Actions / check_extension

Unsafe assignment of an `any` value

Check failure on line 44 in modules/openvino_code/src/python-server/python-server-runner.ts

View workflow job for this annotation

GitHub Actions / check_extension

Unsafe member access [deviceName] on an `any` value

Check failure on line 44 in modules/openvino_code/src/python-server/python-server-runner.ts

View workflow job for this annotation

GitHub Actions / check_extension

Computed name [deviceName] resolves to an any value

await spawnCommand(venvPython, ['main.py', '--model', model], {
await spawnCommand(venvPython, ['main.py', '--model', model, '--device', device], {
logger,
cwd: serverDir,
abortSignal,
Expand Down Expand Up @@ -149,8 +151,9 @@
this._stateController.setStage(ServerStartingStage.START_SERVER);

const modelName = extensionState.config.model;
const deviceName = extensionState.config.device;

await runServer(modelName, config, {
await runServer(modelName, deviceName, config, {
onStarted: () => {
this._stateController.setStatus(ServerStatus.STARTED);
this._stateController.setStage(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Webview, commands } from 'vscode';
import { settingsService } from '../settings/settings.service';
import { COMMANDS } from '../constants';
import { ModelName } from '@shared/model';
import { DeviceName } from '@shared/device';


type SidePanelMessageHandlerType = (webview: Webview, payload?: ISidePanelMessage['payload']) => void;

Expand All @@ -12,6 +14,8 @@ const sidePanelMessageHandlers: Record<SidePanelMessageTypes, SidePanelMessageHa
[SidePanelMessageTypes.SETTINGS_CLICK]: () => settingsService.openSettings(),
[SidePanelMessageTypes.MODEL_CHANGE]: (_, payload) =>
settingsService.updateSetting('model', (payload as { modelName: ModelName }).modelName),
[SidePanelMessageTypes.DEVICE_CHANGE]: (_, payload) =>
settingsService.updateSetting('device', (payload as { deviceName: DeviceName }).deviceName),
[SidePanelMessageTypes.START_SERVER_CLICK]: () => void commands.executeCommand(COMMANDS.START_SERVER_NATIVE),
[SidePanelMessageTypes.STOP_SERVER_CLICK]: () => void commands.executeCommand(COMMANDS.STOP_SERVER_NATIVE),
[SidePanelMessageTypes.SHOW_SERVER_LOG_CLICK]: () => void commands.executeCommand(COMMANDS.SHOW_SERVER_LOG),
Expand Down
Loading