Skip to content

Commit 29dd1fe

Browse files
高魏洪qwencoder
andcommitted
feat: add upgrade model support in fileManager remove operation
- Add upgrade property to modelConfig for handling upgrade models - Implement _removeUpgradeSingleFile method to handle upgrade file removal - Refactor remove operation to support both regular and upgrade files - Improve error logging order in retryFileManagerRm function - Consolidate remove promises into a single execution list Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 0cb5e83 commit 29dd1fe

3 files changed

Lines changed: 77 additions & 32 deletions

File tree

src/subCommands/model/fileManager.ts

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,29 @@ export class ArtModelService {
190190
const { nasMountPoints, ossMountPoints, role, vpcConfig, modelConfig, region } = params;
191191
try {
192192
const devClient = await initClient(this.inputs, this.region, 'fun-art');
193-
const { files } = modelConfig;
193+
const { files, upgrade } = modelConfig;
194194
if (_.isEmpty(files)) {
195195
logger.info('[Remove-model] No files specified for removal.');
196196
return;
197197
}
198+
let allRemovePromises = [];
199+
if (!_.isEmpty(upgrade)) {
200+
logger.info('[Remove-model] Upgrade model, only support once model.');
201+
const removeUpgradePromises = Object.keys(upgrade).map((key) =>
202+
this._removeUpgradeSingleFile(devClient, upgrade[key], key, {
203+
name,
204+
nasMountPoints,
205+
ossMountPoints: processedOssMountPoints,
206+
role,
207+
vpcConfig,
208+
modelConfig,
209+
region,
210+
timeout: modelConfig?.timeout,
211+
}),
212+
);
213+
// 将升级文件删除任务添加到总的任务列表中
214+
allRemovePromises = allRemovePromises.concat(removeUpgradePromises);
215+
}
198216
const processedOssMountPoints = extractOssMountDir(ossMountPoints);
199217

200218
// 将异步操作重构为并行处理
@@ -210,8 +228,10 @@ export class ArtModelService {
210228
timeout: modelConfig?.timeout,
211229
}),
212230
);
231+
// 将删除任务也添加到总的任务列表中
232+
allRemovePromises = allRemovePromises.concat(removePromises);
213233

214-
const removeResults = await Promise.all(removePromises);
234+
const removeResults = await Promise.all(allRemovePromises);
215235

