Views
No views yet
coreai-torch (LLMs: coreai.llm.export) into .aimodel bundles that run on the GPU or the Neural Engine, e.g. Qwen3-8B 4-bit decodes at 94 tok/s on an M4 Max GPU, MLX 90 under the same protocol (apple-silicon-llm-bench, macOS 27 beta, 2026-06)..aimodel via AIModel.run
(like the vision encoders), not the pipelined generate engine.| name | shape | dtype | |
|---|---|---|---|
| input | input_ids | [1, 512] | int32 (right-padded; pad id 151643) |
| input | attention_mask | [1, 512] | int32 (1 = real token, 0 = padding) |
| output | embedding | [1, 1024] | fp16, L2-normalized |
Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery:
Document → no prefix.1# Core AI runtime (Python), GPU delegate
2import coreai.runtime as rt, numpy as np
3from transformers import AutoTokenizer
4
5tok = AutoTokenizer.from_pretrained("tokenizer")
6m = await rt.AIModel.load("qwen3-embedding-0.6b_float16_s512_static.aimodel",
7 rt.SpecializationOptions.from_preferred_compute_unit_kind(rt.ComputeUnitKind.gpu()))
8fn = m.load_function("main")
9
10def embed(text, is_query):
11 prefix = ("Instruct: Given a web search query, retrieve relevant passages that "
12 "answer the query\nQuery:") if is_query else ""
13 enc = tok(prefix + text, padding="max_length", truncation=True, max_length=512,
14 return_tensors="np", padding_side="right")
15 res = await fn({"input_ids": rt.NDArray(enc["input_ids"].astype(np.int32)),
16 "attention_mask": rt.NDArray(enc["attention_mask"].astype(np.int32))})
17 return res["embedding"].numpy()[0] # [1024], unit-norm1import CoreAIKitEmbeddings
2
3let embedder = try await TextEmbedder(model: .qwen3Embedding0_6B, prompts: .qwen3Embedding)
4let query = try await embedder.embed(query: "What is the capital of Japan?")
5let doc = try await embedder.embed(document: "Tokyo is the capital and largest city of Japan.")
6let score = TextEmbedder.cosineSimilarity(query, doc) // unit vectors → dot product = cosineqwen3-embedding-0.6b_float16_s512_static.aimodel (~1.1 GB, fp16)
tokenizer/ (HF tokenizer files)
reference.json (torch reference embeddings + cosines)sentence-transformers pipeline (fp32):
per-text embedding cosine 1.000000, retrieval order identical, MRL rankings preserved at
512 / 256 / 128. On the Core AI GPU delegate the .aimodel reproduces the torch reference at
cosine 0.999998 end-to-end (host tokenize → run). Measured ~25 ms (256-grid) / ~45 ms
(512-grid) per embedding on an M4 Max GPU.conversion/export_qwen3_embedding.py
in the coreai-model-zoo.