@mlx-node/lm 0.0.7 → 0.0.9

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/dist/index.d.ts CHANGED
@@ -12,30 +12,25 @@
12
12
  * const result = await model.generate([{ role: 'user', content: 'Hello!' }]);
13
13
  * ```
14
14
  */
15
- export { Qwen3Tokenizer } from '@mlx-node/core';
16
15
  export { Qwen3Model } from './stream.js';
17
- export { Gemma4Model, Gemma4Model as Gemma4_Model } from './stream.js';
18
- export type { Gemma4Config } from '@mlx-node/core';
16
+ export { Gemma4Model } from './stream.js';
19
17
  export { HarrierModel } from '@mlx-node/core';
20
- export type { HarrierConfig } from '@mlx-node/core';
21
- export { Qwen35Model, Qwen35Model as Qwen3_5Model } from './stream.js';
22
- export type { Qwen35Config, Qwen35GenerationConfig, Qwen35GenerationResult } from '@mlx-node/core';
18
+ export { Qwen35Model } from './stream.js';
19
+ export type { Qwen35Config, Qwen35ContextLimits } from '@mlx-node/core';
23
20
  export { Lfm2Model } from './stream.js';
24
- export type { Lfm2Config } from '@mlx-node/core';
25
21
  export { LFM2_CONFIGS, getLfm2Config } from './models/lfm2-configs.js';
26
- export { Qwen35MoeModel, Qwen35MoeModel as Qwen3_5MoeModel } from './stream.js';
27
- export type { Qwen35MoeConfig, Qwen35MoeGenerationConfig, Qwen35MoeGenerationResult } from '@mlx-node/core';
28
- export type { DType } from '@mlx-node/core';
29
- export type { SamplingConfig, BatchGenerationResult } from '@mlx-node/core';
22
+ export { Qwen35MoeModel } from './stream.js';
23
+ export type { Qwen35MoeConfig } from '@mlx-node/core';
24
+ export { memoryStats } from '@mlx-node/core';
30
25
  export type { ChatConfig, ChatResult, ChatMessage, ToolCallResult, PerformanceMetrics } from '@mlx-node/core';
31
26
  export type { ChatStreamDelta, ChatStreamFinal, ChatStreamEvent } from './stream.js';
32
- export type { ChatStreamChunk, ChatStreamHandle } from '@mlx-node/core';
33
- export { _runChatStream } from './stream.js';
34
- export { ChatSession } from './chat-session.js';
35
- export type { ChatSessionOptions, SendOptions, SessionCapableModel } from './chat-session.js';
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';
36
31
  export { type Qwen3Config, QWEN3_CONFIGS, type GenerationResult, type GenerationConfig, getQwen3Config, } from './models/qwen3-configs.js';
37
- export { loadModel, loadSession, detectModelType, type ModelType } from './models/model-loader.js';
38
- export type { TrainableModel, LoadableModel, EmbeddingModel } from './interfaces.js';
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';
39
34
  export { QWEN35_CONFIGS, getQwen35Config } from './models/qwen3_5-configs.js';
40
35
  export * from './tools/index.js';
41
36
  export { enableProfiling, disableProfiling } from './profiling.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,IAAI,YA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AkB,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,34 +13,58 @@
13
13
  * ```
14
14
  */
15
15
  // Model classes (for inference)
16
- export { Qwen3Tokenizer } from '@mlx-node/core';
17
16
  export { Qwen3Model } from './stream.js';
18
17
  // Gemma4 models
19
- export { Gemma4Model, Gemma4Model as Gemma4_Model } from './stream.js';
18
+ export { Gemma4Model } from './stream.js';
20
19
  // Embedding models
21
20
  export { HarrierModel } from '@mlx-node/core';
22
- export { Qwen35Model, Qwen35Model as Qwen3_5Model } from './stream.js';
21
+ export { Qwen35Model } from './stream.js';
23
22
  // LFM2 models
24
23
  export { Lfm2Model } from './stream.js';
25
24
  export { LFM2_CONFIGS, getLfm2Config } from './models/lfm2-configs.js';
26
25
  // MoE variant
27
- export { Qwen35MoeModel, Qwen35MoeModel as Qwen3_5MoeModel } from './stream.js';
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';
28
48
  // Internal: exported for testing the callback-to-AsyncGenerator bridge
29
49
  // Not part of the public API — may change without notice.
30
50
  // `_runChatStream` is the generic adapter used by every model wrapper
31
51
  // (and the VLM package's QianfanOCR wrapper) to turn a callback-based
