odant-work 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/#system/package-manifest.json +20 -18
- package/MODELS/$ai/$folder/$class/$provider/handlers/pages/form/trainer/$handler/trainer.js +9 -5
- package/MODELS/Local/$provider/class.js +2 -2
- package/package.json +1 -1
- package/scripts/check-ignored-code.mjs +4 -2
- package/sources/data/progress.md +9 -0
- package/sources/host/auto-updater.js +1 -0
- package/sources/modules/license/index.js +4 -2
- package/sources/modules/trainer/dataset.js +5 -2
- package/sources/modules/trainer/downloader.js +129 -25
- package/sources/modules/trainer/halogen.js +48 -23
- package/sources/modules/trainer/huggingface.js +182 -42
- package/sources/modules/trainer/index.js +2 -0
- package/sources/modules/trainer/local-engine.js +8 -2
- package/sources/modules/trainer/paths.js +257 -0
- package/sources/modules/trainer/providers.js +23 -6
- package/sources/modules/trainer/runner.js +57 -31
- package/sources/modules/trainer/transfer.js +142 -136
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Канонические пути подсистемы локальных моделей ИИ (правило метапапок WORK / ODANT):
|
|
3
|
+
* - Всё, что относится к провайдеру `/MODELS/Local`, живёт внутри его метапапки `MODELS/Local/$provider/`:
|
|
4
|
+
* - `#datasets/` — собранные обучающие наборы (.jsonl)
|
|
5
|
+
* - `#adapters/` — обученные LoRA-адаптеры
|
|
6
|
+
* - `#runtime/` — нативные рантаймы (bubo, gufo, strata, ROCm)
|
|
7
|
+
* - `#cache/` — дисковый кэш инференса
|
|
8
|
+
* - `#tmp/` — временная область распаковки импорта
|
|
9
|
+
* - Дети `/MODELS/Local` — только папки конкретных моделей `MODELS/Local/<Модель>/`,
|
|
10
|
+
* а всё относящееся к модели (включая `#weights` и активные `.part`-загрузки с `download-state.json`)
|
|
11
|
+
* лежит строго внутри её метапапки `MODELS/Local/<Модель>/$ai/#weights/`.
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
|
+
export const WEIGHT_FILE_EXT_RE = /\.(gguf|safetensors|hgn|hnpw|bin|onnx|pt|pth)$/i;
|
|
17
|
+
|
|
18
|
+
export function localRootDir(rootDir = process.cwd()) {
|
|
19
|
+
return path.join(rootDir, 'MODELS', 'Local');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function localProviderMetaDir(rootDir = process.cwd()) {
|
|
23
|
+
return path.join(localRootDir(rootDir), '$provider');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function localDatasetsDir(rootDir = process.cwd()) {
|
|
27
|
+
return path.join(localProviderMetaDir(rootDir), '#datasets');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function localAdaptersDir(rootDir = process.cwd()) {
|
|
31
|
+
return path.join(localProviderMetaDir(rootDir), '#adapters');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function localRuntimeDir(rootDir = process.cwd()) {
|
|
35
|
+
return path.join(localProviderMetaDir(rootDir), '#runtime');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function localCacheDir(rootDir = process.cwd()) {
|
|
39
|
+
return path.join(localProviderMetaDir(rootDir), '#cache');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function localTempDir(rootDir = process.cwd()) {
|
|
43
|
+
return path.join(localProviderMetaDir(rootDir), '#tmp');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function modelDir(rootDir = process.cwd(), folderName, providerFolder = 'Local') {
|
|
47
|
+
return path.join(rootDir, 'MODELS', String(providerFolder || 'Local'), String(folderName || ''));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function modelMetaDir(rootDir = process.cwd(), folderName, providerFolder = 'Local') {
|
|
51
|
+
return path.join(modelDir(rootDir, folderName, providerFolder), '$ai');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function modelWeightsDir(rootDir = process.cwd(), folderName, providerFolder = 'Local') {
|
|
55
|
+
return path.join(modelMetaDir(rootDir, folderName, providerFolder), '#weights');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function modelClassFile(rootDir = process.cwd(), folderName, providerFolder = 'Local') {
|
|
59
|
+
return path.join(modelMetaDir(rootDir, folderName, providerFolder), 'class.js');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Проверить, есть ли в директории готовые файлы весов (не .part).
|
|
64
|
+
*/
|
|
65
|
+
export function hasReadyWeightFilesSync(dirPath) {
|
|
66
|
+
if (!dirPath || !fs.existsSync(dirPath))
|
|
67
|
+
return false;
|
|
68
|
+
try {
|
|
69
|
+
return fs.readdirSync(dirPath).some(f => !f.endsWith('.part') && WEIGHT_FILE_EXT_RE.test(f));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Безопасно перенести/слить старую папку `src` в `dest` без потери файлов.
|
|
78
|
+
* На одном томе использует мгновенный `renameSync`; при занятых файлах (`EBUSY`) не падает.
|
|
79
|
+
*/
|
|
80
|
+
export function mergeMoveDirSync(srcDir, destDir) {
|
|
81
|
+
if (!srcDir || !fs.existsSync(srcDir))
|
|
82
|
+
return false;
|
|
83
|
+
if (path.resolve(srcDir) === path.resolve(destDir))
|
|
84
|
+
return true;
|
|
85
|
+
|
|
86
|
+
fs.mkdirSync(path.dirname(destDir), { recursive: true });
|
|
87
|
+
if (!fs.existsSync(destDir)) {
|
|
88
|
+
try {
|
|
89
|
+
fs.renameSync(srcDir, destDir);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
catch { /* слияние по файлам ниже */ }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
96
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true });
|
|
97
|
+
for (const e of entries) {
|
|
98
|
+
const srcEntry = path.join(srcDir, e.name);
|
|
99
|
+
const destEntry = path.join(destDir, e.name);
|
|
100
|
+
try {
|
|
101
|
+
if (e.isDirectory()) {
|
|
102
|
+
mergeMoveDirSync(srcEntry, destEntry);
|
|
103
|
+
}
|
|
104
|
+
else if (e.isFile()) {
|
|
105
|
+
if (!fs.existsSync(destEntry)) {
|
|
106
|
+
try {
|
|
107
|
+
fs.renameSync(srcEntry, destEntry);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
fs.copyFileSync(srcEntry, destEntry);
|
|
111
|
+
fs.unlinkSync(srcEntry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Если в цели уже есть файл — для download-state.json берём более свежий, иначе удаляем старый дубль только если целевой >= по размеру
|
|
116
|
+
const srcSt = fs.statSync(srcEntry);
|
|
117
|
+
const dstSt = fs.statSync(destEntry);
|
|
118
|
+
if (e.name === 'download-state.json' ? srcSt.mtimeMs > dstSt.mtimeMs : srcSt.size > dstSt.size) {
|
|
119
|
+
fs.rmSync(destEntry, { force: true });
|
|
120
|
+
try {
|
|
121
|
+
fs.renameSync(srcEntry, destEntry);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
fs.copyFileSync(srcEntry, destEntry);
|
|
125
|
+
fs.unlinkSync(srcEntry);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch { /* занятый файл другого процесса — оставим до следующего прохода */ }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
if (!fs.readdirSync(srcDir).length)
|
|
136
|
+
fs.rmdirSync(srcDir);
|
|
137
|
+
}
|
|
138
|
+
catch { /* папка не пуста или занята */ }
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Разовая/идемпотентная миграция старой раскладки `MODELS/Local`:
|
|
144
|
+
* - `#datasets`, `#adapters`, `#runtime`, `#cache` → `MODELS/Local/$provider/#...`;
|
|
145
|
+
* - `#downloads/<Модель>` → `MODELS/Local/<Модель>/$ai/#weights/`;
|
|
146
|
+
* - `MODELS/Local/<Модель>/#weights/` → `MODELS/Local/<Модель>/$ai/#weights/`.
|
|
147
|
+
*/
|
|
148
|
+
export function migrateLocalModelsLayoutSync(rootDir = process.cwd(), { skipModels = null } = {}) {
|
|
149
|
+
const localRoot = localRootDir(rootDir);
|
|
150
|
+
if (!fs.existsSync(localRoot))
|
|
151
|
+
return;
|
|
152
|
+
|
|
153
|
+
const providerMeta = localProviderMetaDir(rootDir);
|
|
154
|
+
|
|
155
|
+
// 1. Служебные папки провайдера Local переносим в $provider/
|
|
156
|
+
for (const dirName of ['#datasets', '#adapters', '#runtime', '#cache']) {
|
|
157
|
+
const legacy = path.join(localRoot, dirName);
|
|
158
|
+
if (fs.existsSync(legacy))
|
|
159
|
+
mergeMoveDirSync(legacy, path.join(providerMeta, dirName));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 2. Старая папка #downloads/<Модель> переносится в <Модель>/$ai/#weights
|
|
163
|
+
const legacyDownloads = path.join(localRoot, '#downloads');
|
|
164
|
+
if (fs.existsSync(legacyDownloads)) {
|
|
165
|
+
try {
|
|
166
|
+
const dlEntries = fs.readdirSync(legacyDownloads, { withFileTypes: true });
|
|
167
|
+
for (const e of dlEntries) {
|
|
168
|
+
if (!e.isDirectory() || e.name.startsWith('.'))
|
|
169
|
+
continue;
|
|
170
|
+
if (e.name.startsWith('_import_') || e.name.startsWith('_tar_import_')) {
|
|
171
|
+
mergeMoveDirSync(path.join(legacyDownloads, e.name), path.join(localTempDir(rootDir), e.name));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (skipModels && skipModels.has(e.name))
|
|
175
|
+
continue;
|
|
176
|
+
const src = path.join(legacyDownloads, e.name);
|
|
177
|
+
const dstWeights = modelWeightsDir(rootDir, e.name);
|
|
178
|
+
mergeMoveDirSync(src, dstWeights);
|
|
179
|
+
|
|
180
|
+
// Если $ai/class.js ещё нет, но в download-state.json сохранены метаданные — создадим неактивный узел $ai
|
|
181
|
+
const aiClass = modelClassFile(rootDir, e.name);
|
|
182
|
+
const stateFile = path.join(dstWeights, 'download-state.json');
|
|
183
|
+
if (!fs.existsSync(aiClass) && fs.existsSync(stateFile)) {
|
|
184
|
+
try {
|
|
185
|
+
const st = JSON.parse(fs.readFileSync(stateFile, 'utf-8')) || {};
|
|
186
|
+
const meta = {
|
|
187
|
+
label: st.label || e.name,
|
|
188
|
+
icon: st.nodeMeta?.icon || 'ai:ollama',
|
|
189
|
+
protocol: st.nodeMeta?.protocol || 'local',
|
|
190
|
+
baseUrl: st.nodeMeta?.baseUrl || 'http://127.0.0.1:8731/v1/chat/completions',
|
|
191
|
+
model: st.nodeMeta?.model || st.repoId || e.name,
|
|
192
|
+
modality: st.modality || st.nodeMeta?.modality || 'llm',
|
|
193
|
+
maxTokens: Number(st.nodeMeta?.maxTokens) || 16384,
|
|
194
|
+
maxOutput: Number(st.nodeMeta?.maxOutput) || 8192,
|
|
195
|
+
capabilities: Array.isArray(st.capabilities) ? st.capabilities : ['chat', 'stream'],
|
|
196
|
+
hfRepo: st.repoId || '',
|
|
197
|
+
weightsDir: path.relative(rootDir, dstWeights).replace(/\\/g, '/'),
|
|
198
|
+
};
|
|
199
|
+
fs.mkdirSync(path.dirname(aiClass), { recursive: true });
|
|
200
|
+
fs.writeFileSync(aiClass, `/**\n * Локальная модель ИИ: ${meta.label}\n */\nexport default ${JSON.stringify(meta, null, 4)};\n`, 'utf-8');
|
|
201
|
+
}
|
|
202
|
+
catch { /* ignore */ }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
if (!fs.readdirSync(legacyDownloads).length)
|
|
207
|
+
fs.rmdirSync(legacyDownloads);
|
|
208
|
+
}
|
|
209
|
+
catch { /* ignore */ }
|
|
210
|
+
}
|
|
211
|
+
catch { /* ignore */ }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 3. Папки моделей со старым #weights на уровне модели (рядом с $ai) переносим в $ai/#weights
|
|
215
|
+
try {
|
|
216
|
+
const entries = fs.readdirSync(localRoot, { withFileTypes: true });
|
|
217
|
+
for (const e of entries) {
|
|
218
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#') || e.name === 'models')
|
|
219
|
+
continue;
|
|
220
|
+
if (skipModels && skipModels.has(e.name))
|
|
221
|
+
continue;
|
|
222
|
+
const mDir = path.join(localRoot, e.name);
|
|
223
|
+
const legacyWeights = path.join(mDir, '#weights');
|
|
224
|
+
const newWeights = modelWeightsDir(rootDir, e.name);
|
|
225
|
+
if (fs.existsSync(legacyWeights))
|
|
226
|
+
mergeMoveDirSync(legacyWeights, newWeights);
|
|
227
|
+
|
|
228
|
+
const classFile = modelClassFile(rootDir, e.name);
|
|
229
|
+
if (fs.existsSync(classFile)) {
|
|
230
|
+
try {
|
|
231
|
+
const raw = fs.readFileSync(classFile, 'utf-8');
|
|
232
|
+
const jsonPart = raw.replace(/^[^{]*/, '').replace(/;\s*$/, '');
|
|
233
|
+
const meta = JSON.parse(jsonPart);
|
|
234
|
+
let changed = false;
|
|
235
|
+
const expectedWeightsRel = path.relative(rootDir, newWeights).replace(/\\/g, '/');
|
|
236
|
+
if (meta.weightsDir && !meta.weightsDir.includes('/$ai/#weights') && fs.existsSync(newWeights)) {
|
|
237
|
+
meta.weightsDir = expectedWeightsRel;
|
|
238
|
+
changed = true;
|
|
239
|
+
}
|
|
240
|
+
if (meta.adapterPath && !meta.adapterPath.includes('/$provider/#adapters/')) {
|
|
241
|
+
const adName = path.basename(String(meta.adapterPath));
|
|
242
|
+
const newAdPath = path.join(localAdaptersDir(rootDir), adName);
|
|
243
|
+
if (fs.existsSync(newAdPath)) {
|
|
244
|
+
meta.adapterPath = path.relative(rootDir, newAdPath).replace(/\\/g, '/');
|
|
245
|
+
changed = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (changed) {
|
|
249
|
+
fs.writeFileSync(classFile, `/**\n * Локальная модель ИИ: ${meta.label || e.name}\n */\nexport default ${JSON.stringify(meta, null, 4)};\n`, 'utf-8');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch { /* ignore non-json */ }
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch { /* ignore */ }
|
|
257
|
+
}
|
|
@@ -782,9 +782,22 @@ function hasWeightFilesInDirSync(dir) {
|
|
|
782
782
|
if (!dir || !fs.existsSync(dir))
|
|
783
783
|
return false;
|
|
784
784
|
try {
|
|
785
|
-
|
|
785
|
+
const entries = fs.readdirSync(dir);
|
|
786
|
+
if (entries.includes('download-state.json')) {
|
|
787
|
+
try {
|
|
788
|
+
const st = JSON.parse(fs.readFileSync(path.join(dir, 'download-state.json'), 'utf-8'));
|
|
789
|
+
if (st?.status !== 'completed')
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
catch {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return entries.some(f =>
|
|
786
797
|
!f.endsWith('.part')
|
|
798
|
+
&& !f.endsWith('.tmp')
|
|
787
799
|
&& f !== 'hf-manifest.json'
|
|
800
|
+
&& f !== 'download-state.json'
|
|
788
801
|
&& /\.(safetensors|gguf|bin|onnx|pt|pth|hgn|hnpw|json)$/i.test(f)
|
|
789
802
|
);
|
|
790
803
|
}
|
|
@@ -861,7 +874,8 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
861
874
|
if (!entry.isDirectory() || entry.name.startsWith('$') || entry.name.startsWith('#') || entry.name === 'models')
|
|
862
875
|
continue;
|
|
863
876
|
if (
|
|
864
|
-
hasWeightFilesInDirSync(path.join(localDir, entry.name, '#weights'))
|
|
877
|
+
hasWeightFilesInDirSync(path.join(localDir, entry.name, '$ai', '#weights'))
|
|
878
|
+
|| hasWeightFilesInDirSync(path.join(localDir, entry.name, '#weights'))
|
|
865
879
|
|| hasWeightFilesInDirSync(path.join(localDir, entry.name, '#adapters'))
|
|
866
880
|
) {
|
|
867
881
|
installedCount++;
|
|
@@ -879,15 +893,18 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
879
893
|
|
|
880
894
|
// Дочерняя модель в /MODELS/Local/<Model>
|
|
881
895
|
const modelName = parts[2] || item.id || '';
|
|
882
|
-
const
|
|
883
|
-
const
|
|
884
|
-
const
|
|
896
|
+
const canonicalWeightsRel = path.join('MODELS', 'Local', modelName, '$ai', '#weights');
|
|
897
|
+
const legacyWeightsRel = path.join('MODELS', 'Local', modelName, '#weights');
|
|
898
|
+
const adapterRel = data.adapterPath || path.join('MODELS', 'Local', '$provider', '#adapters', modelName);
|
|
899
|
+
const hasWeights = hasWeightFilesInDirSync(path.resolve(rootDir, data.weightsDir || canonicalWeightsRel))
|
|
900
|
+
|| hasWeightFilesInDirSync(path.resolve(rootDir, canonicalWeightsRel))
|
|
901
|
+
|| hasWeightFilesInDirSync(path.resolve(rootDir, legacyWeightsRel))
|
|
885
902
|
|| hasWeightFilesInDirSync(path.resolve(rootDir, adapterRel))
|
|
886
903
|
|| fs.existsSync(path.join(rootDir, 'MODELS', 'Local', 'models', 'qwen38-flash-next-base-ud-q4-k-xl-v1', 'bubo-package.json'));
|
|
887
904
|
if (hasWeights) {
|
|
888
905
|
return { active: true, reason: 'Активна (веса модели на диске)', configuredKey: true };
|
|
889
906
|
}
|
|
890
|
-
return { active: false, reason: 'Веса модели не скачаны в
|
|
907
|
+
return { active: false, reason: 'Веса модели не скачаны в $ai/#weights', configuredKey: false };
|
|
891
908
|
}
|
|
892
909
|
|
|
893
910
|
// 2. Внешние и облачные провайдеры ($provider и их $ai)
|
|
@@ -9,6 +9,15 @@ import crypto from 'node:crypto';
|
|
|
9
9
|
import { spawn } from 'node:child_process';
|
|
10
10
|
import { registerLocalModelNode, estimateModelMemoryFromId, listHuggingFaceDownloads } from './huggingface.js';
|
|
11
11
|
import { verifyCompletion } from './dataset.js';
|
|
12
|
+
import {
|
|
13
|
+
localRootDir,
|
|
14
|
+
localAdaptersDir,
|
|
15
|
+
localDatasetsDir,
|
|
16
|
+
modelWeightsDir,
|
|
17
|
+
modelClassFile,
|
|
18
|
+
migrateLocalModelsLayoutSync,
|
|
19
|
+
WEIGHT_FILE_EXT_RE,
|
|
20
|
+
} from './paths.js';
|
|
12
21
|
|
|
13
22
|
const _jobs = new Map();
|
|
14
23
|
let _hwCache = null;
|
|
@@ -200,7 +209,7 @@ export async function detectHardware({ force = false } = {}) {
|
|
|
200
209
|
* Инвентарь локальных моделей и обученных LoRA-адаптеров в `/MODELS/Local`.
|
|
201
210
|
*/
|
|
202
211
|
export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
203
|
-
const localRoot =
|
|
212
|
+
const localRoot = localRootDir(rootDir);
|
|
204
213
|
const legacyHalogenRoot = path.join(rootDir, 'MODELS', 'Halogen');
|
|
205
214
|
|
|
206
215
|
// Автоматическая миграция и очистка устаревшей дублирующей папки MODELS/Halogen
|
|
@@ -213,7 +222,7 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
213
222
|
const oldWeights = path.join(legacyHalogenRoot, he.name, '#weights');
|
|
214
223
|
if (fs.existsSync(oldWeights)) {
|
|
215
224
|
const wf = await fsp.readdir(oldWeights).catch(() => []);
|
|
216
|
-
const hasRealWeight = wf.some(f => !f.endsWith('.part') &&
|
|
225
|
+
const hasRealWeight = wf.some(f => !f.endsWith('.part') && WEIGHT_FILE_EXT_RE.test(f));
|
|
217
226
|
if (hasRealWeight) {
|
|
218
227
|
const targetModelDir = path.join(localRoot, he.name);
|
|
219
228
|
if (!fs.existsSync(targetModelDir)) {
|
|
@@ -228,46 +237,62 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
228
237
|
catch { /* ignore */ }
|
|
229
238
|
}
|
|
230
239
|
|
|
240
|
+
const activeDownloads = listHuggingFaceDownloads(rootDir).filter(d => d.status === 'downloading');
|
|
241
|
+
migrateLocalModelsLayoutSync(rootDir, { skipModels: new Set(activeDownloads.map(d => d.folderName)) });
|
|
242
|
+
|
|
231
243
|
const models = [];
|
|
232
244
|
const adapters = [];
|
|
245
|
+
|
|
246
|
+
// Адаптеры хранятся внутри метапапки провайдера Local: MODELS/Local/$provider/#adapters
|
|
247
|
+
const adaptersDir = localAdaptersDir(rootDir);
|
|
248
|
+
if (fs.existsSync(adaptersDir)) {
|
|
249
|
+
const adEntries = await fsp.readdir(adaptersDir, { withFileTypes: true }).catch(() => []);
|
|
250
|
+
for (const ad of adEntries) {
|
|
251
|
+
if (!ad.isDirectory())
|
|
252
|
+
continue;
|
|
253
|
+
const cfgPath = path.join(adaptersDir, ad.name, 'adapter_config.json');
|
|
254
|
+
if (fs.existsSync(cfgPath)) {
|
|
255
|
+
try {
|
|
256
|
+
adapters.push(JSON.parse(await fsp.readFile(cfgPath, 'utf-8')));
|
|
257
|
+
}
|
|
258
|
+
catch { /* ignore */ }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
233
263
|
if (!fs.existsSync(localRoot))
|
|
234
264
|
return { models, adapters };
|
|
235
265
|
|
|
236
|
-
const activeDownloads = listHuggingFaceDownloads().filter(d => d.status === 'downloading');
|
|
237
266
|
const entries = await fsp.readdir(localRoot, { withFileTypes: true });
|
|
238
267
|
for (const e of entries) {
|
|
239
|
-
if (!e.isDirectory() || e.name.startsWith('$'))
|
|
240
|
-
continue;
|
|
241
|
-
if (e.name === '#adapters') {
|
|
242
|
-
const adEntries = await fsp.readdir(path.join(localRoot, '#adapters'), { withFileTypes: true }).catch(() => []);
|
|
243
|
-
for (const ad of adEntries) {
|
|
244
|
-
if (!ad.isDirectory())
|
|
245
|
-
continue;
|
|
246
|
-
const cfgPath = path.join(localRoot, '#adapters', ad.name, 'adapter_config.json');
|
|
247
|
-
if (fs.existsSync(cfgPath)) {
|
|
248
|
-
try {
|
|
249
|
-
adapters.push(JSON.parse(await fsp.readFile(cfgPath, 'utf-8')));
|
|
250
|
-
}
|
|
251
|
-
catch { /* ignore */ }
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (e.name.startsWith('#'))
|
|
268
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
257
269
|
continue;
|
|
258
270
|
|
|
259
271
|
const isDownloading = activeDownloads.some(
|
|
260
272
|
d => d.folderName === e.name || d.modelPath === `/MODELS/Local/${e.name}`
|
|
261
273
|
);
|
|
262
|
-
const aiClassFile =
|
|
263
|
-
const weightsDir =
|
|
274
|
+
const aiClassFile = modelClassFile(rootDir, e.name, 'Local');
|
|
275
|
+
const weightsDir = modelWeightsDir(rootDir, e.name, 'Local');
|
|
264
276
|
let weightFiles = [];
|
|
265
277
|
let hasRealWeightBinary = false;
|
|
278
|
+
let hasPendingDownload = false;
|
|
266
279
|
let sizeBytes = 0;
|
|
267
280
|
if (fs.existsSync(weightsDir)) {
|
|
268
281
|
const wf = await fsp.readdir(weightsDir).catch(() => []);
|
|
269
|
-
|
|
270
|
-
|
|
282
|
+
const hasParts = wf.some(f => f.endsWith('.part'));
|
|
283
|
+
let pendingState = false;
|
|
284
|
+
if (wf.includes('download-state.json')) {
|
|
285
|
+
try {
|
|
286
|
+
const st = JSON.parse(await fsp.readFile(path.join(weightsDir, 'download-state.json'), 'utf-8'));
|
|
287
|
+
pendingState = st?.status !== 'completed';
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
pendingState = true;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
hasPendingDownload = hasParts || pendingState;
|
|
294
|
+
weightFiles = wf.filter(f => !f.endsWith('.part') && f !== 'hf-manifest.json' && f !== 'download-state.json' && !f.endsWith('.tmp'));
|
|
295
|
+
hasRealWeightBinary = weightFiles.some(f => WEIGHT_FILE_EXT_RE.test(f));
|
|
271
296
|
for (const f of weightFiles) {
|
|
272
297
|
try {
|
|
273
298
|
const st = await fsp.stat(path.join(weightsDir, f));
|
|
@@ -288,8 +313,8 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
288
313
|
|
|
289
314
|
const isAdapterNode = Boolean(meta.adapterPath);
|
|
290
315
|
|
|
291
|
-
// Если папка модели
|
|
292
|
-
if (!isDownloading && !hasRealWeightBinary && !isAdapterNode) {
|
|
316
|
+
// Если папка модели пустая (ни готовых весов, ни незавершённой загрузки, ни адаптера) — убираем мусор
|
|
317
|
+
if (!isDownloading && !hasPendingDownload && !hasRealWeightBinary && !isAdapterNode) {
|
|
293
318
|
try {
|
|
294
319
|
await fsp.rm(path.join(localRoot, e.name), { recursive: true, force: true });
|
|
295
320
|
}
|
|
@@ -297,8 +322,8 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
297
322
|
continue;
|
|
298
323
|
}
|
|
299
324
|
|
|
300
|
-
// Пока модель
|
|
301
|
-
if (isDownloading
|
|
325
|
+
// Пока модель качается или стоит на паузе/обрыве, она отображается только в загрузках, а не в «Установленных»
|
|
326
|
+
if ((isDownloading || hasPendingDownload) && !isAdapterNode) {
|
|
302
327
|
continue;
|
|
303
328
|
}
|
|
304
329
|
|
|
@@ -370,8 +395,9 @@ export async function startTrainingJob({
|
|
|
370
395
|
const resolvedMaxSeq = Number(maxSeqLength) || hw.recommendedMaxSeq || 8192;
|
|
371
396
|
|
|
372
397
|
const safeAdapter = String(adapterName || 'work-lora').replace(/[<>:"/\\|?*]/g, '-').trim();
|
|
373
|
-
|
|
374
|
-
const
|
|
398
|
+
migrateLocalModelsLayoutSync(rootDir);
|
|
399
|
+
const datasetFile = path.join(localDatasetsDir(rootDir), `${datasetName}.jsonl`);
|
|
400
|
+
const outputDir = path.join(localAdaptersDir(rootDir), safeAdapter);
|
|
375
401
|
await fsp.mkdir(outputDir, { recursive: true });
|
|
376
402
|
|
|
377
403
|
let datasetLines = 0;
|