running-openmed-ondevice
它能做什么
这项技能教智能体如何在个人设备上运行 OpenMed 医学文本模型,无需互联网。内容涵盖苹果设备、iPhone 和 iPad 应用,以及浏览器环境的设置。
适用场景
- ✓当团队想在 Mac 或 iPhone 上进行医学文本分析,又不想把数据发送到服务器的时候。
- ✓当开发者需要通过 WebGPU 或 ONNX 在网页浏览器中运行模型的时候。
- ✓当用户想把临床模型压缩为 8 位或 4 位权重,以便在更小的设备上运行的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/running-openmed-ondevice/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“如何在没有互联网连接的情况下,在我的 Mac 上运行这个医学文本模型?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把模型转换为所选运行时的格式,按需压缩,并在本地运行。由于数据不会离开设备,患者文本会保留在设备上。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Running OpenMed on-device
OpenMed runs fully on-device by design. These three backends let you take it further at the edge: MLX (Apple Silicon acceleration), CoreML (iOS/macOS / Neural Engine), and ONNX / WebGPU (cross-platform and in-browser). The flow is the same: convert → (quantize) → run locally. Because inference is local, raw PHI never leaves the device — the strongest privacy posture OpenMed offers.
When to use this skill
When you need OpenMed where there is no server: an iOS/macOS app (CoreML),
fast NER/de-id on an Apple Silicon Mac (MLX), or a portable/browser deployment
(ONNX/WebGPU). For a hosted endpoint use serving-openmed-rest-api; for an
agent tool use deploying-openmed-mcp; for corpora use
batch-processing-clinical-text.
Pick a backend
| Backend | Extra | Best for | Quantization |
|---|---|---|---|
| MLX | openmed[mlx] |
Apple Silicon Macs; fastest local NER/de-id; on-device LLMs | 4-bit / 8-bit weights |
| CoreML | openmed[coreml] |
iOS/iPadOS/macOS apps, Neural Engine | int8 palettization |
| ONNX / WebGPU | openmed[onnx] |
cross-platform runtimes, browser (transformers.js) | fp16 (WebGPU); int8 via ORT |
Quick start — MLX (Apple Silicon)
pip install "openmed[mlx]"
# Convert a HF token-classification model to an OpenMed MLX artifact, 8-bit:
python -m openmed.mlx.convert --model OpenMed/<some-ner-model> --output ./mlx_ner --quantize 8
import openmed
# Run NER/de-id through the normal API — pass the local artifact dir as model_name.
# The loader auto-detects the MLX backend from the artifact (or set backend explicitly).
result = openmed.analyze_text(
"Patient received 75mg clopidogrel for NSTEMI.",
model_name="./mlx_ner", # local MLX artifact directory
output_format="dict",
)
# Force MLX via config if you prefer to be explicit:
from openmed.core.config import OpenMedConfig
cfg = OpenMedConfig(backend="mlx") # None=auto-detect, "mlx", or "hf"
convert() is also importable: openmed.mlx.convert.convert(model_id, output_dir, quantize_bits=8). The CLI accepts --quantize {4,8}, --quantize-group-size,
--cache-dir, and an optional --eval-suite to certify quantized recall
against the full-precision parent (recommended for clinical models — quantization
can drop recall on rare entities).
On-device LLM generation (MLX)
from openmed.mlx.lm import generate_text, OpenMedMLXLanguageModel
text = generate_text(
messages=[{"role": "user", "content": "Summarize: chest pain, troponin elevated."}],
model_name="OpenMed/laneformer-2b-it-q4-mlx", # resolves to a local MLX-LM artifact
max_tokens=128,
)
llm = OpenMedMLXLanguageModel("OpenMed/laneformer-2b-it-q4-mlx")
out = llm.generate(prompt="...", max_tokens=64, temp=0.0)
Quick start — CoreML (iOS/macOS)
pip install "openmed[coreml]"
python -m openmed.coreml.convert --model OpenMed/<some-ner-model> --output model.mlpackage --quantize int8
from openmed.coreml.convert import convert
convert(
"OpenMed/<some-ner-model>",
"model.mlpackage",
compute_units="cpuAndNeuralEngine", # "all" | "cpuAndNeuralEngine" | "cpuOnly"
compute_precision="float16", # float16 for Neural Engine, float32 for CPU
quantize="int8", # emits an int8-palettized sibling .mlpackage
)
Bundle the .mlpackage in your Xcode app and run it with Core ML; the converter
writes the id2label map so your app can decode token labels. Use float16 +
cpuAndNeuralEngine for the Neural Engine; int8 shrinks the model for
storage-constrained devices.
Quick start — ONNX / WebGPU
pip install "openmed[onnx]"
python -m openmed.onnx.convert --model OpenMed/<some-ner-model> --output ./onnx_out
from openmed.onnx.convert import convert
res = convert("OpenMed/<some-ner-model>", "./onnx_out", include_webgpu=True, opset=18)
# Emits model.onnx (fp32) and model.webgpu.onnx (fp16) + an export manifest.
Run model.onnx with ONNX Runtime on any platform, or ship model.webgpu.onnx
to the browser via transformers.js for in-page, zero-upload inference. Use
--no-webgpu to skip the fp16 artifact.
Workflow
- Pick the backend for the target (table above).
- Convert the HF/OpenMed model with the matching
convert()/python -m openmed.<backend>.convert. - Quantize if size/latency demands it (MLX 4/8-bit, CoreML int8, WebGPU
常见问题
我应该选择哪种后端?
Apple Silicon Mac 使用 MLX,iPhone 和 iPad 应用使用 CoreML,浏览器和其他系统使用 ONNX 或 WebGPU。
它需要互联网连接吗?
不需要。这项技能说明推理在本地进行,无需网络。
它涵盖托管服务器方案吗?
不涵盖。这项技能会指引用户去看其他关于服务器和智能体工具设置的技能。
详情
作者的原始描述
Run OpenMed models fully on-device with the MLX (Apple Silicon), CoreML (iOS/macOS), or ONNX/WebGPU (cross-platform/browser) backends, including convert-quantize-run workflows. Use when the user wants to deploy OpenMed at the edge, run NER/de-id on Apple Silicon, target iPhone/iPad/Mac, export to ONNX or WebGPU, quantize a clinical model to int8/4-bit, run with no network, or pick between MLX/CoreML/ONNX. Covers the mlx/coreml/onnx extras, the convert() functions and python -m convert CLIs, quantization, loading a local MLX artifact through analyze_text, OpenMedMLXLanguageModel/generate_text,
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14728
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。