32
52
  // native stream into an `AsyncGenerator<ChatStreamEvent>`.
33
- export { _runChatStream } from './stream.js';
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';
34
57
  // Cross-model chat session wrapper (see chat-session.ts for design notes).
35
58
  // `SessionCapableModel` is the structural interface matched by every
36
59
  // generative model wrapper and used as the upper-bound for
37
60
  // `ChatSession<M>`; exported so the VLM wrapper can pin a compile-time
38
61
  // conformance assertion.
39
- export { ChatSession } from './chat-session.js';
62
+ export { ChatSession, ContextCapacityError, isContextCapacityError } from './chat-session.js';
40
63
  // Model utilities (TypeScript-only)
41
64
  export { QWEN3_CONFIGS, getQwen3Config, } from './models/qwen3-configs.js';
42
65
  // Model loading
43
- export { loadModel, loadSession, 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';
44
68
  export { QWEN35_CONFIGS, getQwen35Config } from './models/qwen3_5-configs.js';
45
69
  // Tool calling utilities
46
70
  export * from './tools/index.js';
@@ -1,18 +1,3 @@
1
- import type { Gemma4Model, HarrierModel, Lfm2Model, Qwen3Model, Qwen35Model, Qwen35MoeModel, QianfanOCRModel } from '@mlx-node/core';
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;
8
- /**
9
- * Union of all embedding model classes.
10
- * These models encode text into fixed-size embedding vectors.
11
- */
12
- export type EmbeddingModel = HarrierModel;
13
- /**
14
- * Union of all model classes that loadModel can return.
15
- * Includes trainable models, inference-only models, and embedding models.
16
- */
17
- export type LoadableModel = TrainableModel | QianfanOCRModel | EmbeddingModel | Gemma4Model | Lfm2Model;
1
+ /** Compatibility type barrel; model unions are derived from the loader registry. */
2
+ export type { LoadableModel, TrainableModel } from './models/model-loader.js';
18
3
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,CAAC;AAEvE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,eAAe,GAAG,cAAc,GAAG,WAAW,GAAG,SAAS,CAAC"}
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"}
@@ -1 +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;CAwCrD,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAMtD"}
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"}
@@ -1,4 +1,61 @@
1
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
+ },
2
59
  'lfm2.5-1.2b-thinking': {
3
60
  vocabSize: 65536,
4
61
  hiddenSize: 2048,
@@ -37,6 +94,8 @@ export const LFM2_CONFIGS = {
37
94
  eosTokenId: 7,
38
95
  bosTokenId: 1,
39
96
  padTokenId: 0,
97
+ normTopkProb: true,
98
+ useExpertBias: true,
40
99
  },
41
100
  };