216236
// 统计成功和失败的数量
217237
const successfulRemovals = removeResults.filter((result) => result.success);
@@ -261,27 +281,58 @@ export class ArtModelService {
261281
timeout: number;
262282
},
263283
) {
264-
const { name, nasMountPoints, ossMountPoints, role, vpcConfig, modelConfig, region, timeout } =
265-
config;
284+
const { nasMountPoints, ossMountPoints, modelConfig } = config;
285+
286+
let filepath: string;
287+
const uri = file.target?.uri || modelConfig.target.uri;
288+
const path = file.target?.path || '';
289+
const fileName = file.source?.path || 'unknown';
290+
291+
// 判断uri是否为nas://auto或oss://auto
292+
if (uri.startsWith('nas://auto') && nasMountPoints?.length > 0) {
293+
const { mountDir } = nasMountPoints[0];
294+
filepath = `${mountDir}/${path}`;
295+
} else if (uri.startsWith('oss://auto') && ossMountPoints?.length > 0) {
296+
const { mountDir } = ossMountPoints[0];
297+
filepath = `${mountDir}/${path}`;
298+
} else {
299+
// 直接拼接uri和path
300+
let normalizedUri = uri.endsWith('/') ? uri.slice(0, -1) : uri;
301+
normalizedUri = normalizedUri.replace(/^(nas|oss|file):\/\//, '/');
302+
filepath = `${normalizedUri}/${path}`;
303+
}
304+
305+
return this._removeFileWithRetry(devClient, filepath, fileName, config);
306+
}
307+
308+
private async _removeUpgradeSingleFile(
309+
devClient: DevClient,
310+
path: string,
311+
version: string,
312+
config: {
313+
name: string;
314+
nasMountPoints: any[];
315+
ossMountPoints: any[];
316+
role: string;
317+
vpcConfig: any;
318+
modelConfig: any;
319+
region: string;
320+
timeout: number;
321+
},
322+
) {
323+
const fileName = version || 'unknown';
266324

325+
return this._removeFileWithRetry(devClient, path, fileName, config);
326+
}
327+
328+
private async _removeFileWithRetry(
329+
devClient: DevClient,
330+
filepath: string,
331+
fileName: string,
332+
config: any,
333+
): Promise<any> {
267334
try {
268-
let filepath;
269-
const uri = file.target?.uri || modelConfig.target.uri;
270-
const path = file.target?.path || '';
271-
272-
// 判断uri是否为nas://auto或oss://auto
273-
if (uri.startsWith('nas://auto') && nasMountPoints?.length > 0) {
274-
const { mountDir } = nasMountPoints[0];
275-
filepath = `${mountDir}/${path}`;
276-
} else if (uri.startsWith('oss://auto') && ossMountPoints?.length > 0) {
277-
const { mountDir } = ossMountPoints[0];
278-
filepath = `${mountDir}/${path}`;
279-
} else {
280-
// 直接拼接uri和path
281-
let normalizedUri = uri.endsWith('/') ? uri.slice(0, -1) : uri;
282-
normalizedUri = normalizedUri.replace(/^(nas|oss|file):\/\//, '/');
283-
filepath = `${normalizedUri}/${path}`;
284-
}
335+
const { name, nasMountPoints, ossMountPoints, role, vpcConfig, region, timeout } = config;
285336

286337
const fileManagerRmRequest = new $Dev20230714.FileManagerRmRequest({
287338
filepath,
@@ -296,17 +347,10 @@ export class ArtModelService {
296347
}),
297348
});
298349

299-
const result = await retryFileManagerRm(
300-
devClient,
301-
fileManagerRmRequest,
302-
file.source.path,
303-
3,
304-
30,
305-
);
350+
const result = await retryFileManagerRm(devClient, fileManagerRmRequest, fileName, 3, 30);
306351

307352
return result;
308353
} catch (error) {
309-
const fileName = file.source?.path || 'unknown';
310354
logger.error(`[Remove-model] Error removing file ${fileName}: ${error.message}`);
311355
logger.error(`[Remove-model] Error details:`, error.stack || error);
312356
return {

src/subCommands/model/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ mountPoints:
297297
files: modelConfig.files,
298298
conflictResolution: modelConfig?.downloadStrategy?.conflictResolution || 'overwrite',
299299
mode: process.env.MODEL_DOWNLOAD_STRATEGY || modelConfig?.downloadStrategy?.mode || 'once',
300+
upgrade: modelConfig?.upgrade || {},
300301
timeout:
301302
(modelConfig?.downloadStrategy?.timeout &&
302303
modelConfig?.downloadStrategy?.timeout * 1000) ||

src/subCommands/model/utils/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ export async function retryFileManagerRm(
318318

319319
if (isInitializeError(modelStatus.errorMessage) && attempts < maxRetries) {
320320
const delay = baseDelay * Math.pow(2, attempts - 1);
321+
logger.error(
322+
`[Remove-model] model: ${modelStatus.errorMessage}, requestId: ${getFileManagerTask.body.requestId}`,
323+
);
321324
logger.warn(
322325
`[Remove-model] Detected initialization error for ${fileName}, retrying... (${
323326
attempts + 1
324327
}/${maxRetries}). Waiting ${delay}s`,
325328
);
326-
logger.error(
327-
`[Remove-model] model: ${modelStatus.errorMessage}, requestId: ${getFileManagerTask.body.requestId}`,
328-
);
329329

330330
// eslint-disable-next-line no-await-in-loop
331331
await sleep(delay);

0 commit comments

Comments
 (0)