CoreML Export¶
Use CoreML when you need a bundled Apple model package for Swift, iOS, or macOS app integration. If you want the shared OpenMed MLX artifact path, see the MLX backend and OpenMedKit Swift guide.
The CoreML converter is a local packaging path for Hugging Face token-classification checkpoints. After model download, conversion runs locally and writes .mlpackage artifacts plus label sidecars for app bundles.
Converter Contract¶
python -m openmed.coreml.convert \
--model OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 \
--output ./OpenMedPIISmall.mlpackage \
--precision float16 \
--compute-units cpuAndNeuralEngine \
--quantize int8
The command writes:
OpenMedPIISmall.mlpackage: the float16 CoreML packageOpenMedPIISmall_id2label.json: label sidecar for the float packageOpenMedPIISmall_int8.mlpackage: the INT8-palettized package when--quantize int8is setOpenMedPIISmall_int8_id2label.json: label sidecar for the INT8 package
Use --quantized-output <path> when the default _int8.mlpackage sibling name does not fit your release layout.
Supported Families¶
The converter accepts these Hugging Face token-classification source families:
bertdistilbertelectrarobertaxlm-robertadeberta-v2
Unsupported architectures fail before tracing with an error that lists the supported families.
Compute Units¶
Use --compute-units to declare the Core ML runtime target:
all: Core ML may use all available compute unitscpuAndNeuralEngine: prefer CPU plus Apple Neural EnginecpuOnly: CPU-only package execution
The selected value is passed to Core ML conversion and stored in package metadata.
Metadata¶
Each .mlpackage carries the following user_defined_metadata fields:
id2labelnum_labelsmax_seq_lengthsource_modelsource_model_typecompute_precisioncompute_unitsquantization
The float package records quantization=none; the INT8 package records quantization=int8.
Manual CoreML Integration¶
If you already have a compatible CoreML model and prefer not to use OpenMedKit, you can integrate it directly:
import CoreML
let model = try MLModel(contentsOf: modelURL)
let inputIds = try MLMultiArray(shape: [1, seqLen], dataType: .int32)
let mask = try MLMultiArray(shape: [1, seqLen], dataType: .int32)
let input = try MLDictionaryFeatureProvider(dictionary: [
"input_ids": MLFeatureValue(multiArray: inputIds),
"attention_mask": MLFeatureValue(multiArray: mask),
])
let output = try model.prediction(from: input)
let logits = output.featureValue(for: "logits")!.multiArrayValue!
For most apps, OpenMedKit is the simpler route.