Skip to content

Commit d849b0a

Browse files
committed
refactor(constants): rename BackendCell default -> base; fast-sam size-first paths
`MODEL_REGISTRY` accessors default to the quantized variant when one is published, so the non-quantized slot is no longer the runtime default. Rename the `BackendCell.default` key to `base` so the field name matches what it actually represents (the unquantized base variant) and stops fighting the new runtime default. `PlatformDefaults.default` is unrelated (platform-fallback backend) and is unchanged. Also point FastSAM URLs at the size-first HF layout: <size>/<backend>/fast_sam_<size>_<backend>_<precision>.pte matching the yolo26-seg / lfm-2.5 convention.
1 parent d0982df commit d849b0a

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

packages/react-native-executorch/src/constants/modelRegistry.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Accessor<
3737
> = C & ((opts?: ModelOpts<B>) => C);
3838

3939
type BackendCell = {
40-
default?: { modelName: string };
40+
base?: { modelName: string };
4141
quant?: { modelName: string };
4242
};
4343
type AnyVariantMap = Partial<Record<Backend, BackendCell>>;
@@ -48,7 +48,7 @@ type PlatformDefaults<B extends Backend> = {
4848
default?: B;
4949
};
5050

51-
type CellConfig<T> = T extends { default?: infer D; quant?: infer Q }
51+
type CellConfig<T> = T extends { base?: infer D; quant?: infer Q }
5252
? NonNullable<D> | NonNullable<Q>
5353
: never;
5454
type ConfigOf<V> = Extract<
@@ -86,8 +86,8 @@ function resolveBackend(
8686
function resolveCell(cell: BackendCell, quant: boolean): { modelName: string } {
8787
// Fall back to the other slot when the requested precision is missing,
8888
// so single-precision backends still work either way.
89-
const primary = quant ? cell.quant : cell.default;
90-
const fallback = quant ? cell.default : cell.quant;
89+
const primary = quant ? cell.quant : cell.base;
90+
const fallback = quant ? cell.base : cell.quant;
9191
const result = primary ?? fallback;
9292
if (!result) {
9393
throw new Error('Model variant cell has no config.');
@@ -126,15 +126,15 @@ function variant<const V extends AnyVariantMap>(
126126

127127
// Single-config accessor (xnnpack-only, no quantized variant).
128128
function base<C extends { modelName: string }>(c: C) {
129-
return variant({ xnnpack: { default: c } });
129+
return variant({ xnnpack: { base: c } });
130130
}
131131

132-
// xnnpack-only accessor with a `default` / `quant` pair.
132+
// xnnpack-only accessor with a `base` / `quant` pair.
133133
function pair<D extends { modelName: string }, Q extends { modelName: string }>(
134-
defaultC: D,
134+
baseC: D,
135135
quantC: Q
136136
) {
137-
return variant({ xnnpack: { default: defaultC, quant: quantC } });
137+
return variant({ xnnpack: { base: baseC, quant: quantC } });
138138
}
139139

140140
// ─────────────────────────────────────────────────────────────────────────────
@@ -148,7 +148,7 @@ function pair<D extends { modelName: string }, Q extends { modelName: string }>(
148148

149149
const EFFICIENTNET_V2_S_VARIANTS = {
150150
xnnpack: {
151-
default: {
151+
base: {
152152
modelName: 'efficientnet-v2-s' as const,
153153
modelSource: `${URL_PREFIX}-efficientnet-v2-s/${VERSION_TAG}/xnnpack/efficientnet_v2_s_xnnpack_fp32.pte`,
154154
},
@@ -158,7 +158,7 @@ const EFFICIENTNET_V2_S_VARIANTS = {
158158
},
159159
},
160160
coreml: {
161-
default: {
161+
base: {
162162
modelName: 'efficientnet-v2-s' as const,
163163
modelSource: `${URL_PREFIX}-efficientnet-v2-s/${VERSION_TAG}/coreml/efficientnet_v2_s_coreml_fp32.pte`,
164164
},
@@ -171,13 +171,13 @@ const EFFICIENTNET_V2_S_VARIANTS = {
171171

172172
const SSDLITE_320_MOBILENET_V3_LARGE_VARIANTS = {
173173
xnnpack: {
174-
default: {
174+
base: {
175175
modelName: 'ssdlite-320-mobilenet-v3-large' as const,
176176
modelSource: `${URL_PREFIX}-ssdlite320-mobilenet-v3-large/${VERSION_TAG}/xnnpack/ssdlite320_mobilenet_v3_large_xnnpack_fp32.pte`,
177177
},
178178
},
179179
coreml: {
180-
default: {
180+
base: {
181181
modelName: 'ssdlite-320-mobilenet-v3-large' as const,
182182
modelSource: `${URL_PREFIX}-ssdlite320-mobilenet-v3-large/${VERSION_TAG}/coreml/ssdlite320_mobilenet_v3_large_coreml_fp16.pte`,
183183
},
@@ -186,13 +186,13 @@ const SSDLITE_320_MOBILENET_V3_LARGE_VARIANTS = {
186186

187187
const RF_DETR_NANO_VARIANTS = {
188188
xnnpack: {
189-
default: {
189+
base: {
190190
modelName: 'rf-detr-nano' as const,
191191
modelSource: `${URL_PREFIX}-rfdetr-nano-detector/${VERSION_TAG}/xnnpack/rfdetr_nano_xnnpack_fp32.pte`,
192192
},
193193
},
194194
coreml: {
195-
default: {
195+
base: {
196196
modelName: 'rf-detr-nano' as const,
197197
modelSource: `${URL_PREFIX}-rfdetr-nano-detector/${VERSION_TAG}/coreml/rfdetr_nano_coreml_int8.pte`,
198198
},
@@ -201,13 +201,13 @@ const RF_DETR_NANO_VARIANTS = {
201201

202202
const RF_DETR_NANO_SEG_VARIANTS = {
203203
xnnpack: {
204-
default: {
204+
base: {
205205
modelName: 'rfdetr-nano-seg' as const,
206206
modelSource: `${URL_PREFIX}-rfdetr-nano-segmentation/${VERSION_TAG}/xnnpack/rfdetr_nano_xnnpack_fp32.pte`,
207207
},
208208
},
209209
coreml: {
210-
default: {
210+
base: {
211211
modelName: 'rfdetr-nano-seg' as const,
212212
modelSource: `${URL_PREFIX}-rfdetr-nano-segmentation/${VERSION_TAG}/coreml/rfdetr_nano_coreml_int8.pte`,
213213
},
@@ -216,30 +216,30 @@ const RF_DETR_NANO_SEG_VARIANTS = {
216216

217217
const FASTSAM_S_VARIANTS = {
218218
xnnpack: {
219-
default: {
219+
base: {
220220
modelName: 'fastsam-s' as const,
221-
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/xnnpack/fast_sam_s_xnnpack_fp32.pte`,
221+
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/s/xnnpack/fast_sam_s_xnnpack_fp32.pte`,
222222
},
223223
},
224224
coreml: {
225-
default: {
225+
base: {
226226
modelName: 'fastsam-s' as const,
227-
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/coreml/fast_sam_s_coreml_fp16.pte`,
227+
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/s/coreml/fast_sam_s_coreml_fp16.pte`,
228228
},
229229
},
230230
};
231231

232232
const FASTSAM_X_VARIANTS = {
233233
xnnpack: {
234-
default: {
234+
base: {
235235
modelName: 'fastsam-x' as const,
236-
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/xnnpack/fast_sam_x_xnnpack_fp32.pte`,
236+
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/x/xnnpack/fast_sam_x_xnnpack_fp32.pte`,
237237
},
238238
},
239239
coreml: {
240-
default: {
240+
base: {
241241
modelName: 'fastsam-x' as const,
242-
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/coreml/fast_sam_x_coreml_fp16.pte`,
242+
modelSource: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/x/coreml/fast_sam_x_coreml_fp16.pte`,
243243
},
244244
},
245245
};
@@ -250,7 +250,7 @@ function styleTransferVariants<
250250
>(display: Display, slug: Slug) {
251251
return {
252252
xnnpack: {
253-
default: {
253+
base: {
254254
modelName: `style-transfer-${display}`,
255255
modelSource: `${URL_PREFIX}-style-transfer-${display}/${VERSION_TAG}/xnnpack/style_transfer_${slug}_xnnpack_fp32.pte`,
256256
} as {
@@ -266,7 +266,7 @@ function styleTransferVariants<
266266
},
267267
},
268268
coreml: {
269-
default: {
269+
base: {
270270
modelName: `style-transfer-${display}`,
271271
modelSource: `${URL_PREFIX}-style-transfer-${display}/${VERSION_TAG}/coreml/style_transfer_${slug}_coreml_fp32.pte`,
272272
} as {
@@ -299,14 +299,14 @@ const DISTILUSE_TOKENIZER = `${URL_PREFIX}-distiluse-base-multilingual-cased-v2/
299299

300300
const DISTILUSE_BASE_MULTILINGUAL_CASED_V2_VARIANTS = {
301301
xnnpack: {
302-
default: {
302+
base: {
303303
modelName: 'distiluse-base-multilingual-cased-v2-8da4w' as const,
304304
modelSource: `${URL_PREFIX}-distiluse-base-multilingual-cased-v2/${VERSION_TAG}/xnnpack/distiluse_base_multilingual_cased_v2_xnnpack_8da4w.pte`,
305305
tokenizerSource: DISTILUSE_TOKENIZER,
306306
},
307307
},
308308
coreml: {
309-
default: {
309+
base: {
310310
modelName: 'distiluse-base-multilingual-cased-v2-coreml' as const,
311311
modelSource: `${URL_PREFIX}-distiluse-base-multilingual-cased-v2/${VERSION_TAG}/coreml/distiluse_base_multilingual_cased_v2_coreml_fp32.pte`,
312312
tokenizerSource: DISTILUSE_TOKENIZER,

packages/react-native-executorch/src/constants/modelUrls.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,12 +1021,12 @@ export const SELFIE_SEGMENTATION = {
10211021
// FastSAM Instance Segmentation
10221022
const FASTSAM_S_SEG_MODEL =
10231023
Platform.OS === 'ios'
1024-
? `${URL_PREFIX}-fast-sam/${VERSION_TAG}/coreml/fast_sam_s_coreml_fp16.pte`
1025-
: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/xnnpack/fast_sam_s_xnnpack_fp32.pte`;
1024+
? `${URL_PREFIX}-fast-sam/${VERSION_TAG}/s/coreml/fast_sam_s_coreml_fp16.pte`
1025+
: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/s/xnnpack/fast_sam_s_xnnpack_fp32.pte`;
10261026
const FASTSAM_X_SEG_MODEL =
10271027
Platform.OS === 'ios'
1028-
? `${URL_PREFIX}-fast-sam/${VERSION_TAG}/coreml/fast_sam_x_coreml_fp16.pte`
1029-
: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/xnnpack/fast_sam_x_xnnpack_fp32.pte`;
1028+
? `${URL_PREFIX}-fast-sam/${VERSION_TAG}/x/coreml/fast_sam_x_coreml_fp16.pte`
1029+
: `${URL_PREFIX}-fast-sam/${VERSION_TAG}/x/xnnpack/fast_sam_x_xnnpack_fp32.pte`;
10301030

10311031
/**
10321032
* @category Models - Instance Segmentation

0 commit comments

Comments
 (0)