From f311d92d5e723f677281d5cd72a815b2ca46f2a4 Mon Sep 17 00:00:00 2001 From: Bartosz Hanc Date: Fri, 21 Aug 2026 15:08:50 +0200 Subject: [PATCH 01/38] docs: enrich model registry JSDoc comments and document rnexecutorchJsi --- .../react-native-executorch/src/models.ts | 281 +++++++++++------- .../src/native/bridge.ts | 9 + packages/react-native-executorch/src/utils.ts | 4 +- 3 files changed, 178 insertions(+), 116 deletions(-) diff --git a/packages/react-native-executorch/src/models.ts b/packages/react-native-executorch/src/models.ts index b4db68689c..72ea6530f2 100644 --- a/packages/react-native-executorch/src/models.ts +++ b/packages/react-native-executorch/src/models.ts @@ -1333,9 +1333,9 @@ export const models = { classification: { /** * EfficientNetV2-S image classification model pre-trained on ImageNet-1k - * (1000 categories, see {@link IMAGENET1K_LABELS}). - * Compact and efficient architecture providing high accuracy for - * general-purpose image classification. + * (1000 categories, see {@link IMAGENET1K_LABELS}). Compact and efficient + * architecture providing high accuracy for general-purpose image + * classification. */ EFFICIENTNET_V2_S: { ...EFFICIENTNET_V2_S_XNNPACK_INT8, @@ -1361,8 +1361,8 @@ export const models = { COREML_FP16: STYLE_TRANSFER_CANDY_COREML_FP16, }, /** - * Fast neural style transfer model applying a classic tile mosaic - * artistic pattern. + * Fast neural style transfer model applying a classic tile mosaic artistic + * pattern. */ MOSAIC: { ...STYLE_TRANSFER_MOSAIC_XNNPACK_INT8, @@ -1371,8 +1371,8 @@ export const models = { COREML_FP16: STYLE_TRANSFER_MOSAIC_COREML_FP16, }, /** - * Fast neural style transfer model applying a painterly "Rain Princess" - * oil painting aesthetic. + * Fast neural style transfer model applying a painterly "Rain Princess" oil + * painting aesthetic. */ RAIN_PRINCESS: { ...STYLE_TRANSFER_RAIN_PRINCESS_XNNPACK_INT8, @@ -1393,14 +1393,14 @@ export const models = { }, /** - * Semantic segmentation models that classify each pixel into target object - * or background classes. + * Semantic segmentation models that classify each pixel into target object or + * background classes. */ semanticSegmentation: { /** * Lightweight portrait selfie segmentation model for real-time person vs - * background separation. Categorizes pixels into `background` and - * `person`. Ideal for background blur and replacement effects. + * background separation. Categorizes pixels into `background` and `person`. + * Ideal for background blur and replacement effects. */ SELFIE_SEGMENTATION: { ...SELFIE_SEGMENTATION_XNNPACK_FP32, @@ -1428,8 +1428,8 @@ export const models = { COREML_FP16: LRASPP_MOBILENET_V3_LARGE_COREML_FP16, }, /** - * DeepLabV3 semantic segmentation model with ResNet-50 backbone - * (21 classes, see {@link PASCAL_VOC_LABELS}). High-accuracy segmentation + * DeepLabV3 semantic segmentation model with ResNet-50 backbone (21 + * classes, see {@link PASCAL_VOC_LABELS}). High-accuracy segmentation * utilizing atrous spatial pyramid pooling. */ DEEPLAB_V3_RESNET50: { @@ -1439,8 +1439,8 @@ export const models = { COREML_FP16: DEEPLAB_V3_RESNET50_COREML_FP16, }, /** - * DeepLabV3 semantic segmentation model with ResNet-101 backbone - * (21 classes, see {@link PASCAL_VOC_LABELS}). High-capacity backbone for + * DeepLabV3 semantic segmentation model with ResNet-101 backbone (21 + * classes, see {@link PASCAL_VOC_LABELS}). High-capacity backbone for * maximum segmentation detail and boundary accuracy. */ DEEPLAB_V3_RESNET101: { @@ -1450,8 +1450,8 @@ export const models = { COREML_FP16: DEEPLAB_V3_RESNET101_COREML_FP16, }, /** - * DeepLabV3 semantic segmentation model with MobileNetV3-Large backbone - * (21 classes, see {@link PASCAL_VOC_LABELS}). Combines DeepLabV3 feature + * DeepLabV3 semantic segmentation model with MobileNetV3-Large backbone (21 + * classes, see {@link PASCAL_VOC_LABELS}). Combines DeepLabV3 feature * extraction quality with a lightweight mobile backbone. */ DEEPLAB_V3_MOBILENET_V3_LARGE: { @@ -1507,16 +1507,16 @@ export const models = { COREML_FP16: RFDETR_NANO_DETECTOR_COREML_FP16, }, /** - * Ultralytics YOLO26 real-time object detection models trained on COCO - * (80 classes, see {@link COCO_CLASSES_YOLO}). Available across multiple - * scale sizes (NANO, SMALL, MEDIUM, LARGE, XLARGE) and resolutions - * (384x384, 512x512, 640x640). + * Ultralytics YOLO26 real-time object detection models trained on COCO (80 + * classes, see {@link COCO_CLASSES_YOLO}). Available across multiple scale + * sizes (NANO, SMALL, MEDIUM, LARGE, XLARGE) and resolutions (384x384, + * 512x512, 640x640). */ YOLO26: { ...YOLO26_NANO_384_XNNPACK_FP32, /** - * Nano scale YOLO26 object detection model. High speed, - * ultra low latency. + * Nano scale YOLO26 object detection model. High speed, ultra low + * latency. */ NANO: { ...YOLO26_NANO_384_XNNPACK_FP32, @@ -1534,8 +1534,8 @@ export const models = { }, }, /** - * Small scale YOLO26 object detection model. Balanced - * latency and accuracy. + * Small scale YOLO26 object detection model. Balanced latency and + * accuracy. */ SMALL: { ...YOLO26_SMALL_384_XNNPACK_FP32, @@ -1553,8 +1553,8 @@ export const models = { }, }, /** - * Medium scale YOLO26 object detection model. Higher - * precision for complex scenes. + * Medium scale YOLO26 object detection model. Higher precision for + * complex scenes. */ MEDIUM: { ...YOLO26_MEDIUM_384_XNNPACK_FP32, @@ -1572,8 +1572,7 @@ export const models = { }, }, /** - * Large scale YOLO26 object detection model. High accuracy - * model variant. + * Large scale YOLO26 object detection model. High accuracy model variant. */ LARGE: { ...YOLO26_LARGE_384_XNNPACK_FP32, @@ -1591,8 +1590,8 @@ export const models = { }, }, /** - * Extra Large scale YOLO26 object detection model. - * Maximum detection performance. + * Extra Large scale YOLO26 object detection model. Maximum detection + * performance. */ XLARGE: { ...YOLO26_XLARGE_384_XNNPACK_FP32, @@ -1618,17 +1617,18 @@ export const models = { */ keypointDetection: { /** - * MediaPipe BlazeFace lightweight face detection and 6-point facial landmark - * locator (eyes, nose, mouth, ears, see {@link BLAZEFACE_LANDMARKS}). + * MediaPipe BlazeFace lightweight face detection and 6-point facial + * landmark locator (eyes, nose, mouth, ears, see + * {@link BLAZEFACE_LANDMARKS}). */ BLAZEFACE: { ...BLAZEFACE_XNNPACK_FP32, XNNPACK_FP32: BLAZEFACE_XNNPACK_FP32, }, /** - * YOLO26 human pose estimation model predicting 17 COCO body keypoints - * (see {@link COCO_LANDMARKS}). Available across 384x384, 512x512, and - * 640x640 resolutions. + * YOLO26 human pose estimation model predicting 17 COCO body keypoints (see + * {@link COCO_LANDMARKS}). Available across 384x384, 512x512, and 640x640 + * resolutions. */ YOLO26_POSE: { ...YOLO26_POSE_384_XNNPACK_FP32, @@ -1649,8 +1649,8 @@ export const models = { }, /** - * Instance segmentation models predicting both bounding boxes and fine-grained - * pixel masks per object instance. + * Instance segmentation models predicting both bounding boxes and + * fine-grained pixel masks per object instance. */ instanceSegmentation: { /** @@ -1660,8 +1660,7 @@ export const models = { */ FASTSAM: { /** - * FastSAM Small - lightweight instance segmenter for - * mobile. + * FastSAM Small - lightweight instance segmenter for mobile. */ S: { ...FASTSAM_S_XNNPACK_FP32, @@ -1678,9 +1677,9 @@ export const models = { }, }, /** - * RF-DETR (Roboflow Detection Transformer) Nano instance segmentation - * model predicting COCO class masks and bounding boxes - * (see {@link COCO_CLASSES}). + * RF-DETR (Roboflow Detection Transformer) Nano instance segmentation model + * predicting COCO class masks and bounding boxes (see + * {@link COCO_CLASSES}). */ RFDETR_NANO: { ...RFDETR_NANO_SEG_COREML_FP16, @@ -1696,8 +1695,8 @@ export const models = { YOLO26: { ...YOLO26_NANO_SEG_384_XNNPACK_FP32, /** - * Nano scale YOLO26 instance segmentation model. High - * speed. + * Nano scale YOLO26 instance segmentation model. High speed, ultra low + * latency mask generation. */ NANO: { ...YOLO26_NANO_SEG_384_XNNPACK_FP32, @@ -1705,28 +1704,40 @@ export const models = { SIZE_512: { XNNPACK_FP32: YOLO26_NANO_SEG_512_XNNPACK_FP32 }, SIZE_640: { XNNPACK_FP32: YOLO26_NANO_SEG_640_XNNPACK_FP32 }, }, - /** Small scale YOLO26 instance segmentation model. */ + /** + * Small scale YOLO26 instance segmentation model. Balanced latency and + * mask accuracy. + */ SMALL: { ...YOLO26_SMALL_SEG_384_XNNPACK_FP32, SIZE_384: { XNNPACK_FP32: YOLO26_SMALL_SEG_384_XNNPACK_FP32 }, SIZE_512: { XNNPACK_FP32: YOLO26_SMALL_SEG_512_XNNPACK_FP32 }, SIZE_640: { XNNPACK_FP32: YOLO26_SMALL_SEG_640_XNNPACK_FP32 }, }, - /** Medium scale YOLO26 instance segmentation model. */ + /** + * Medium scale YOLO26 instance segmentation model. Higher mask boundary + * precision for complex multi-object scenes. + */ MEDIUM: { ...YOLO26_MEDIUM_SEG_384_XNNPACK_FP32, SIZE_384: { XNNPACK_FP32: YOLO26_MEDIUM_SEG_384_XNNPACK_FP32 }, SIZE_512: { XNNPACK_FP32: YOLO26_MEDIUM_SEG_512_XNNPACK_FP32 }, SIZE_640: { XNNPACK_FP32: YOLO26_MEDIUM_SEG_640_XNNPACK_FP32 }, }, - /** Large scale YOLO26 instance segmentation model. */ + /** + * Large scale YOLO26 instance segmentation model. High accuracy instance + * segmentation variant for demanding visual pipelines. + */ LARGE: { ...YOLO26_LARGE_SEG_384_XNNPACK_FP32, SIZE_384: { XNNPACK_FP32: YOLO26_LARGE_SEG_384_XNNPACK_FP32 }, SIZE_512: { XNNPACK_FP32: YOLO26_LARGE_SEG_512_XNNPACK_FP32 }, SIZE_640: { XNNPACK_FP32: YOLO26_LARGE_SEG_640_XNNPACK_FP32 }, }, - /** Extra Large scale YOLO26 instance segmentation model. */ + /** + * Extra Large scale YOLO26 instance segmentation model. Maximum instance + * segmentation and mask delineation performance. + */ XLARGE: { ...YOLO26_XLARGE_SEG_384_XNNPACK_FP32, SIZE_384: { XNNPACK_FP32: YOLO26_XLARGE_SEG_384_XNNPACK_FP32 }, @@ -1763,8 +1774,8 @@ export const models = { */ WHISPER: { /** - * Multilingual Whisper Tiny model. Supporting 99+ - * languages. High speed speech recognition. + * Multilingual Whisper Tiny model. Supporting 99+ languages. High speed + * speech recognition. */ TINY: { ...WHISPER_TINY_XNNPACK_FP32, @@ -1774,8 +1785,8 @@ export const models = { MLX_INT8: WHISPER_TINY_MLX_INT8, }, /** - * Multilingual Whisper Base model. Higher accuracy across - * supported languages. + * Multilingual Whisper Base model. Higher accuracy across supported + * languages. */ BASE: { ...WHISPER_BASE_XNNPACK_FP32, @@ -1785,8 +1796,8 @@ export const models = { MLX_INT8: WHISPER_BASE_MLX_INT8, }, /** - * Multilingual Whisper Small model. Best accuracy for - * complex multi-language audio. + * Multilingual Whisper Small model. Best accuracy for complex + * multi-language audio. */ SMALL: { ...WHISPER_SMALL_XNNPACK_FP32, @@ -1797,8 +1808,7 @@ export const models = { /** English-only optimized Whisper models (`TINY`, `BASE`, `SMALL`). */ EN: { /** - * English-only Whisper Tiny model. Fast and compact for - * English STT. + * English-only Whisper Tiny model. Fast and compact for English STT. */ TINY: { ...WHISPER_TINY_EN_XNNPACK_FP32, @@ -1808,8 +1818,8 @@ export const models = { MLX_INT8: WHISPER_TINY_EN_MLX_INT8, }, /** - * English-only Whisper Base model. High accuracy - * English speech recognition. + * English-only Whisper Base model. High accuracy English speech + * recognition. */ BASE: { ...WHISPER_BASE_EN_XNNPACK_FP32, @@ -1819,8 +1829,8 @@ export const models = { MLX_INT8: WHISPER_BASE_EN_MLX_INT8, }, /** - * English-only Whisper Small model. Superior accuracy - * for English transcription. + * English-only Whisper Small model. Superior accuracy for English + * transcription. */ SMALL: { ...WHISPER_SMALL_EN_XNNPACK_FP32, @@ -1841,13 +1851,16 @@ export const models = { }, /** - * Generative Large Language Models (LLMs) for instruction following, - * chat, text generation, and reasoning. + * Generative Large Language Models (LLMs) for instruction following, chat, + * text generation, and reasoning. */ llm: { /** - * Liquid AI LFM 2.5 1.2B general-purpose text model. Excellent for complex - * on-device reasoning, instruction following, and fast multi-turn chat. + * Liquid AI LFM 2.5 1.2B general-purpose hybrid language model. Built on + * the Liquid Foundation Model architecture for low memory bandwidth usage, + * and high-throughput token generation. Delivers strong general-purpose + * reasoning, instruction following, and fast multi-turn conversational chat + * on mobile devices. */ LFM2_5_1_2B: { ...LFM2_5_1_2B_XNNPACK_8DA4W, @@ -1856,8 +1869,10 @@ export const models = { MLX_INT4: LFM2_5_1_2B_MLX_INT4, }, /** - * Liquid AI LFM 2.5 350M ultra-compact text model. Best for low-latency text - * completion, quick responses, and resource-constrained devices. + * Liquid AI LFM 2.5 350M ultra-compact hybrid language model. Optimized for + * minimal memory footprint and sub-second first-token response times. Ideal + * for lightweight text completion, fast intent classification, query + * routing, and low-latency chat on resource-constrained edge hardware. */ LFM2_5_350M: { ...LFM2_5_350M_XNNPACK_8DA4W, @@ -1866,8 +1881,10 @@ export const models = { MLX_INT4: LFM2_5_350M_MLX_INT4, }, /** - * Liquid AI LFM 2.5 450M vision-language model. Optimized for real-time - * visual QA, image description, and low-latency multimodal chat. + * Liquid AI LFM 2.5 VL 450M lightweight multimodal vision-language model. + * Combines Liquid hybrid language modeling with visual token embeddings for + * real-time on-device visual question answering (VQA), image description, + * UI element inspection, and low-latency multimodal conversational agents. */ LFM2_5_VL_450M: { ...LFM2_5_VL_450M_XNNPACK_8DA4W, @@ -1876,8 +1893,10 @@ export const models = { VULKAN_8DA4W: LFM2_5_VL_450M_VULKAN_8DA4W, }, /** - * Liquid AI LFM 2.5 1.6B vision-language model. Higher quality visual - * understanding, detailed image analysis, and complex multimodal tasks. + * Liquid AI LFM 2.5 VL 1.6B high-capacity vision-language model. Provides + * fine-grained visual scene understanding, document/chart interpretation, + * detailed image captioning, and multi-turn visual dialogue with higher + * precision and reasoning fidelity than the 450M variant. */ LFM2_5_VL_1_6B: { ...LFM2_5_VL_1_6B_XNNPACK_8DA4W, @@ -1885,8 +1904,10 @@ export const models = { VULKAN_8DA4W: LFM2_5_VL_1_6B_VULKAN_8DA4W, }, /** - * Bielik v3 1.5B Polish & English language model. Fine-tuned specifically for - * native Polish fluency, grammar, and bilingual translation. + * Bielik v3 1.5B bilingual Polish & English language model, developed by + * SpeakLeash. Fine-tuned on curated Polish corpora and instruction datasets + * for native Polish cultural nuance, grammar accuracy, idioms, and + * high-fidelity bidirectional Polish-English translation. */ BIELIK_V3_1_5B: { ...BIELIK_V3_1_5B_XNNPACK_8DA4W, @@ -1894,8 +1915,11 @@ export const models = { XNNPACK_FP16: BIELIK_V3_1_5B_XNNPACK_FP16, }, /** - * Meta Llama 3.2 1B multilingual text model. Ideal for lightweight mobile - * chat, summary generation, and multilingual prompt processing. + * Meta Llama 3.2 1B lightweight instruction-tuned multilingual model. + * Features Grouped-Query Attention (GQA) and SpinQuant quantization for + * compact memory utilization and high throughput. Well suited for on-device + * text summarization, prompt rewriting, and lightweight conversational + * assistance. */ LLAMA3_2_1B: { ...LLAMA3_2_1B_SPINQUANT, @@ -1903,8 +1927,10 @@ export const models = { XNNPACK_BF16: LLAMA3_2_1B_BF16, }, /** - * Meta Llama 3.2 3B multilingual text model. Strong instruction following, - * detailed content creation, and high-precision text reasoning. + * Meta Llama 3.2 3B instruction-tuned multilingual language model. Delivers + * strong instruction adherence, multi-turn reasoning, and high-quality + * content creation across 8+ core languages while maintaining a compact + * on-device memory profile. */ LLAMA3_2_3B: { ...LLAMA3_2_3B_SPINQUANT, @@ -1912,8 +1938,9 @@ export const models = { XNNPACK_BF16: LLAMA3_2_3B_BF16, }, /** - * Hugging Face SmolLM2 135M sub-parameter model. Best for micro-footprint - * background tasks, simple text tagging, and instant autocomplete. + * Hugging Face SmolLM2 135M ultra-compact language model. Engineered for + * micro-memory footprints, instant token generation, text classification, + * and background processing on low-power devices. */ SMOLLM2_135M: { ...SMOLLM2_135M_8DA4W, @@ -1921,8 +1948,10 @@ export const models = { XNNPACK_BF16: SMOLLM2_135M_BF16, }, /** - * Hugging Face SmolLM2 360M compact model. Balanced speed and intelligence - * for lightweight conversational assistants. + * Hugging Face SmolLM2 360M compact instruction-tuned model. Provides a + * practical balance between fast mobile generation speed and conversational + * coherence, ideal for lightweight on-device assistants, text + * simplification, and structured data extraction. */ SMOLLM2_360M: { ...SMOLLM2_360M_8DA4W, @@ -1930,8 +1959,10 @@ export const models = { XNNPACK_BF16: SMOLLM2_360M_BF16, }, /** - * Hugging Face SmolLM2 1.7B language model. Powerful general-purpose text - * generation, creative writing, and general knowledge Q&A. + * Hugging Face SmolLM2 1.7B language model trained on curated educational, + * synthetic, and web data. Delivers competitive reasoning, creative text + * generation, and general knowledge Q&A performance approaching larger + * 2B-3B models while maintaining fast on-device inference. */ SMOLLM2_1_7B: { ...SMOLLM2_1_7B_8DA4W, @@ -1939,8 +1970,10 @@ export const models = { XNNPACK_BF16: SMOLLM2_1_7B_BF16, }, /** - * Hammer 2.1 0.5B function-calling model. Specialized for lightweight agentic - * tool calling, JSON extraction, and structured output parsing. + * Hammer 2.1 0.5B specialized function-calling model. Fine-tuned + * specifically for agentic tool use, structured JSON extraction, and + * single/multi-tool invocation with ultra-low latency for real-time mobile + * tool calling flows. */ HAMMER2_1_0_5B: { ...HAMMER2_1_0_5B_XNNPACK_8DA4W, @@ -1948,8 +1981,9 @@ export const models = { XNNPACK_BF16: HAMMER2_1_0_5B_XNNPACK_BF16, }, /** - * Hammer 2.1 1.5B function-calling model. Optimized for multi-tool agentic - * workflows, API function calling, and structured JSON schemas. + * Hammer 2.1 1.5B function-calling language model. Optimized for multi-tool + * agentic workflows, API parameter schema validation, and structured JSON + * output generation on edge devices. */ HAMMER2_1_1_5B: { ...HAMMER2_1_1_5B_XNNPACK_8DA4W, @@ -1957,8 +1991,10 @@ export const models = { XNNPACK_BF16: HAMMER2_1_1_5B_XNNPACK_BF16, }, /** - * Hammer 2.1 3B function-calling model. High-capacity agentic reasoning, - * complex multi-step tool execution, and robust schema compliance. + * Hammer 2.1 3B high-capacity function-calling model. Provides top-tier + * tool selection precision, multi-turn tool calling, error recovery, and + * strict compliance with complex TypeScript/JSON schema specifications in + * autonomous mobile agent pipelines. */ HAMMER2_1_3B: { ...HAMMER2_1_3B_XNNPACK_8DA4W, @@ -1966,8 +2002,10 @@ export const models = { XNNPACK_BF16: HAMMER2_1_3B_XNNPACK_BF16, }, /** - * Microsoft Phi-4 Mini 3.8B reasoning model. Exceptional for math problem - * solving, logical reasoning, code synthesis, and analytical tasks. + * Microsoft Phi-4 Mini 3.8B high-density reasoning model. Trained on + * synthetic textbook-grade datasets for state-of-the-art on-device STEM + * problem solving, complex mathematical reasoning, multi-step code + * synthesis, and structured analytical tasks. */ PHI4_MINI: { ...PHI4_MINI_XNNPACK_8DA4W, @@ -1975,8 +2013,10 @@ export const models = { XNNPACK_BF16: PHI4_MINI_XNNPACK_BF16, }, /** - * Alibaba Qwen 2.5 0.5B multilingual model. Extremely efficient for fast - * multi-language translation and basic conversational chat. + * Alibaba Qwen 2.5 0.5B ultra-lightweight multilingual model. Trained on + * 18T tokens supporting 29+ languages; optimized for near-instant response + * times, basic instruction following, multilingual translation, and + * lightweight conversational assistants on mobile devices. */ QWEN2_5_0_5B: { ...QWEN2_5_0_5B_XNNPACK_8DA4W, @@ -1984,8 +2024,10 @@ export const models = { XNNPACK_BF16: QWEN2_5_0_5B_XNNPACK_BF16, }, /** - * Alibaba Qwen 2.5 1.5B multilingual model. Great for balanced multilingual - * chat, text summarization, and cross-lingual understanding. + * Alibaba Qwen 2.5 1.5B multilingual instruction model. Combines broad + * multilingual comprehension across 29+ languages with strong coding and + * math capabilities, well suited for interactive chat, summarization, and + * cross-lingual translation. */ QWEN2_5_1_5B: { ...QWEN2_5_1_5B_XNNPACK_8DA4W, @@ -1993,8 +2035,9 @@ export const models = { XNNPACK_BF16: QWEN2_5_1_5B_XNNPACK_BF16, }, /** - * Alibaba Qwen 2.5 3B multilingual model. High capability across 29+ - * languages for complex translation, long-form writing, and Q&A. + * Alibaba Qwen 2.5 3B high-capability multilingual model. Delivers strong + * reasoning, coding, mathematics, and multilingual fluency across 29+ + * languages for in-depth text generation and complex multi-turn dialogue. */ QWEN2_5_3B: { ...QWEN2_5_3B_XNNPACK_8DA4W, @@ -2002,8 +2045,10 @@ export const models = { XNNPACK_BF16: QWEN2_5_3B_XNNPACK_BF16, }, /** - * Alibaba Qwen 3 0.6B next-gen text model. Low-latency multilingual model - * for fast turn-taking and concise response generation. + * Alibaba Qwen 3 0.6B next-generation compact language model. Features + * updated architectural optimizations for reduced latency, enhanced + * multilingual token representation, and efficient conversational + * turn-taking on mobile devices. */ QWEN3_0_6B: { ...QWEN3_0_6B_XNNPACK_8DA4W, @@ -2011,8 +2056,9 @@ export const models = { XNNPACK_BF16: QWEN3_0_6B_XNNPACK_BF16, }, /** - * Alibaba Qwen 3 1.7B next-gen text model. Versatile multilingual assistant - * for high-quality instruction following and knowledge retrieval. + * Alibaba Qwen 3 1.7B next-generation multilingual language model. Balances + * high reasoning capability, general knowledge retrieval, coding + * proficiency, and conversational fluidity across multiple languages. */ QWEN3_1_7B: { ...QWEN3_1_7B_XNNPACK_8DA4W, @@ -2020,8 +2066,10 @@ export const models = { XNNPACK_BF16: QWEN3_1_7B_XNNPACK_BF16, }, /** - * Alibaba Qwen 3 4B high-capacity text model. Top-tier multilingual - * reasoning, technical content generation, and multi-turn dialogue. + * Alibaba Qwen 3 4B high-capacity generative model. Delivers advanced + * multi-step reasoning, comprehensive world knowledge, complex coding + * capabilities, and top-tier multilingual performance for demanding + * on-device AI applications. */ QWEN3_4B: { ...QWEN3_4B_XNNPACK_8DA4W, @@ -2029,8 +2077,10 @@ export const models = { XNNPACK_BF16: QWEN3_4B_XNNPACK_BF16, }, /** - * Google Gemma 4 E2B generative text model. Built on Google's Gemini tech - * for high-fidelity instruction following and mobile assistance. + * Google Gemma 4 E2B generative language model. Built on Google's Gemini + * research and architecture innovations, offering high-fidelity instruction + * following, creative text generation, and reasoning efficiency optimized + * for mobile deployment. */ GEMMA4_E2B: { ...GEMMA4_E2B_XNNPACK_8DA4W, @@ -2062,8 +2112,8 @@ export const models = { XNNPACK_FP32: ALL_MPNET_BASE_V2_EMBEDDINGS, }, /** - * 384-dimensional sentence transformer fine-tuned specifically for - * semantic QA matching using cosine similarity. + * 384-dimensional sentence transformer fine-tuned specifically for semantic + * QA matching using cosine similarity. */ MULTI_QA_MINILM_L6_COS_V1: { ...MULTI_QA_MINILM_L6_COS_V1_EMBEDDINGS, @@ -2095,9 +2145,9 @@ export const models = { MLX_INT8: DISTILUSE_BASE_MULTILINGUAL_CASED_V2_MLX_INT8, }, /** - * CLIP text encoder (ViT-B/32) mapping text queries into a - * 512-dimensional joint text-image embedding space. Used in combination - * with `imageEmbeddings.CLIP_VIT_BASE_PATCH32` for zero-shot text-to-image + * CLIP text encoder (ViT-B/32) mapping text queries into a 512-dimensional + * joint text-image embedding space. Used in combination with + * `imageEmbeddings.CLIP_VIT_BASE_PATCH32` for zero-shot text-to-image * search. */ CLIP_VIT_BASE_PATCH32_TEXT: { @@ -2165,8 +2215,8 @@ export const models = { textToImage: { /** * Ultra-fast SDXS (Stable Diffusion eXtreme Speed) 512x512 text-to-image - * generation model based on DreamShaper. Generates high-quality images - * from text prompts in real time. + * generation model based on DreamShaper. Generates high-quality images from + * text prompts in real time. */ SDXS_512_DREAMSHAPER: { ...SDXS_512_DREAMSHAPER_XNNPACK_FP32, @@ -2176,11 +2226,14 @@ export const models = { }, /** - * Text-to-Speech (TTS) models that synthesize audio waveforms from input text. + * Text-to-Speech (TTS) models that synthesize audio waveforms from input + * text. */ textToSpeech: { /** - * Supertonic 3 multilingual flow-matching Text-to-Speech model. + * Supertonic 3 multilingual flow-matching Text-to-Speech model. Delivers + * natural, highly expressive speech synthesis with configurable speaker + * voice presets (see {@link SUPERTONIC_DEFAULT_VOICE_NAMES}). */ SUPERTONIC: { ...SUPERTONIC_3_XNNPACK_FP32, diff --git a/packages/react-native-executorch/src/native/bridge.ts b/packages/react-native-executorch/src/native/bridge.ts index c3d5f6bb73..3d17ab8fc0 100644 --- a/packages/react-native-executorch/src/native/bridge.ts +++ b/packages/react-native-executorch/src/native/bridge.ts @@ -7,6 +7,15 @@ if (!globalObj.__rnexecutorch_jsi__) { if (NativeRnExecutorch) NativeRnExecutorch.install(); } +/** + * Direct reference to the native C++ JSI host object (`__rnexecutorch_jsi__`). + * + * Provides low-level, synchronous bindings for ExecuTorch core runtime + * operations (model loading, tensor allocation and manipulation, registered + * backends inspection, emulator detection) and native extension namespaces + * (`cv`, `llm`, `math`, `nlp`, `speech`). + * @internal + */ export const rnexecutorchJsi = globalObj.__rnexecutorch_jsi__; if (!rnexecutorchJsi) { diff --git a/packages/react-native-executorch/src/utils.ts b/packages/react-native-executorch/src/utils.ts index d7ad54f65c..278b223be1 100644 --- a/packages/react-native-executorch/src/utils.ts +++ b/packages/react-native-executorch/src/utils.ts @@ -30,8 +30,8 @@ export function getRegisteredBackends(): string[] { * returned local path if you also intend to run the model. * @category Utils * @param source The remote HTTP URL or local path to the `.pte` model file. - * @returns A promise resolving to an object containing the model source, - * method signature metadata, and per-method backend usage. + * @returns A promise resolving to an object containing the model source, method + * signature metadata, and per-method backend usage. */ export async function inspectModel(source: string): Promise<{ source: string; From 23d08eac3da002f2e49b7cc9b2f0827fad4e023b Mon Sep 17 00:00:00 2001 From: Bartosz Hanc Date: Fri, 21 Aug 2026 15:27:02 +0200 Subject: [PATCH 02/38] refactor(hooks): unify JSDoc documentation, link imperative APIs and types, and use undefined for absent state --- .agents/skills/add-task-pipeline/SKILL.md | 17 +++----- .../src/hooks/useClassifier.ts | 16 +++++--- .../src/hooks/useImageEmbedder.ts | 16 +++++--- .../src/hooks/useInstanceSegmenter.ts | 16 +++++--- .../src/hooks/useKeypointDetector.ts | 16 +++++--- .../src/hooks/useLLMChatSession.ts | 26 ++++++------ .../src/hooks/useModel.ts | 28 ++++++------- .../src/hooks/useObjectDetector.ts | 18 ++++---- .../hooks/useOpticalCharacterRecognizer.ts | 19 +++++---- .../src/hooks/usePrivacyFilter.ts | 17 ++++---- .../src/hooks/useResourceDownload.ts | 18 ++++---- .../src/hooks/useSemanticSegmenter.ts | 16 +++++--- .../src/hooks/useSpeechToText.ts | 18 ++++---- .../src/hooks/useStyleTransfer.ts | 14 ++++--- .../src/hooks/useTextEmbedder.ts | 17 ++++---- .../src/hooks/useTextToImage.ts | 19 +++++---- .../src/hooks/useTextToSpeech.ts | 41 +++++++++++-------- .../src/hooks/useTokenizer.ts | 14 ++++--- .../src/hooks/useVoiceActivityDetector.ts | 15 ++++--- packages/react-native-executorch/src/utils.ts | 4 +- 20 files changed, 212 insertions(+), 153 deletions(-) diff --git a/.agents/skills/add-task-pipeline/SKILL.md b/.agents/skills/add-task-pipeline/SKILL.md index 84574c50c8..d0d9d306a6 100644 --- a/.agents/skills/add-task-pipeline/SKILL.md +++ b/.agents/skills/add-task-pipeline/SKILL.md @@ -190,28 +190,21 @@ Wrap the task pipeline in a custom React Hook using the core hooks `useResourceD ```typescript import { useModel } from './useModel'; -import { useResourceDownload } from './useResourceDownload'; +import { useResourceDownload, type ResourceOptions } from './useResourceDownload'; import { createMyTask, type MyTaskModel } from '../extensions//tasks/'; -export function useMyTask(config: MyTaskModel, options?: { preventLoad?: boolean }) { +export function useMyTask(config: MyTaskModel, options?: ResourceOptions) { // 1. Resolve remote or local asset model path and download progress - const { localPath, downloadProgress, downloadError } = useResourceDownload( - config.modelPath, - options?.preventLoad - ); + const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); // 2. Instantiate and compile the task pipeline (with automatic lifecycle cleanup) - const { model, error } = useModel( - createMyTask, - localPath ? { ...config, modelPath: localPath } : null, - [localPath] - ); + const { model, error } = useModel(createMyTask, resource); return { isReady: !!model, error: downloadError || error, downloadProgress, - localPath, + resource, runTask: model?.runTask, runTaskWorklet: model?.runTaskWorklet, }; diff --git a/packages/react-native-executorch/src/hooks/useClassifier.ts b/packages/react-native-executorch/src/hooks/useClassifier.ts index 9612539b88..795e010589 100644 --- a/packages/react-native-executorch/src/hooks/useClassifier.ts +++ b/packages/react-native-executorch/src/hooks/useClassifier.ts @@ -5,20 +5,24 @@ import { createClassifier, type ClassifierModel } from '../extensions/cv/tasks/c /** * React hook to load and run an image classification model. * - * This hook manages downloading (if it's a remote URL) and loading the model - * file, compiling it, tracking download progress and compilation errors, and - * cleaning up native model memory when the component unmounts or configuration + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets, compiling them, tracking download progress and load errors, and + * releasing native memory when the component unmounts or the configuration * changes. + * + * For imperative usage, see {@link createClassifier}. * @category Hooks * @typeParam L The type representing the classification labels. - * @param config The image classification model configuration. + * @param config The image classification model configuration. See {@link + * ClassifierModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download - * progress, and classification functions. + * progress, labels, and classification functions. + * @see {@link createClassifier} */ export function useClassifier(config: ClassifierModel, options?: ResourceOptions) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createClassifier, resource ?? null); + const { model, error } = useModel(createClassifier, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/useImageEmbedder.ts b/packages/react-native-executorch/src/hooks/useImageEmbedder.ts index 5a6eec7c17..5d91c0bfa2 100644 --- a/packages/react-native-executorch/src/hooks/useImageEmbedder.ts +++ b/packages/react-native-executorch/src/hooks/useImageEmbedder.ts @@ -6,21 +6,25 @@ import { } from '../extensions/cv/tasks/imageEmbedding'; /** - * React hook to load and run an image embedder model. + * React hook to load and run an image embedding model. * - * This hook manages downloading (if it's a remote URL) and loading the model - * file, compiling it, tracking download progress and compilation errors, and - * cleaning up native model memory when the component unmounts or configuration + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets, compiling them, tracking download progress and load errors, and + * releasing native memory when the component unmounts or the configuration * changes. + * + * For imperative usage, see {@link createImageEmbedder}. * @category Hooks - * @param config The image embedder model configuration. + * @param config The image embedder model configuration. See {@link + * ImageEmbedderModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download * progress, and embedding functions. + * @see {@link createImageEmbedder} */ export function useImageEmbedder(config: ImageEmbedderModel, options?: ResourceOptions) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createImageEmbedder, resource ?? null); + const { model, error } = useModel(createImageEmbedder, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/useInstanceSegmenter.ts b/packages/react-native-executorch/src/hooks/useInstanceSegmenter.ts index e986709a5d..b43b6eba25 100644 --- a/packages/react-native-executorch/src/hooks/useInstanceSegmenter.ts +++ b/packages/react-native-executorch/src/hooks/useInstanceSegmenter.ts @@ -9,24 +9,28 @@ import { /** * React hook to load and run an instance segmentation model. * - * This hook manages downloading (if it's a remote URL) and loading the model - * file, compiling it, tracking download progress and compilation errors, and - * cleaning up native model memory when the component unmounts or configuration + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets, compiling them, tracking download progress and load errors, and + * releasing native memory when the component unmounts or the configuration * changes. + * + * For imperative usage, see {@link createInstanceSegmenter}. * @category Hooks * @typeParam F The bounding box format. * @typeParam L The class labels type. - * @param config The instance segmentation model configuration. + * @param config The instance segmentation model configuration. See {@link + * InstanceSegmenterModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download - * progress, and segmentation functions. + * progress, labels, and instance segmentation functions. + * @see {@link createInstanceSegmenter} */ export function useInstanceSegmenter( config: InstanceSegmenterModel, options?: ResourceOptions ) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createInstanceSegmenter, resource ?? null); + const { model, error } = useModel(createInstanceSegmenter, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/useKeypointDetector.ts b/packages/react-native-executorch/src/hooks/useKeypointDetector.ts index e14b10c53a..01bba9c1c1 100644 --- a/packages/react-native-executorch/src/hooks/useKeypointDetector.ts +++ b/packages/react-native-executorch/src/hooks/useKeypointDetector.ts @@ -9,24 +9,28 @@ import { /** * React hook to load and run a keypoint detection model. * - * This hook manages downloading (if it's a remote URL) and loading the model - * file, compiling it, tracking download progress and compilation errors, and - * cleaning up native model memory when the component unmounts or configuration + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets, compiling them, tracking download progress and load errors, and + * releasing native memory when the component unmounts or the configuration * changes. + * + * For imperative usage, see {@link createKeypointDetector}. * @category Hooks * @typeParam F The bounding box format. * @typeParam L The landmark labels type. - * @param config The keypoint detection model configuration. + * @param config The keypoint detection model configuration. See {@link + * KeypointDetectorModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download - * progress, and keypoint detection functions. + * progress, landmarks, and keypoint detection functions. + * @see {@link createKeypointDetector} */ export function useKeypointDetector( config: KeypointDetectorModel, options?: ResourceOptions ) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createKeypointDetector, resource ?? null); + const { model, error } = useModel(createKeypointDetector, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/useLLMChatSession.ts b/packages/react-native-executorch/src/hooks/useLLMChatSession.ts index 32b537a456..c33a6a6c76 100644 --- a/packages/react-native-executorch/src/hooks/useLLMChatSession.ts +++ b/packages/react-native-executorch/src/hooks/useLLMChatSession.ts @@ -7,26 +7,28 @@ import { } from '../extensions/llm/tasks/llmChatSession'; /** - * React hook to load and run an LLM chat session model. + * React hook to load and run an LLM chat session. * - * This hook manages downloading (if they are remote URLs) and loading the `.pte` model - * file, `tokenizer.json`, and `tokenizer_config.json`, tracking download progress and errors, - * and cleaning up native memory when the component unmounts or configuration changes. + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets and tokenizer files, tracking download progress and load errors, + * and releasing native memory when the component unmounts or the configuration + * changes. + * + * For imperative usage, see {@link createLLMChatSession}. * @category Hooks - * @param config The LLM model configuration. - * @param options Chat session options and load/caching options. See {@link ResourceOptions}. - * @returns An object containing the session's loading state, error, download progress, - * and chat functions. + * @param config The LLM model configuration. See {@link LLMModel}. + * @param options Chat session options and load/caching options. See {@link + * ResourceOptions}. + * @returns An object containing the session's loading state, error, download + * progress, and chat functions. + * @see {@link createLLMChatSession} */ export function useLLMChatSession( config: LLMModel, options?: LLMChatSessionOptions & ResourceOptions ) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model: session, error } = useModel( - (res) => createLLMChatSession(res, options), - resource ?? null - ); + const { model: session, error } = useModel((res) => createLLMChatSession(res, options), resource); return { isReady: !!session, diff --git a/packages/react-native-executorch/src/hooks/useModel.ts b/packages/react-native-executorch/src/hooks/useModel.ts index aa1f022b7e..98748f7807 100644 --- a/packages/react-native-executorch/src/hooks/useModel.ts +++ b/packages/react-native-executorch/src/hooks/useModel.ts @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState } from 'react'; /** - * React hook to instantiate and compile a model pipeline with automatic + * React hook to instantiate and manage a model or task instance with automatic * lifetime management. * * It manages the lifecycle of a model or task runner instance. When the @@ -11,10 +11,10 @@ import { useEffect, useMemo, useState } from 'react'; * @typeParam TConfig The configuration type passed to the model creator. * @typeParam TModel The type of the compiled model instance containing a * `dispose` method. - * @param createModel An asynchronous factory function to instantiate the - * model/task. - * @param config The configuration to pass to `createModel`, or `null` if the - * model shouldn't be loaded yet. It is tracked by value, so the model is + * @param createModel An asynchronous factory function to instantiate the model + * or task runner. + * @param config The configuration to pass to `createModel`, or `undefined` if + * the model shouldn't be loaded yet. It is tracked by value, so the model is * re-created whenever the config's contents change and passing an inline object * is safe. * @returns An object containing the loaded model instance and any instantiation @@ -22,26 +22,26 @@ import { useEffect, useMemo, useState } from 'react'; */ export function useModel void }>( createModel: (config: TConfig) => Promise, - config: TConfig | null + config: TConfig | undefined ) { - const [model, setModel] = useState(null); - const [error, setError] = useState(null); + const [model, setModel] = useState(); + const [error, setError] = useState(); // Configs are plain JSON data, so serializing is a sound structural identity // and keeps an inline `config` object from rebuilding the model every render. const configKey = useMemo(() => JSON.stringify(config), [config]); useEffect(() => { - if (!config) { - setModel(null); - setError(null); + if (config === undefined) { + setModel(undefined); + setError(undefined); return; } let isMounted = true; - let instance: TModel | null = null; - setModel(null); - setError(null); + let instance: TModel | undefined; + setModel(undefined); + setError(undefined); createModel(config) .then((m) => { diff --git a/packages/react-native-executorch/src/hooks/useObjectDetector.ts b/packages/react-native-executorch/src/hooks/useObjectDetector.ts index 6a724840cf..e66109628a 100644 --- a/packages/react-native-executorch/src/hooks/useObjectDetector.ts +++ b/packages/react-native-executorch/src/hooks/useObjectDetector.ts @@ -9,24 +9,28 @@ import { /** * React hook to load and run an object detection model. * - * This hook manages downloading (if it's a remote URL) and loading the model - * file, compiling it, tracking download progress and compilation errors, and - * cleaning up native model memory when the component unmounts or configuration + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets, compiling them, tracking download progress and load errors, and + * releasing native memory when the component unmounts or the configuration * changes. + * + * For imperative usage, see {@link createObjectDetector}. * @category Hooks - * @typeParam L The type representing the object class labels. * @typeParam F The bounding box format. - * @param config The object detection model configuration. + * @typeParam L The type representing the object class labels. + * @param config The object detection model configuration. See {@link + * ObjectDetectorModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download - * progress, and object detection functions. + * progress, labels, and object detection functions. + * @see {@link createObjectDetector} */ export function useObjectDetector( config: ObjectDetectorModel, options?: ResourceOptions ) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createObjectDetector, resource ?? null); + const { model, error } = useModel(createObjectDetector, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/useOpticalCharacterRecognizer.ts b/packages/react-native-executorch/src/hooks/useOpticalCharacterRecognizer.ts index 3b2ee02a3f..572651b1eb 100644 --- a/packages/react-native-executorch/src/hooks/useOpticalCharacterRecognizer.ts +++ b/packages/react-native-executorch/src/hooks/useOpticalCharacterRecognizer.ts @@ -3,19 +3,24 @@ import { useResourceDownload, type ResourceOptions } from './useResourceDownload import { useModel } from './useModel'; /** - * React hook for the PP-OCRv6 pipeline. It downloads and loads the model, tracks - * progress and errors, instantiates the task runner, and cleans up native memory - * on unmount or config change. Heavy work runs on a worklet thread; - * `recognizeCharacters` resolves with the recognized regions in reading order. + * React hook for the PP-OCRv6 pipeline. + * + * It downloads and loads the model, tracks progress and errors, instantiates the + * task runner, and cleans up native memory on unmount or config change. Heavy + * work runs on a worklet thread; `recognizeCharacters` resolves with the + * recognized regions in reading order. + * + * For imperative usage, see {@link createPaddleOcr}. * @category Hooks * @param config OCR model configuration. Use a preset from `models.ocr.*`. * @param options Load and caching options. See {@link ResourceOptions}. - * @returns Readiness flags, download progress, and the `recognizeCharacters` / - * `recognizeCharactersWorklet` runners. + * @returns The same object as {@link createPaddleOcr} (without `dispose`), + * combined with loading state, download progress, and resource info. + * @see {@link createPaddleOcr} */ export function useOpticalCharacterRecognizer(config: PaddleOcrModel, options?: ResourceOptions) { const { resource, downloadProgress, downloadError } = useResourceDownload(config, options); - const { model, error } = useModel(createPaddleOcr, resource ?? null); + const { model, error } = useModel(createPaddleOcr, resource); return { isReady: !!model, diff --git a/packages/react-native-executorch/src/hooks/usePrivacyFilter.ts b/packages/react-native-executorch/src/hooks/usePrivacyFilter.ts index 88b182de07..6a0ed8872e 100644 --- a/packages/react-native-executorch/src/hooks/usePrivacyFilter.ts +++ b/packages/react-native-executorch/src/hooks/usePrivacyFilter.ts @@ -8,25 +8,28 @@ import { /** * React hook to load and run a privacy filter (PII detection) model. * - * This hook manages downloading (if they are remote URLs) and loading both the - * model file and its `tokenizer.json`, tracking download progress and errors, - * and cleaning up native memory when the component unmounts or the - * configuration changes. + * This hook manages downloading (if remote URLs are provided) and loading the + * model assets and tokenizer files, tracking download progress and load errors, + * and releasing native memory when the component unmounts or the configuration + * changes. + * + * For imperative usage, see {@link createPrivacyFilter}. * @category Hooks * @typeParam Label The model's BIOES label space, narrowing the detected entity * types when a concrete `models` registry entry is passed. - * @param config The privacy filter model configuration (model and tokenizer - * paths plus the label space options). + * @param config The privacy filter model configuration. See {@link + * PrivacyFilterModel}. * @param options Load and caching options. See {@link ResourceOptions}. * @returns An object containing the model's loading state, error, download * progress, and detection functions. + * @see {@link createPrivacyFilter} */ export function usePrivacyFilter