@mlx-node/lm 0.0.6 → 0.0.8
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/README.md +71 -46
- package/dist/chat-session.d.ts +700 -0
- package/dist/chat-session.d.ts.map +1 -0
- package/dist/chat-session.js +1467 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -6
- package/dist/interfaces.d.ts +2 -7
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/models/lfm2-configs.d.ts +6 -0
- package/dist/models/lfm2-configs.d.ts.map +1 -0
- package/dist/models/lfm2-configs.js +107 -0
- package/dist/models/model-loader.d.ts +194 -4
- package/dist/models/model-loader.d.ts.map +1 -1
- package/dist/models/model-loader.js +253 -21
- package/dist/models/paged-config-override.d.ts +60 -0
- package/dist/models/paged-config-override.d.ts.map +1 -0
- package/dist/models/paged-config-override.js +254 -0
- package/dist/models/qwen3_5-configs.d.ts.map +1 -1
- package/dist/models/qwen3_5-configs.js +5 -0
- package/dist/stream.d.ts +234 -29
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +294 -52
- package/dist/tools/index.d.ts +38 -11
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +38 -11
- package/dist/tools/types.d.ts +5 -25
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +5 -30
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -12,20 +12,25 @@
|
|
|
12
12
|
* const result = await model.generate([{ role: 'user', content: 'Hello!' }]);
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export { Qwen3Model
|
|
16
|
-
export {
|
|
17
|
-
export
|
|
18
|
-
export {
|
|
19
|
-
export type {
|
|
20
|
-
export
|
|
21
|
-
export
|
|
15
|
+
export { Qwen3Model } from './stream.js';
|
|
16
|
+
export { Gemma4Model } from './stream.js';
|
|
17
|
+
export { HarrierModel } from '@mlx-node/core';
|
|
18
|
+
export { Qwen35Model } from './stream.js';
|
|
19
|
+
export type { Qwen35Config, Qwen35ContextLimits } from '@mlx-node/core';
|
|
20
|
+
export { Lfm2Model } from './stream.js';
|
|
21
|
+
export { LFM2_CONFIGS, getLfm2Config } from './models/lfm2-configs.js';
|
|
22
|
+
export { Qwen35MoeModel } from './stream.js';
|
|
23
|
+
export type { Qwen35MoeConfig } from '@mlx-node/core';
|
|
24
|
+
export { memoryStats } from '@mlx-node/core';
|
|
22
25
|
export type { ChatConfig, ChatResult, ChatMessage, ToolCallResult, PerformanceMetrics } from '@mlx-node/core';
|
|
23
26
|
export type { ChatStreamDelta, ChatStreamFinal, ChatStreamEvent } from './stream.js';
|
|
24
|
-
export
|
|
25
|
-
export {
|
|
27
|
+
export { _runChatStream, makeStreamingModel } from './stream.js';
|
|
28
|
+
export type { NativeStreamingInstance, NativeStreamingMethod, StreamingInstance, StreamingModel } from './stream.js';
|
|
29
|
+
export { ChatSession, ContextCapacityError, isContextCapacityError } from './chat-session.js';
|
|
30
|
+
export type { ChatSessionOptions, SendOptions, SessionCapableModel, SessionContextLimits } from './chat-session.js';
|
|
26
31
|
export { type Qwen3Config, QWEN3_CONFIGS, type GenerationResult, type GenerationConfig, getQwen3Config, } from './models/qwen3-configs.js';
|
|
27
|
-
export { loadModel, detectModelType, type ModelType } from './models/model-loader.js';
|
|
28
|
-
export type
|
|
32
|
+
export { loadModel, loadSession, detectModelType, type LoadableModel, type TrainableModel, type ModelType, type LoadModelOptions, } from './models/model-loader.js';
|
|
33
|
+
export { AGENT_PAGED_MODEL_TYPES, PagedConfigOverrideManager, QWEN35_PAGED_MODEL_TYPES, type PagedConfigOverrideManagerOptions, } from './models/paged-config-override.js';
|
|
29
34
|
export { QWEN35_CONFIGS, getQwen35Config } from './models/qwen3_5-configs.js';
|
|
30
35
|
export * from './tools/index.js';
|
|
31
36
|
export { enableProfiling, disableProfiling } from './profiling.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGxE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGvE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAsBtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAG9G,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AASrF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMrH,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGpH,OAAO,EACL,KAAK,WAAW,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,KAAK,iCAAiC,GACvC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9E,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,17 +13,58 @@
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
// Model classes (for inference)
|
|
16
|
-
export { Qwen3Model
|
|
17
|
-
|
|
16
|
+
export { Qwen3Model } from './stream.js';
|
|
17
|
+
// Gemma4 models
|
|
18
|
+
export { Gemma4Model } from './stream.js';
|
|
19
|
+
// Embedding models
|
|
20
|
+
export { HarrierModel } from '@mlx-node/core';
|
|
21
|
+
export { Qwen35Model } from './stream.js';
|
|
22
|
+
// LFM2 models
|
|
23
|
+
export { Lfm2Model } from './stream.js';
|
|
24
|
+
export { LFM2_CONFIGS, getLfm2Config } from './models/lfm2-configs.js';
|
|
18
25
|
// MoE variant
|
|
19
|
-
export { Qwen35MoeModel
|
|
26
|
+
export { Qwen35MoeModel } from './stream.js';
|
|
27
|
+
// Memory hygiene: most management is automatic — the decode loop
|
|
28
|
+
// inside `@mlx-node/core` calls `mlx_clear_cache()` every 256 generated
|
|
29
|
+
// tokens to prevent unbounded free-pool growth during long
|
|
30
|
+
// generations, and `MLX_CACHE_LIMIT_GB` auto-tunes the Metal pool cap
|
|
31
|
+
// at model load. Across-request drains are handled by the
|
|
32
|
+
// `@mlx-node/server` idle sweeper (see `packages/server/src/idle-sweeper.ts`):
|
|
33
|
+
// a single `clearCache()` fires after `idleClearCacheMs` of HTTP
|
|
34
|
+
// inactivity once the in-flight request counter has returned to zero.
|
|
35
|
+
// `memoryStats()` is re-exported as a read-only observability hook for
|
|
36
|
+
// dashboards / debugging.
|
|
37
|
+
//
|
|
38
|
+
// `clearCache()` is DELIBERATELY not re-exported here: the native impl
|
|
39
|
+
// routes through MLX's no-arg `synchronize()` which waits only on the
|
|
40
|
+
// default stream, so calling it while a decode runs on a model's
|
|
41
|
+
// custom stream risks racing live Metal command buffers. The only
|
|
42
|
+
// safe caller today is `@mlx-node/server`'s idle sweeper (fires after
|
|
43
|
+
// the in-flight request counter hits zero AND — for hot-load flows —
|
|
44
|
+
// outside any `withSuspendedDrains()` bracket). Admin / cron code that
|
|
45
|
+
// reaches for a manual drain should deep-import from `@mlx-node/core`
|
|
46
|
+
// directly and read the `@internal` caveat there.
|
|
47
|
+
export { memoryStats } from '@mlx-node/core';
|
|
20
48
|
// Internal: exported for testing the callback-to-AsyncGenerator bridge
|
|
21
|
-
// Not part of the public API — may change without notice
|
|
22
|
-
|
|
49
|
+
// Not part of the public API — may change without notice.
|
|
50
|
+
// `_runChatStream` is the generic adapter used by every model wrapper
|
|
51
|
+
// (and the VLM package's QianfanOCR wrapper) to turn a callback-based
|
|
52
|
+
// native stream into an `AsyncGenerator<ChatStreamEvent>`.
|
|
53
|
+
// `makeStreamingModel` is the factory that builds each family's wrapper
|
|
54
|
+
// subclass from its native class; the VLM package reuses it to build
|
|
55
|
+
// `QianfanOCRModel`.
|
|
56
|
+
export { _runChatStream, makeStreamingModel } from './stream.js';
|
|
57
|
+
// Cross-model chat session wrapper (see chat-session.ts for design notes).
|
|
58
|
+
// `SessionCapableModel` is the structural interface matched by every
|
|
59
|
+
// generative model wrapper and used as the upper-bound for
|
|
60
|
+
// `ChatSession<M>`; exported so the VLM wrapper can pin a compile-time
|
|
61
|
+
// conformance assertion.
|
|
62
|
+
export { ChatSession, ContextCapacityError, isContextCapacityError } from './chat-session.js';
|
|
23
63
|
// Model utilities (TypeScript-only)
|
|
24
64
|
export { QWEN3_CONFIGS, getQwen3Config, } from './models/qwen3-configs.js';
|
|
25
65
|
// Model loading
|
|
26
|
-
export { loadModel, detectModelType } from './models/model-loader.js';
|
|
66
|
+
export { loadModel, loadSession, detectModelType, } from './models/model-loader.js';
|
|
67
|
+
export { AGENT_PAGED_MODEL_TYPES, PagedConfigOverrideManager, QWEN35_PAGED_MODEL_TYPES, } from './models/paged-config-override.js';
|
|
27
68
|
export { QWEN35_CONFIGS, getQwen35Config } from './models/qwen3_5-configs.js';
|
|
28
69
|
// Tool calling utilities
|
|
29
70
|
export * from './tools/index.js';
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Union of all model classes that can be used with training engines.
|
|
4
|
-
* Uses the native (core) types so trainers can pass instances directly
|
|
5
|
-
* to Rust engine factory methods without type conflicts.
|
|
6
|
-
*/
|
|
7
|
-
export type TrainableModel = Qwen3Model | Qwen35Model | Qwen35MoeModel;
|
|
1
|
+
/** Compatibility type barrel; model unions are derived from the loader registry. */
|
|
2
|
+
export type { LoadableModel, TrainableModel } from './models/model-loader.js';
|
|
8
3
|
//# sourceMappingURL=interfaces.d.ts.map
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lfm2-configs.d.ts","sourceRoot":"","sources":["../../src/models/lfm2-configs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,YAAY,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAmGrD,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAMtD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const LFM2_CONFIGS = {
|
|
2
|
+
'lfm2.5-8b-a1b': {
|
|
3
|
+
vocabSize: 128000,
|
|
4
|
+
hiddenSize: 2048,
|
|
5
|
+
numHiddenLayers: 24,
|
|
6
|
+
numAttentionHeads: 32,
|
|
7
|
+
numKeyValueHeads: 8,
|
|
8
|
+
maxPositionEmbeddings: 128000,
|
|
9
|
+
normEps: 1e-5,
|
|
10
|
+
convBias: false,
|
|
11
|
+
convLCache: 3,
|
|
12
|
+
// block* fields are unused for MoE checkpoints (MoE dense layers use
|
|
13
|
+
// intermediateSize directly; MoE sparse layers use moeIntermediateSize).
|
|
14
|
+
// Required by the NAPI-derived Lfm2Config interface; set to 0 / defaults.
|
|
15
|
+
blockDim: 0,
|
|
16
|
+
blockFfDim: 0,
|
|
17
|
+
blockMultipleOf: 256,
|
|
18
|
+
blockFfnDimMultiplier: 1.0,
|
|
19
|
+
blockAutoAdjustFfDim: false,
|
|
20
|
+
ropeTheta: 5000000.0,
|
|
21
|
+
layerTypes: [
|
|
22
|
+
'conv',
|
|
23
|
+
'conv',
|
|
24
|
+
'full_attention',
|
|
25
|
+
'conv',
|
|
26
|
+
'conv',
|
|
27
|
+
'conv',
|
|
28
|
+
'full_attention',
|
|
29
|
+
'conv',
|
|
30
|
+
'conv',
|
|
31
|
+
'conv',
|
|
32
|
+
'full_attention',
|
|
33
|
+
'conv',
|
|
34
|
+
'conv',
|
|
35
|
+
'conv',
|
|
36
|
+
'full_attention',
|
|
37
|
+
'conv',
|
|
38
|
+
'conv',
|
|
39
|
+
'conv',
|
|
40
|
+
'full_attention',
|
|
41
|
+
'conv',
|
|
42
|
+
'conv',
|
|
43
|
+
'full_attention',
|
|
44
|
+
'conv',
|
|
45
|
+
'conv',
|
|
46
|
+
],
|
|
47
|
+
tieEmbedding: true,
|
|
48
|
+
eosTokenId: 124900,
|
|
49
|
+
bosTokenId: 124894,
|
|
50
|
+
padTokenId: 124893,
|
|
51
|
+
intermediateSize: 7168,
|
|
52
|
+
moeIntermediateSize: 1792,
|
|
53
|
+
numExperts: 32,
|
|
54
|
+
numExpertsPerTok: 4,
|
|
55
|
+
numDenseLayers: 2,
|
|
56
|
+
normTopkProb: true,
|
|
57
|
+
useExpertBias: true,
|
|
58
|
+
},
|
|
59
|
+
'lfm2.5-1.2b-thinking': {
|
|
60
|
+
vocabSize: 65536,
|
|
61
|
+
hiddenSize: 2048,
|
|
62
|
+
numHiddenLayers: 16,
|
|
63
|
+
numAttentionHeads: 32,
|
|
64
|
+
numKeyValueHeads: 8,
|
|
65
|
+
maxPositionEmbeddings: 128000,
|
|
66
|
+
normEps: 1e-5,
|
|
67
|
+
convBias: false,
|
|
68
|
+
convLCache: 3,
|
|
69
|
+
blockDim: 2048,
|
|
70
|
+
blockFfDim: 12288,
|
|
71
|
+
blockMultipleOf: 256,
|
|
72
|
+
blockFfnDimMultiplier: 1.0,
|
|
73
|
+
blockAutoAdjustFfDim: true,
|
|
74
|
+
ropeTheta: 1000000.0,
|
|
75
|
+
layerTypes: [
|
|
76
|
+
'conv',
|
|
77
|
+
'conv',
|
|
78
|
+
'full_attention',
|
|
79
|
+
'conv',
|
|
80
|
+
'conv',
|
|
81
|
+
'full_attention',
|
|
82
|
+
'conv',
|
|
83
|
+
'conv',
|
|
84
|
+
'full_attention',
|
|
85
|
+
'conv',
|
|
86
|
+
'full_attention',
|
|
87
|
+
'conv',
|
|
88
|
+
'full_attention',
|
|
89
|
+
'conv',
|
|
90
|
+
'full_attention',
|
|
91
|
+
'conv',
|
|
92
|
+
],
|
|
93
|
+
tieEmbedding: true,
|
|
94
|
+
eosTokenId: 7,
|
|
95
|
+
bosTokenId: 1,
|
|
96
|
+
padTokenId: 0,
|
|
97
|
+
normTopkProb: true,
|
|
98
|
+
useExpertBias: true,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
export function getLfm2Config(name) {
|
|
102
|
+
const config = LFM2_CONFIGS[name];
|
|
103
|
+
if (!config) {
|
|
104
|
+
throw new Error(`Unknown LFM2 config: ${name}. Available: ${Object.keys(LFM2_CONFIGS).join(', ')}`);
|
|
105
|
+
}
|
|
106
|
+
return config;
|
|
107
|
+
}
|
|
@@ -3,11 +3,201 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Handles loading pretrained weights from MLX format or converting from HuggingFace.
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import { Gemma4Model as NativeGemma4Model, HarrierModel, Lfm2Model as NativeLfm2Model, QianfanOCRModel, Qwen3Model as NativeQwen3Model, Qwen35Model as NativeQwen35Model, Qwen35MoeModel as NativeQwen35MoeModel } from '@mlx-node/core';
|
|
7
|
+
import { ChatSession, type SessionCapableModel } from '../chat-session.js';
|
|
8
|
+
/** Optional settings for {@link loadModel} / {@link loadSession}. */
|
|
9
|
+
export interface LoadModelOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Gemma4 only: directory of an external draft checkpoint (config.json +
|
|
12
|
+
* model.safetensors) loaded alongside the target model for speculative
|
|
13
|
+
* decoding (forwarded as `Gemma4LoadOptions.draftModelPath`). Accepts
|
|
14
|
+
* either a DSpark draft or a Google gemma-4 assistant draft
|
|
15
|
+
* (`google/gemma-4-*-it-assistant`); the variant is auto-detected from
|
|
16
|
+
* the draft's config.json (`model_type` `gemma4_assistant` /
|
|
17
|
+
* `gemma4_unified_assistant` → assistant, `architectures` containing
|
|
18
|
+
* `Gemma4DSparkModel` → DSpark). When omitted, Gemma4 automatically loads
|
|
19
|
+
* an embedded draft from `<modelPath>/draft/` when present. Draft decoding
|
|
20
|
+
* runs on the flat KV-cache path, so the target checkpoint must not
|
|
21
|
+
* explicitly enable `use_block_paged_cache`. Setting this for any other
|
|
22
|
+
* model family is a hard error — no other loader accepts a draft model.
|
|
23
|
+
*/
|
|
24
|
+
draftModelPath?: string;
|
|
25
|
+
}
|
|
26
|
+
interface NormalizedModelConfig {
|
|
27
|
+
readonly usesDefaultModelType: boolean;
|
|
28
|
+
readonly rawModelType: string | undefined;
|
|
29
|
+
readonly rawModelTypeLabel: string;
|
|
30
|
+
readonly architectures: ReadonlySet<string>;
|
|
31
|
+
}
|
|
32
|
+
interface ModelConfigMatchContext extends NormalizedModelConfig {
|
|
33
|
+
readonly modelType: string | undefined;
|
|
34
|
+
}
|
|
8
35
|
/**
|
|
9
|
-
*
|
|
36
|
+
* Ordered source of truth for every supported model family. Each entry owns
|
|
37
|
+
* its canonical `ModelType`, raw config aliases / architecture probes, loader,
|
|
38
|
+
* and `ChatSession` eligibility:
|
|
39
|
+
*
|
|
40
|
+
* - `'trainable'` — GRPO/SFT-capable LM (Qwen3 family); chat-capable.
|
|
41
|
+
* - `'loadable'` — chat-capable LM with no trainer engine (Gemma4, LFM2).
|
|
42
|
+
* - `'embedding'` — no chat surface (Harrier); rejected by `loadSession`.
|
|
43
|
+
* - `'vlm'` — VLM whose AsyncGenerator wrapper lives in
|
|
44
|
+
* `@mlx-node/vlm` (importing it here would create a
|
|
45
|
+
* circular package dependency), so `loadSession`
|
|
46
|
+
* rejects it and routes callers to `@mlx-node/vlm`.
|
|
47
|
+
*
|
|
48
|
+
* A base family is selected from an explicit alias or the single declarative
|
|
49
|
+
* nullish-model_type default, then architecture probes refine it in declaration
|
|
50
|
+
* order. Gemma's unified architecture is authoritative (matching the native
|
|
51
|
+
* loader); Harrier refines a Qwen3 base. Adding a family means adding one
|
|
52
|
+
* descriptor here, without a second normalization or dispatch branch.
|
|
53
|
+
*/
|
|
54
|
+
declare const MODEL_FAMILY_REGISTRY: readonly [{
|
|
55
|
+
readonly modelType: 'gemma4';
|
|
56
|
+
readonly kind: 'loadable';
|
|
57
|
+
readonly match: {
|
|
58
|
+
readonly rawModelTypes: readonly ["gemma4", "gemma4_text", "gemma4_unified"];
|
|
59
|
+
readonly architectureProbe: ({ architectures }: ModelConfigMatchContext) => boolean;
|
|
60
|
+
};
|
|
61
|
+
readonly load: (modelPath: string, options?: LoadModelOptions) => Promise<import("../stream.js").StreamingInstance<typeof NativeGemma4Model, {
|
|
62
|
+
readonly recordModelPath: true;
|
|
63
|
+
}>>;
|
|
64
|
+
readonly nativeModelClass: typeof NativeGemma4Model;
|
|
65
|
+
readonly acceptsDraftModel: true;
|
|
66
|
+
}, {
|
|
67
|
+
readonly modelType: 'harrier';
|
|
68
|
+
readonly kind: 'embedding';
|
|
69
|
+
readonly match: {
|
|
70
|
+
readonly rawModelTypes: readonly ["harrier"];
|
|
71
|
+
readonly architectureProbe: ({ modelType, architectures }: ModelConfigMatchContext) => boolean;
|
|
72
|
+
};
|
|
73
|
+
readonly load: (modelPath: string) => Promise<HarrierModel>;
|
|
74
|
+
readonly nativeModelClass: typeof HarrierModel;
|
|
75
|
+
}, {
|
|
76
|
+
readonly modelType: 'qwen3';
|
|
77
|
+
readonly kind: 'trainable';
|
|
78
|
+
readonly match: {
|
|
79
|
+
readonly rawModelTypes: readonly ["qwen3"];
|
|
80
|
+
};
|
|
81
|
+
readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeQwen3Model, {
|
|
82
|
+
readonly recordModelPath: true;
|
|
83
|
+
readonly applyTemplate: false;
|
|
84
|
+
}>>;
|
|
85
|
+
readonly nativeModelClass: typeof NativeQwen3Model;
|
|
86
|
+
readonly defaultForNullishModelType: true;
|
|
87
|
+
}, {
|
|
88
|
+
readonly modelType: 'qwen3_5';
|
|
89
|
+
readonly kind: 'trainable';
|
|
90
|
+
readonly match: {
|
|
91
|
+
readonly rawModelTypes: readonly ["qwen3_5"];
|
|
92
|
+
};
|
|
93
|
+
readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeQwen35Model, {
|
|
94
|
+
readonly recordModelPath: true;
|
|
95
|
+
}>>;
|
|
96
|
+
readonly nativeModelClass: typeof NativeQwen35Model;
|
|
97
|
+
}, {
|
|
98
|
+
readonly modelType: 'qwen3_5_moe';
|
|
99
|
+
readonly kind: 'trainable';
|
|
100
|
+
readonly match: {
|
|
101
|
+
readonly rawModelTypes: readonly ["qwen3_5_moe"];
|
|
102
|
+
};
|
|
103
|
+
readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeQwen35MoeModel, {
|
|
104
|
+
readonly recordModelPath: true;
|
|
105
|
+
}>>;
|
|
106
|
+
readonly nativeModelClass: typeof NativeQwen35MoeModel;
|
|
107
|
+
}, {
|
|
108
|
+
readonly modelType: 'lfm2';
|
|
109
|
+
readonly kind: 'loadable';
|
|
110
|
+
readonly match: {
|
|
111
|
+
readonly rawModelTypes: readonly ["lfm2"];
|
|
112
|
+
};
|
|
113
|
+
readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeLfm2Model, {
|
|
114
|
+
readonly recordModelPath: true;
|
|
115
|
+
}>>;
|
|
116
|
+
readonly nativeModelClass: typeof NativeLfm2Model;
|
|
117
|
+
}, {
|
|
118
|
+
readonly modelType: 'lfm2_moe';
|
|
119
|
+
readonly kind: 'loadable';
|
|
120
|
+
readonly match: {
|
|
121
|
+
readonly rawModelTypes: readonly ["lfm2_moe"];
|
|
122
|
+
};
|
|
123
|
+
readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeLfm2Model, {
|
|
124
|
+
readonly recordModelPath: true;
|
|
125
|
+
}>>;
|
|
126
|
+
readonly nativeModelClass: typeof NativeLfm2Model;
|
|
127
|
+
}, {
|
|
128
|
+
readonly modelType: 'internvl_chat';
|
|
129
|
+
readonly kind: 'vlm';
|
|
130
|
+
readonly match: {
|
|
131
|
+
readonly rawModelTypes: readonly ["internvl_chat"];
|
|
132
|
+
};
|
|
133
|
+
readonly load: (modelPath: string) => Promise<QianfanOCRModel>;
|
|
134
|
+
readonly nativeModelClass: typeof QianfanOCRModel;
|
|
135
|
+
}, {
|
|
136
|
+
readonly modelType: 'qianfan-ocr';
|
|
137
|
+
readonly kind: 'vlm';
|
|
138
|
+
readonly match: {
|
|
139
|
+
readonly rawModelTypes: readonly ["qianfan-ocr"];
|
|
140
|
+
};
|
|
141
|
+
readonly load: (modelPath: string) => Promise<QianfanOCRModel>;
|
|
142
|
+
readonly nativeModelClass: typeof QianfanOCRModel;
|
|
143
|
+
}];
|
|
144
|
+
export type ModelType = (typeof MODEL_FAMILY_REGISTRY)[number]['modelType'];
|
|
145
|
+
type RegisteredModelFamily = (typeof MODEL_FAMILY_REGISTRY)[number];
|
|
146
|
+
type RegisteredTrainableFamily = Extract<RegisteredModelFamily, {
|
|
147
|
+
readonly kind: 'trainable';
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Union of the native `@mlx-node/core` model classes across every registered
|
|
151
|
+
* family — the public contract of {@link loadModel}. At runtime the chat
|
|
152
|
+
* families resolve to streaming-wrapper subclasses of these classes
|
|
153
|
+
* (AsyncGenerator `chatStream*` overrides), but the public type names the
|
|
154
|
+
* native classes so downstream code can pass instances directly to Rust
|
|
155
|
+
* engine factory methods without type conflicts.
|
|
156
|
+
*/
|
|
157
|
+
export type LoadableModel = InstanceType<RegisteredModelFamily['nativeModelClass']>;
|
|
158
|
+
/**
|
|
159
|
+
* Union accepted by trainer APIs: registered wrapper results plus their native
|
|
160
|
+
* FFI instances. Both sides derive from the same trainable registry rows.
|
|
161
|
+
*/
|
|
162
|
+
export type TrainableModel = Awaited<ReturnType<RegisteredTrainableFamily['load']>> | InstanceType<RegisteredTrainableFamily['nativeModelClass']>;
|
|
163
|
+
/**
|
|
164
|
+
* Load a model from disk, auto-detecting architecture from config.json.
|
|
165
|
+
*
|
|
166
|
+
* Supports both language models (Qwen3, Qwen3.5) and vision-language models
|
|
167
|
+
* (Qianfan-OCR / InternVL). Use `instanceof` to narrow the returned type.
|
|
168
|
+
*
|
|
169
|
+
* `options.draftModelPath` attaches an external draft checkpoint (DSpark or
|
|
170
|
+
* Google gemma-4 assistant, auto-detected from the draft's config.json) for
|
|
171
|
+
* speculative decoding — gemma4 only; any other detected family rejects it.
|
|
172
|
+
* Without the option, Gemma4 loads `<modelPath>/draft/` automatically when
|
|
173
|
+
* that embedded checkpoint is present.
|
|
174
|
+
*/
|
|
175
|
+
export declare function loadModel(modelPath: string, options?: LoadModelOptions): Promise<LoadableModel>;
|
|
176
|
+
/**
|
|
177
|
+
* Load a model and wrap it in a {@link ChatSession} for multi-turn chat.
|
|
178
|
+
*
|
|
179
|
+
* Convenience around `loadModel()` + `new ChatSession(model)` for the
|
|
180
|
+
* common case where a caller just wants an ergonomic session handle.
|
|
181
|
+
*
|
|
182
|
+
* Rejects models that cannot be driven by a `ChatSession`:
|
|
183
|
+
* - Embedding models (`HarrierModel`) have no chat surface.
|
|
184
|
+
* - The native `QianfanOCRModel` exposes callback-based streaming
|
|
185
|
+
* methods that do not structurally satisfy `SessionCapableModel`'s
|
|
186
|
+
* `AsyncGenerator` overloads. The VLM AsyncGenerator wrapper lives
|
|
187
|
+
* in `@mlx-node/vlm` (importing it here would create a circular
|
|
188
|
+
* package dependency), so callers who want a Qianfan-OCR session
|
|
189
|
+
* must import `QianfanOCRModel` from `@mlx-node/vlm` and construct
|
|
190
|
+
* `new ChatSession(model)` directly.
|
|
191
|
+
*
|
|
192
|
+
* `options.draftModelPath` attaches an external draft checkpoint (DSpark or
|
|
193
|
+
* Google gemma-4 assistant, auto-detected from the draft's config.json) for
|
|
194
|
+
* speculative decoding — gemma4 only; any other detected family rejects it.
|
|
195
|
+
* Without the option, Gemma4 loads `<modelPath>/draft/` automatically when
|
|
196
|
+
* that embedded checkpoint is present.
|
|
197
|
+
* The resulting session auto-enables the speculative path (the model
|
|
198
|
+
* reports `hasMtpWeights()`); pass `enableMtp: false` per call to opt out.
|
|
10
199
|
*/
|
|
11
|
-
export declare function
|
|
200
|
+
export declare function loadSession(modelPath: string, options?: LoadModelOptions): Promise<ChatSession<SessionCapableModel>>;
|
|
12
201
|
export declare function detectModelType(modelPath: string): Promise<ModelType>;
|
|
202
|
+
export {};
|
|
13
203
|
//# sourceMappingURL=model-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../../src/models/model-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../../src/models/model-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,YAAY,EACZ,SAAS,IAAI,eAAe,EAC5B,eAAe,EACf,UAAU,IAAI,gBAAgB,EAC9B,WAAW,IAAI,iBAAiB,EAChC,cAAc,IAAI,oBAAoB,EACvC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG3E,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAID,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,UAAU,uBAAwB,SAAQ,qBAAqB;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAgCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,qBAAqB;wBAEZ,QAAQ;mBACb,UAAU;;;;;+BAKE,MAAM,YAAY,gBAAgB;;;;;;wBASzC,SAAS;mBACd,WAAW;;;;;+BAMC,MAAM;;;wBAIb,OAAO;mBACZ,WAAW;;iBACR,aAAa;;+BACJ,MAAM;;;;;;;wBAKb,SAAS;mBACd,WAAW;;iBACR,aAAa;;+BACJ,MAAM;;;;;wBAIb,aAAa;mBAClB,WAAW;;iBACR,aAAa;;+BACJ,MAAM;;;;;wBAIb,MAAM;mBACX,UAAU;;iBACP,aAAa;;+BACJ,MAAM;;;;;wBAIb,UAAU;mBACf,UAAU;;iBACP,aAAa;;+BACJ,MAAM;;;;;wBAIb,eAAe;mBACpB,KAAK;;iBACF,aAAa;;+BACJ,MAAM;;;wBAIb,aAAa;mBAClB,KAAK;;iBACF,aAAa;;+BACJ,MAAM;;EAGyB,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC;AAE5E,KAAK,qBAAqB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACpE,KAAK,yBAAyB,GAAG,OAAO,CAAC,qBAAqB,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AAEhG;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAEpF;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB,OAAO,CAAC,UAAU,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,GACtD,YAAY,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAsIhE;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAGrG;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAa3C;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB3E"}
|