Skip to main content

Play international chess against AI opponents powered by local LLMs

Project description

LLMChess 训练 Pipeline 测试

本目录包含用于验证 LLM 训练 pipeline 的测试脚本和示例数据。

目录结构

LLMChess/
├── tests/
│   ├── __init__.py
│   └── test_pipeline.py    # 完整训练 pipeline 测试
├── data/
│   └── sample_train.json   # 示例训练数据
└── README.md               # 本文档

快速开始

运行测试

在 LLMChess 目录下执行:

python tests/test_pipeline.py

这将运行以下测试:

  1. 模型前向传播测试 - 验证 GPT2 模型的 forward pass
  2. 数据处理测试 - 验证文本清洗和 BPE 分词
  3. 训练步骤测试 - 验证单个训练步骤(forward、backward、optimizer step)
  4. 文本生成测试 - 验证贪婪解码生成
  5. 完整 Pipeline 测试 - 验证多步训练循环

准备训练数据

使用示例数据或准备您自己的训练数据:

# 示例数据位于
data/sample_train.json

# 数据格式
[
  {"text": "您的训练文本1"},
  {"text": "您的训练文本2"}
]

开始训练

使用示例数据训练模型:

from models.gpt2 import GPT2, GPTConfig
from data import TextDataset, BPETokenizer, collate_fn
from scripts import Trainer
from torch.utils.data import DataLoader

config = GPTConfig(
    vocab_size=10000,
    hidden_size=256,
    num_layers=4,
    num_heads=4
)

model = GPT2(config)
tokenizer = BPETokenizer()
dataset = TextDataset("data/sample_train.json", tokenizer)
dataloader = DataLoader(dataset, batch_size=2, collate_fn=collate_fn)

trainer = Trainer(model, dataloader)
trainer.train(num_epochs=10)

测试说明

测试脚本使用随机生成的数据进行快速验证,确保所有核心组件正常工作:

  • 模型初始化和前向传播
  • 损失计算和反向传播
  • 优化器更新
  • 文本生成解码

所有测试都可以在 CPU 上快速运行,不需要 GPU。

自定义测试

要测试自定义模型配置:

config = GPTConfig(
    vocab_size=5000,      # 词汇表大小
    hidden_size=128,      # 隐藏层维度
    num_layers=2,        # Transformer 层数
    num_heads=4,         # 注意力头数
    max_seq_length=512    # 最大序列长度
)
model = GPT2(config)

依赖

测试脚本依赖以下模块:

  • torch - PyTorch 深度学习框架
  • models.gpt2 - GPT2 模型实现
  • data - 数据处理模块
  • scripts - 训练脚本和工具

确保这些模块在您的 Python 环境中可用。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmchess-1.5.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llmchess-1.5.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file llmchess-1.5.0.tar.gz.

File metadata

  • Download URL: llmchess-1.5.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for llmchess-1.5.0.tar.gz
Algorithm Hash digest
SHA256 7557957b892e1e7a358a17b4f23fd6a7691bfe145817a338439e199a301f9e9c
MD5 f97fe3220a56cbf4c159045bef86a556
BLAKE2b-256 0152b335e224c6e962881d3afd3c2eaf4649e6cedda83d01d405e919a9db982c

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmchess-1.5.0.tar.gz:

Publisher: publish.yml on oemoem12/LLMChess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llmchess-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: llmchess-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for llmchess-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72a24fc40becbd3e6c3dff1761efdf995ef2e503702429acf1009217ddfa413d
MD5 d7fcd66aea4104abe418f544a48a41ee
BLAKE2b-256 27612aad6d4b06ab4de2697b092b2257131458f6160231f43fbf59e3fbfa103f

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmchess-1.5.0-py3-none-any.whl:

Publisher: publish.yml on oemoem12/LLMChess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page