Skip to content

Commit

Permalink
fix: handle arch as array and gpu-env and switch to base repo for sample
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff MAURY <[email protected]>
  • Loading branch information
jeffmaury committed Jan 25, 2024
1 parent 6c5ca63 commit 0f318bf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/ai.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "chatbot",
"description" : "Chat bot application",
"name" : "ChatBot",
"repository": "https://github.com/axel7083/locallm",
"repository": "https://github.com/redhat-et/locallm",
"icon": "natural-language-processing",
"categories": [
"natural-language-processing"
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getParentDirectory } from '../utils/pathUtils';
import type { ModelInfo } from '@shared/src/models/IModelInfo';
import type { ModelsManager } from './modelsManager';
import { getPortsInfo } from '../utils/ports';
import { goarch } from '../utils/arch';

export const CONFIG_FILENAME = 'ai-studio.yaml';

Expand Down Expand Up @@ -342,7 +343,7 @@ export class ApplicationManager {

filterContainers(aiConfig: AIConfig): ContainerConfig[] {
return aiConfig.application.containers.filter(
container => container.arch === undefined || container.arch === arch(),
container => container.gpu_env.length === 0 && container.arch.some(arc => arc === goarch()),
);
}

Expand Down Expand Up @@ -398,7 +399,7 @@ export class ApplicationManager {
const rawConfiguration = fs.readFileSync(configFile, 'utf-8');
let aiConfig: AIConfig;
try {
aiConfig = parseYaml(rawConfiguration, arch());
aiConfig = parseYaml(rawConfiguration, goarch());
} catch (err) {
throw new Error('Cannot load configuration file.');
}
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/models/AIConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export interface ContainerConfig {
name: string;
contextdir: string;
containerfile?: string;
arch: string;
arch: string[];
modelService: boolean;
gpu_env: string[];
}
export interface AIConfig {
application: {
Expand Down Expand Up @@ -55,11 +56,12 @@ export function parseYaml(raw: string, defaultArch: string): AIConfig {
return {
application: {
containers: containers.map(container => ({
arch: isString(container['arch']) ? container['arch'] : defaultArch,
arch: Array.isArray(container['arch']) ? container['arch'] : [defaultArch],
modelService: container['model-service'] === true,
containerfile: isString(container['containerfile']) ? container['containerfile'] : undefined,
contextdir: assertString(container['contextdir']),
name: assertString(container['name']),
gpu_env: Array.isArray(container['gpu-env']) ? container['gpu-env'] : [],
})),
},
};
Expand Down
31 changes: 31 additions & 0 deletions packages/backend/src/utils/arch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import { arch } from 'node:os';

const nodeArch2GoArch = new Map<string, string>([
['ia32', '386'],
['x64', 'amd64'],
]);

export function goarch(): string {
let localArch = arch();
if (nodeArch2GoArch.has(localArch)) {
localArch = nodeArch2GoArch.get(localArch);
}
return localArch;
}

0 comments on commit 0f318bf

Please sign in to comment.