CoolFace
Modelpublic

OpenMed/privacy-filter-nemotron-v2-mlx-8bit

sourceHugging Faceotherupdated 3mo agoView on Hugging Face
1likes24downloads
Model Card

OpenMed Privacy Filter Nemotron v2 - MLX 8-bit

A native MLX port of `OpenMed/privacy-filter-nemotron-v2`, affine-quantized to 8-bit for faster and smaller Apple Silicon PII detection with OpenMed. For the unquantized BF16 reference, see `OpenMed/privacy-filter-nemotron-v2-mlx`.

Family at a glance: - PyTorch source: `OpenMed/privacy-filter-nemotron-v2` - MLX BF16: `OpenMed/privacy-filter-nemotron-v2-mlx` - Apple Silicon, 2.6 GiB weights - MLX 8-bit (this repo): Apple Silicon, 1.4 GiB weights, ~1.8x faster than BF16 in the local golden-sample run

Why 8-bit?

BF16 siblingThis repo (Q8)
weights.safetensors size2.6 GiB1.4 GiB
Average forward pass14.2 ms7.9 ms (~1.8x faster)
Average argmax agreement vs. BF16reference99.55%
Entity-span preservationreferenceidentical on all 10 golden samples

Validation used scripts/export/verify_privacy_filter_nemotron_mlx.py over 10 golden PII samples (email, phone, ssn, credit card, name, ipv4, address, dateofbirth, url, mixed). Minimum per-sample argmax agreement was 95.5%; decoded spans still matched the BF16 reference on every sample.

Quantization

FieldValue
Bits8
Group size64
Modeaffine MLX weight-only quantization
Quantized modulesembedding, attention projections, MoE router/expert matrices, output head
Kept in BF16RMSNorm scales and attention sinks

What it does

This model is an MLX packaging of `OpenMed/privacy-filter-nemotron-v2`, the second-generation Nemotron-schema checkpoint with a broader training mix and a more recall-oriented adaptation recipe than the first Nemotron branch. It uses OpenAI's Privacy Filter architecture and predicts 221 BIOES classes (O plus B/I/E/S for each category). The OpenMed PrivacyFilterMLXPipeline runs BIOES-aware Viterbi decoding so callers receive grouped spans instead of raw token tags.

Label coverage highlights:

  • Identity and demographics: firstname, lastname, age, gender, nationality, language
  • Contact and address: email, phonenumber, streetaddress, city, country, postcode
  • Government and regulated IDs: ssn, nationalid, taxid, certificatelicensenumber
  • Financial and secrets: accountnumber, creditdebitcard, cvv, pin, password, swiftbic
  • Medical, workplace, online, vehicle, and time identifiers such as medicalrecordnumber, employeeid, ipv4, url, licenseplate, date, and time

The full label map is included in id2label.json.

Architecture

FieldValue
Source model typeopenai_privacy_filter
Source architectureOpenAIPrivacyFilterForTokenClassification
Hidden size640
Transformer layers8
AttentionGrouped-query attention (14 query heads / 2 KV heads, head_dim=64) with attention sinks
FFNSparse Mixture-of-Experts - 128 experts, top-4 routing, SwiGLU
Position encodingYARN-scaled RoPE (rope_theta=150000, factor=32)
Context length131,072 tokens (initial 4,096)
Tokenizero200k_base / tiktoken-compatible tokenizer assets, vocab 200,064
Output headLinear(640 -> 221) with bias

File set

FileSizePurpose
weights.safetensors1.4 GiBMLX weights
config.json19.6 KiBModel and OpenMed MLX runtime config
id2label.json5.4 KiBNumeric ID to BIOES label mapping
openmed-mlx.json0.8 KiBOpenMed MLX artifact manifest
tokenizer.json27 MiBTokenizer asset kept with the artifact
tokenizer_config.json0.2 KiBTokenizer metadata

The MLX runtime uses the tiktoken-compatible o200k_base tokenizer path. tokenizer.json and tokenizer_config.json are bundled so consumers can inspect the tokenizer assets and keep the artifact self-contained.

Quick start

With OpenMed

bash
pip install -U "openmed[mlx]"
python
from openmed import extract_pii, deidentify
from openmed.core import OpenMedConfig

model_name = "OpenMed/privacy-filter-nemotron-v2-mlx-8bit"
text = (
    "Patient Sarah Johnson (DOB 03/15/1985), MRN 4872910, "
    "phone 415-555-0123, email sarah.johnson@example.com."
)

result = extract_pii(
    text,
    model_name=model_name,
    config=OpenMedConfig(backend="mlx"),
)
for ent in result.entities:
    print(ent.label, ent.text, round(ent.confidence, 4))

masked = deidentify(
    text,
    method="mask",
    model_name=model_name,
    config=OpenMedConfig(backend="mlx"),
)
print(masked.deidentified_text)

For non-MLX hosts, use the source PyTorch checkpoint `OpenMed/privacy-filter-nemotron-v2`.

Direct MLX usage

python
from huggingface_hub import snapshot_download
from openmed.mlx.inference import PrivacyFilterMLXPipeline

model_path = snapshot_download("OpenMed/privacy-filter-nemotron-v2-mlx-8bit")
pipe = PrivacyFilterMLXPipeline(model_path)

print(pipe("Email me at alice.smith@example.com after 5pm."))

Loading from a local snapshot

python
from openmed.mlx.models import load_model
import mlx.core as mx

model = load_model("/path/to/privacy-filter-nemotron-v2-mlx-8bit")
ids = mx.array([[1, 100, 200, 300]], dtype=mx.int32)
mask = mx.ones((1, 4), dtype=mx.bool_)
logits = model(ids, attention_mask=mask)
print(logits.shape)

Hardware notes

  • Designed for Apple Silicon with MLX.
  • CPU inference may work, but GPU-backed MLX on M-series Macs is the intended runtime.
  • The Python package path is pip install -U "openmed[mlx]".

Credits

This artifact builds on:

License

The source checkpoint model card currently declares license: other; this MLX packaging follows that source license metadata. Review the source model card before redistribution.