42
101
  export function getLfm2Config(name) {
@@ -3,16 +3,178 @@
3
3
  *
4
4
  * Handles loading pretrained weights from MLX format or converting from HuggingFace.
5
5
  */
6
+ import { Gemma4Model as NativeGemma4Model, HarrierModel, Lfm2Model as NativeLfm2Model, QianfanOCRModel, Qwen3Model as NativeQwen3Model, Qwen35Model as NativeQwen35Model, Qwen35MoeModel as NativeQwen35MoeModel } from '@mlx-node/core';
6
7
  import { ChatSession, type SessionCapableModel } from '../chat-session.js';
7
- import type { LoadableModel } from '../interfaces.js';
8
- export type ModelType = 'qwen3' | 'qwen3_5' | 'qwen3_5_moe' | 'internvl_chat' | 'qianfan-ocr' | 'harrier' | 'gemma4' | 'lfm2';
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
+ }
35
+ /**
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
+ readonly replayAssistantRawText: true;
116
+ }>>;
117
+ readonly nativeModelClass: typeof NativeLfm2Model;
118
+ }, {
119
+ readonly modelType: 'lfm2_moe';
120
+ readonly kind: 'loadable';
121
+ readonly match: {
122
+ readonly rawModelTypes: readonly ["lfm2_moe"];
123
+ };
124
+ readonly load: (modelPath: string) => Promise<import("../stream.js").StreamingInstance<typeof NativeLfm2Model, {
125
+ readonly recordModelPath: true;
126
+ readonly replayAssistantRawText: true;
127
+ }>>;
128
+ readonly nativeModelClass: typeof NativeLfm2Model;
129
+ }, {
130
+ readonly modelType: 'internvl_chat';
131
+ readonly kind: 'vlm';
132
+ readonly match: {
133
+ readonly rawModelTypes: readonly ["internvl_chat"];
134
+ };
135
+ readonly load: (modelPath: string) => Promise<QianfanOCRModel>;
136
+ readonly nativeModelClass: typeof QianfanOCRModel;
137
+ }, {
138
+ readonly modelType: 'qianfan-ocr';
139
+ readonly kind: 'vlm';
140
+ readonly match: {
141
+ readonly rawModelTypes: readonly ["qianfan-ocr"];
142
+ };
143
+ readonly load: (modelPath: string) => Promise<QianfanOCRModel>;
144
+ readonly nativeModelClass: typeof QianfanOCRModel;
145
+ }];
146
+ export type ModelType = (typeof MODEL_FAMILY_REGISTRY)[number]['modelType'];
147
+ type RegisteredModelFamily = (typeof MODEL_FAMILY_REGISTRY)[number];
148
+ type RegisteredTrainableFamily = Extract<RegisteredModelFamily, {
149
+ readonly kind: 'trainable';
150
+ }>;
151
+ /**
152
+ * Union of the native `@mlx-node/core` model classes across every registered
153
+ * family — the public contract of {@link loadModel}. At runtime the chat
154
+ * families resolve to streaming-wrapper subclasses of these classes
155
+ * (AsyncGenerator `chatStream*` overrides), but the public type names the
156
+ * native classes so downstream code can pass instances directly to Rust
157
+ * engine factory methods without type conflicts.
158
+ */
159
+ export type LoadableModel = InstanceType<RegisteredModelFamily['nativeModelClass']>;
160
+ /**
161
+ * Union accepted by trainer APIs: registered wrapper results plus their native
162
+ * FFI instances. Both sides derive from the same trainable registry rows.
163
+ */
164
+ export type TrainableModel = Awaited<ReturnType<RegisteredTrainableFamily['load']>> | InstanceType<RegisteredTrainableFamily['nativeModelClass']>;
9
165
  /**
10
166
  * Load a model from disk, auto-detecting architecture from config.json.
11
167
  *
12
168
  * Supports both language models (Qwen3, Qwen3.5) and vision-language models
13
169
  * (Qianfan-OCR / InternVL). Use `instanceof` to narrow the returned type.
170
+ *
171
+ * `options.draftModelPath` attaches an external draft checkpoint (DSpark or
172
+ * Google gemma-4 assistant, auto-detected from the draft's config.json) for
173
+ * speculative decoding — gemma4 only; any other detected family rejects it.
174
+ * Without the option, Gemma4 loads `<modelPath>/draft/` automatically when
175
+ * that embedded checkpoint is present.
14
176
  */
15
- export declare function loadModel(modelPath: string): Promise<LoadableModel>;
177
+ export declare function loadModel(modelPath: string, options?: LoadModelOptions): Promise<LoadableModel>;
16
178
  /**
17
179
  * Load a model and wrap it in a {@link ChatSession} for multi-turn chat.
18
180
  *
@@ -28,7 +190,16 @@ export declare function loadModel(modelPath: string): Promise<LoadableModel>;
28
190
  * package dependency), so callers who want a Qianfan-OCR session
29
191
  * must import `QianfanOCRModel` from `@mlx-node/vlm` and construct
30
192
  * `new ChatSession(model)` directly.
193
+ *
194
+ * `options.draftModelPath` attaches an external draft checkpoint (DSpark or
195
+ * Google gemma-4 assistant, auto-detected from the draft's config.json) for
196
+ * speculative decoding — gemma4 only; any other detected family rejects it.
197
+ * Without the option, Gemma4 loads `<modelPath>/draft/` automatically when
198
+ * that embedded checkpoint is present.
199
+ * The resulting session auto-enables the speculative path (the model
200
+ * reports `hasMtpWeights()`); pass `enableMtp: false` per call to opt out.
31
201
  */
32
- export declare function loadSession(modelPath: string): Promise<ChatSession<SessionCapableModel>>;
202
+ export declare function loadSession(modelPath: string, options?: LoadModelOptions): Promise<ChatSession<SessionCapableModel>>;
33
203
  export declare function detectModelType(modelPath: string): Promise<ModelType>;
204
+ export {};
34
205
  //# 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;AAOH,OAAO,EAAE,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAGtE,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,SAAS,GACT,aAAa,GACb,eAAe,GACf,aAAa,GACb,SAAS,GACT,QAAQ,GACR,MAAM,CAAC;AAaX;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAoBzE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAW9F;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAyB3E"}
1
+ {"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../../src/models/model-loader.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