bart-large-cnn-mlx
Model Summary
This is an unofficial MLX conversion of facebook/bart-large-cnn (a standard BART encoder-decoder fine-tuned for summarization on CNN/DailyMail). All credit for the original model goes to its authors (Meta/Facebook AI).
This cannot be loaded with mlx_lm
mlx_lm only supports causal (decoder-only) language models, not
encoder-decoder architectures like BART. This model was reimplemented from
scratch for MLX and requires the bundled bart_mlx.py, which includes an
autoregressive decode loop with KV caching.
Limitations
- Greedy decoding only: the reference model's default generation config
uses beam search (
num_beams=4) plus a no-repeat-3-gram constraint; this implementation only supports greedy decoding. Output text may differ from the PyTorch beam-search reference (teacher-forced logits match exactly -- see Accuracy below). - No padding, single document only: batched processing of multiple documents is not supported.
forced_bos_token_idis applied: the reference generation config forces token ID 0 right after the decoder-start token. Skipping this noticeably degrades output quality (greedy decoding is very sensitive to the first token choice), so it's applied by default here.
Usage
import mlx.core as mx
from mlx.utils import tree_unflatten
from transformers import AutoTokenizer
from bart_mlx import BartMLX
tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
model = BartMLX()
weights = mx.load("model.safetensors")
model.update(tree_unflatten(list(weights.items())))
mx.eval(model.parameters())
article = "..." # the text to summarize
inputs = tokenizer(article, return_tensors="np")
input_ids = mx.array(inputs["input_ids"])
generated_ids = model.generate(input_ids, max_new_tokens=142)
summary = tokenizer.decode(generated_ids, skip_special_tokens=True)
print(summary)
Accuracy
Compared against the PyTorch fp32 reference (teacher-forced with the beam-search reference's own output sequence) on a real article about the Eiffel Tower:
| Precision | Teacher-forced logits cosine sim. | Next-token argmax agreement |
|---|---|---|
| MLX fp32 | 1.0000001 | 100% |
| MLX fp16 (this release) | 0.99999356 | 100% |
Free-running greedy generation, compared against PyTorch's own greedy
(num_beams=1) output:
- PyTorch greedy: "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building. It is the tallest structure in Paris and the second tallest free-standing structure in France after the Millau Viaduct."
- MLX greedy: generates the exact same text as above.
Specs
| Item | Value |
|---|---|
| Base model | facebook/bart-large-cnn (BART-large, 406M params) |
| Precision | float16 |
| Framework | MLX (from-scratch bart_mlx.py, autoregressive decoding with KV cache) |
Notes
- This is a community conversion, not an official release from Meta.
- Security audit uses model-audit-lite
(see
SECURITY.mdfor details).
Security
Audited against its upstream with model-audit-lite: weight format, bundled code, and a machine-readable lineage (ML-BOM). Details, checksums and how to reproduce: SECURITY.md.