Skip to content

Commit 5e02fef

Browse files
committed
feat(constants): wire up backend selection in MODEL_REGISTRY accessors
Each accessor's `backend` parameter is now typed to exactly the backends the model ships with — passing an unsupported one is a compile-time error. `Platform.OS` still picks the default when `backend` is omitted. The per- backend (quant × backend) variant matrix lives in modelRegistry.ts so modelUrls.ts stays flat-per-model. Unifies DISTILUSE_BASE_MULTILINGUAL_CASED_V2 to one accessor with xnnpack + coreml; the _8DA4W and _COREML named constants stay as deprecated aliases.
1 parent a78b52a commit 5e02fef

3 files changed

Lines changed: 346 additions & 42 deletions

File tree

docs/docs/05-utilities/model-registry.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ const llmQuant = useLLM(MODEL_REGISTRY.LLM.LLAMA3_2_3B({ quant: true }));
3636
## Options
3737

3838
```typescript
39-
type ModelOpts = {
39+
type ModelOpts<B extends Backend = Backend> = {
4040
quant?: boolean; // Pick the quantized variant when true. Ignored when no quantized variant exists.
41-
backend?: 'xnnpack' | 'coreml' | 'vulkan' | 'qnn'; // Reserved; today the platform default applies.
41+
backend?: B; // Explicit backend; the set of allowed values is per-model.
4242
};
4343
```
4444

4545
- `quant: true` resolves to the quantized variant for models that publish one (e.g. `LLAMA3_2_3B` → SpinQuant, `EFFICIENTNET_V2_S` → int8). For models with a single variant, `quant` is accepted but has no effect.
46-
- `backend` is accepted in the signature for forward-compatibility. Today every accessor returns a config whose backend is selected at module-load time by `Platform.OS`. Explicit per-backend selection is planned for a future release.
46+
- `backend` selects an explicit backend. The accessor's call signature is typed to exactly the backends the model ships with, so requesting one the model doesn't publish is a compile-time error (e.g. `MODEL_REGISTRY.LLM.LLAMA3_2_3B({ backend: 'coreml' })` does not type-check — Llama 3.2 is xnnpack-only). When `backend` is omitted, the platform-default applies (typically CoreML on iOS and XNNPACK on Android for multi-backend models).
4747

4848
## Usage patterns
4949

@@ -70,6 +70,20 @@ const classifier = useClassification(
7070
);
7171
```
7272

73+
### Explicit backend
74+
75+
```typescript
76+
// Force XNNPACK on iOS (overrides the CoreML default).
77+
const detector = useObjectDetection({
78+
model: MODEL_REGISTRY.OBJECT_DETECTION.RF_DETR_NANO({ backend: 'xnnpack' }),
79+
});
80+
81+
// Combine `quant` and `backend`.
82+
const styled = useStyleTransfer(
83+
MODEL_REGISTRY.STYLE_TRANSFER.CANDY({ backend: 'coreml', quant: true })
84+
);
85+
```
86+
7387
### Inspecting a model's config
7488

7589
Accessors transparently expose the default config's fields, so you can read them without calling:

0 commit comments

Comments
 (0)