Skip to main content

Gleeful Transformer

A Python library for training and running open-weight language models.

  • Use MCP to run training and evaluation jobs from your AI assistant.
  • Fine-tune chat models with LoRA, QLoRA, or full-model training.
  • Pretrain from scratch on your own text, with FSDP2 for multi-GPU runs.
  • Add RAG to your chats with Gleeful Search, which pulls in relevant passages from your documents.

MCP

Use the built-in Model Context Protocol (MCP) server to chat with a local model, evaluate it on a dataset, or fine-tune it.

Paste this prompt into your assistant for setup help.

Help me set up Gleeful Transformer MCP from https://github.com/EricFillion/gleefultransformer. Ask which MCP client I use and whether I want to chat with a local model, evaluate it on a dataset, or fine-tune it. Then guide me through setup and verify the connection by listing my registered models.

Manual setup · Connect a client

Install

Use Python 3.11 or later. On Linux or macOS, clone the repository and install it in a virtual environment.

git clone https://github.com/EricFillion/gleefultransformer.git
cd gleefultransformer
python3 -m venv .venv
. .venv/bin/activate
python -m pip install .

Chat

from gleefultransformer import CHATCallArgs, GleefulChat

chat = GleefulChat(model_name="HuggingFaceTB/SmolLM2-360M-Instruct")
messages = [{"role": "user", "content": "Hi"}]
args = CHATCallArgs(max_len=96, temp=0)

print(chat(messages, args=args).text)

Pass the same messages and settings to stream() to display the reply as it arrives.

for event in chat.stream(messages, args=args):
    if event.marker == "text":
        print(event.text, end="", flush=True)
print()

Chat guide · Inference arguments

Fine-tune

From the checkout root, create separate JSONL files for training, validation, and the final comparison. Create the quickstart datasets

from gleefultransformer import CHATTokArgs, GleefulChat, GleefulTrainArgs

chat = GleefulChat(model_name="HuggingFaceTB/SmolLM2-135M-Instruct")
tok_args = CHATTokArgs(max_len=128)
test_path = "outputs/fine-tune-data/test.jsonl"

baseline = chat.eval(test_path, tok_args=tok_args).loss
chat.train(
    "outputs/fine-tune-data/train.jsonl",
    args=GleefulTrainArgs(eval_steps=1),
    eval_path="outputs/fine-tune-data/validation.jsonl",
    tok_args=tok_args,
)
chat.save("outputs/fine-tuned-chat")

tuned = GleefulChat(model_name="outputs/fine-tuned-chat")
after_reload = tuned.eval(test_path, tok_args=tok_args).loss
print(f"Before training {baseline:.3f}, after reload {after_reload:.3f}")

The training guide covers evaluation, LoRA, QLoRA, and checkpoint resumption. Training guide · Training arguments · Databricks Dolly example

Pretrain with FSDP2

After installing, run this from the checkout root on a Linux machine with two NVIDIA GPUs that support BF16.

cd examples/pretraining/chat/common_corpus
python data.py
python tok.py
torchrun --standalone --nproc-per-node=2 train.py --fsdp_config fsdp2.json --precision bf16 --bs 2 --gas 4 \
  --token_budget 261120 --eval_steps 16 --checkpoint_steps 16 --save_model_path outputs/fsdp2

The consolidated model is saved to outputs/fsdp2 in the example directory. If NCCL stalls at startup on Runpod, retry with NCCL_P2P_DISABLE=1 before torchrun. Full example and troubleshooting

From the checkout root, install the search extra and create a sample passage.

python -m pip install '.[search]'
mkdir -p outputs
cat > outputs/passages.jsonl <<'JSONL'
{"text":"Titan is the largest moon orbiting Saturn.","metadata":{"source":"moon-guide"}}
JSONL
from gleefultransformer import (
    CHATCallArgs,
    GleefulChat,
    GleefulSearch,
    SearchCallArgs,
    SearchTrainArgs,
)

search = GleefulSearch()
search.train("outputs/passages.jsonl", args=SearchTrainArgs(out_dir="outputs/my-index"))

chat = GleefulChat(
    model_name="HuggingFaceTB/SmolLM2-360M-Instruct",
    gleeful_search=GleefulSearch(data_name="outputs/my-index"),
)
args = CHATCallArgs(max_len=96, search_args=SearchCallArgs(limit=1))
print(chat("What is Saturn's largest moon?", args=args).text)

search_result stream events include the retrieved text and its metadata. Search guide · Search example

Metadata

Release files for gleefultransformer 0.0.1

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

Source distribution (sdist)

Source distribution for gleefultransformer 0.0.1
File Size Uploaded Provenance Actions
gleefultransformer-0.0.1.tar.gz 74.9 kB Without provenance Details for gleefultransformer-0.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 174.8 kB

Release files / gleefultransformer-0.0.1.tar.gz

Download URL gleefultransformer-0.0.1.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
658bd7c650145b0a18af7d2c8e17ba7356e19a966716354c9a2663838fb1a67e
BLAKE2b-256 checksum
How to use checksums
aa4a51136407e6bee230de4040f8bce8eb8aa461b397ee4db489b3def4bd18a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / gleefultransformer-0.0.1-py3-none-any.whl

Download URL gleefultransformer-0.0.1-py3-none-any.whl
Size 99.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ef5ca0442012f76b9345c52b9818fd00c12d256dc85e8267738afbc04e4f2c4
BLAKE2b-256 checksum
How to use checksums
56f78adcecc874da882bc3e7e9a71cc5f080f2b739941b5b2b5ea8aed2de4479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for gleefultransformer 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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