---
title: distilgpt2
canonical_url: "https://www.modelscope.cn/models/mlx-community/distilgpt2"
md_url: "https://www.modelscope.cn/models/mlx-community/distilgpt2.md"
repository: mlx-community/distilgpt2
last_updated: 2026-06-28
license: apache-2.0
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - gpt2
architectures:
  - GPT2LMHeadModel
base_model:
  - distilbert/distilgpt2
base_model_relation: finetune
parameters: 81.9M
tensor_type:
  - BF16
library_name:
  - mlx
  - safetensors
  - pytorch
frameworks:
  - pytorch
downloads: 8
stars: 0
tags:
  - mlx
---

# distilgpt2

> distilgpt2 - mlx-community 在 ModelScope 开源的模型。Full-precision (bfloat16) MLX conversion of distilbert/distilgpt2, produced with mlx-lm.

mlx-community/distilgpt2 是 ModelScope 魔搭社区上的 81.9M 参数text-generation模型，采用 apache-2.0 许可，基于 distilbert/distilgpt2 构建。

- **Repository**: mlx-community/distilgpt2
- **License**: apache-2.0
- **Tasks**: text-generation
- **Parameters**: 81.9M
- **Base model**: distilbert/distilgpt2
- **Tags**: mlx
- **Downloads**: 8
- **Stars**: 0
- **Last updated**: 2026-06-28

Source: https://www.modelscope.cn/models/mlx-community/distilgpt2

---

# distilgpt2 (MLX)

Full-precision (bfloat16) MLX conversion of [distilbert/distilgpt2](https://huggingface.co/distilbert/distilgpt2), produced with `mlx-lm`.

For Apple Silicon. Runs in `mlx-lm`, oMLX, or any MLX app.

This is a **base language model** (text continuation), not instruction-tuned. Prompt it with the start of a passage and sample with a non-zero temperature; greedy decoding on a question-style prompt tends to collapse into whitespace.

## Usage

```bash
pip install mlx-lm
```

```python
from mlx_lm import load, generate
from mlx_lm.sample_utils import make_sampler

model, tokenizer = load("mlx-community/distilgpt2")
sampler = make_sampler(temp=0.7)
print(generate(model, tokenizer, prompt="The history of the Roman Empire began when",
               max_tokens=80, sampler=sampler))
```

Or from the command line:

```bash
mlx_lm.generate --model mlx-community/distilgpt2 \
  --prompt "The history of the Roman Empire began when" --max-tokens 80 --temp 0.7
```

Refer to the original model card for architecture, training data, and intended use.

## Conversion check

Smoke-tested after conversion with a continuation prompt: coherent output, ~1700 tok/s generation, peak 0.18 GB on a Macbook Pro M5 Max 128GB 40 GPU.
