Skip to main content

Anthracite 1.5.2

Anthracite is a compact PyTorch framework for training and fine-tuning text-generation and embedding models. This release unifies the public API, fixes version drift, hardens optional TPU execution, and makes multi-GPU training cover text and embedding objectives.

Recommended imports: from anthracite import train, finetune, load_model, generate, stream_text, embed, similarity, search.

Install

pip install -e .
# Optional Hugging Face datasets/tokenizers
pip install -e '.[hf]'

TPU support is optional. Install the torch_xla build matching your PyTorch version on a TPU host; otherwise Anthracite raises a typed TPUNotAvailableError rather than failing later in the training loop.

Quick start

from anthracite import train, load_model, generate

meta = train(
    model_name="MyGPT",
    dataset="data/train.jsonl",
    tokens="100M",
    params="20M",
    tokenizer="bundled",
    device="auto",
    output_dir="models/MyGPT",
)

model = load_model(meta["output_dir"], device="auto")
print(generate(model, "The future of open models is", max_new_tokens=80))

anthracite.interface.text.generate_text remains available for old code, but new code should use the flat top-level API. All saved model metadata and tokenizer manifests report version 1.5.2.

Stable generation API

max_new_tokens is preferred. The older max_tokens keyword is still accepted for compatibility; passing both raises an immediate, clear TypeError.

from anthracite import generate, stream_text

print(generate("models/MyGPT", "Hello", max_new_tokens=64, temperature=0.8, top_p=0.95))
print("".join(stream_text("models/MyGPT", "Write one sentence about GPUs.")))

Training and SFT

Anthracite accepts plain text, JSONL, lists of records, and supported Hugging Face datasets. Instruction, QA, ShareGPT, ChatML, OpenAI-style prompt/completion, and common instruction/input/output records are detected automatically.

from anthracite import train

train(
    model_name="SupportGPT",
    dataset="data/instructions.jsonl",
    objective="sft",
    sft_mask_input=True,
    tokens="50M",
    params="20M",
    context_length=512,
    batch_size="auto",
    device="auto",
    precision="auto",
    output_dir="models/SupportGPT",
)

Input masking means the model is optimized primarily on the answer tokens instead of learning to reproduce the prompt. For large Hugging Face datasets, streaming is enabled by default through hf_streaming=True.

Multi-GPU: what actually happens

Use device="multi-gpu" to explicitly request every visible CUDA GPU, or use device="auto" to select multi-GPU automatically when at least two devices are visible.

train(
    model_name="MultiGPU-GPT",
    dataset="data/train.jsonl",
    params="100M",
    tokens="1B",
    device="multi-gpu",
    batch_size="auto",
)

The single-process runtime uses torch.nn.DataParallel: each GPU receives a replica and a shard of the batch, gradients are gathered on the primary GPU, and gradient accumulation preserves the requested effective batch. The automatic batch planner uses the combined memory pool and scales the effective target with the GPU count. Text forward passes and embedding MLM/contrastive objectives are both dispatched through the parallel wrapper.

Checkpoints are saved from the original model, not from the wrapper, so they load normally on CPU, one GPU, or another multi-GPU machine. An explicit multi-GPU request never silently changes to TPU. For very large production jobs, multi-process DistributedDataParallel remains preferable, but this release provides a reliable no-launcher path.

TPU: safe execution and loss debugging

Use device="tpu", device="xla", or device="multi-tpu" only on a working XLA host. Anthracite performs one XLA optimizer step and one graph boundary per optimizer update, and supports torch_xla versions that expose either the native optimizer_step helper or only the optimizer itself.

If loss appears stuck, check the following before changing the learning rate:

  1. The dataset is non-empty and labels contain non-ignored targets.
  2. Contrastive training has a micro-batch of at least two.
  3. precision="bf16" or precision="auto" matches the TPU hardware.
  4. The token budget is large enough to produce real optimizer steps.
  5. Logs show increasing optimizer step, not only increasing micro-batches.

XLA does not expose CUDA-equivalent free-memory information, so TPU memory planning is deliberately conservative. Never mix arbitrary torch and torch_xla versions.

Fine-tuning and embeddings

from anthracite import finetune, embed, similarity, search

finetune(
    model="models/SupportGPT",
    dataset="data/new_instructions.jsonl",
    tokens="20M",
    output_dir="models/SupportGPT-v2",
)

encoder = "models/MyEmbedder"
vectors = embed(encoder, ["reset password", "track my order"])
print(vectors.shape)
print(similarity(encoder, "reset password", "forgot password"))
print(search(encoder, "where is my package?", ["order tracking", "refund policy"], top_k=1))

Tokenizers

Supported values include "auto", "bundled", a local directory or tokenizer.json, a Hugging Face repository such as "gpt2", or any object exposing encode() and decode(). The tokenizer is saved beside the model and checked against the model vocabulary during loading.

from anthracite import train

train(model_name="GPT2Tok", dataset="data.txt", tokenizer="gpt2", params="20M")
train(model_name="LocalTok", dataset="data.txt", tokenizer="./tokenizers/mytok", params="20M")

Validation before a long run

python -m compileall -q anthracite
python -c 'import anthracite; print(anthracite.__version__)'
python -m anthracite.cli --help

Start with a small smoke run first:

train(
    model_name="smoke",
    dataset=[{"text": "small training corpus " * 20}],
    tokens=10_000,
    params="500K",
    context_length=64,
    batch_size=2,
    device="cpu",
    precision="fp32",
    output_dir="models/smoke",
)

Common runtime causes are an incompatible tokenizer vocabulary, context length below 8, invalid attention dimensions, insufficient memory, or requesting an accelerator that PyTorch cannot see. Anthracite validates these conditions early and reports the correction.

License

MIT. See LICENSE.

Release files for anthracite 1.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anthracite 1.5.2
File Size Uploaded
anthracite-1.5.2.tar.gz 75.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anthracite 1.5.2
File Interpreter ABI Platform
anthracite-1.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 165.5 kB

Release files / anthracite-1.5.2.tar.gz

Download URL anthracite-1.5.2.tar.gz
Size 75.2 kB
Tags Source
SHA-256 checksum
How to use checksums
16b18ada1e9c8f371ec2817f00e791f8650f233864c399d53b2638dc4512b34b
BLAKE2b-256 checksum
How to use checksums
1a97863f17b742a62d21e37f7685680359b7920f005aa26e96104ad5ba04e882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / anthracite-1.5.2-py3-none-any.whl

Download URL anthracite-1.5.2-py3-none-any.whl
Size 90.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
345606032ad06abcdfc87882002d95f34d6ebfd547b32b3ead2f65f23bdd4235
BLAKE2b-256 checksum
How to use checksums
1680a401c283143a902886801cde81b9f4ec281e4e8ad48f107b2209e4b9d6de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release history Release notifications | RSS feed

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

This release

1.5.2 This release

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page