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
这将运行以下测试:
- 模型前向传播测试 - 验证 GPT2 模型的 forward pass
- 数据处理测试 - 验证文本清洗和 BPE 分词
- 训练步骤测试 - 验证单个训练步骤(forward、backward、optimizer step)
- 文本生成测试 - 验证贪婪解码生成
- 完整 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7557957b892e1e7a358a17b4f23fd6a7691bfe145817a338439e199a301f9e9c
|
|
| MD5 |
f97fe3220a56cbf4c159045bef86a556
|
|
| BLAKE2b-256 |
0152b335e224c6e962881d3afd3c2eaf4649e6cedda83d01d405e919a9db982c
|
Provenance
The following attestation bundles were made for llmchess-1.5.0.tar.gz:
Publisher:
publish.yml on oemoem12/LLMChess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llmchess-1.5.0.tar.gz -
Subject digest:
7557957b892e1e7a358a17b4f23fd6a7691bfe145817a338439e199a301f9e9c - Sigstore transparency entry: 2255193347
- Sigstore integration time:
-
Permalink:
oemoem12/LLMChess@71d77f99c9a06c79c00e866af340109fec55bfbb -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/oemoem12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71d77f99c9a06c79c00e866af340109fec55bfbb -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72a24fc40becbd3e6c3dff1761efdf995ef2e503702429acf1009217ddfa413d
|
|
| MD5 |
d7fcd66aea4104abe418f544a48a41ee
|
|
| BLAKE2b-256 |
27612aad6d4b06ab4de2697b092b2257131458f6160231f43fbf59e3fbfa103f
|
Provenance
The following attestation bundles were made for llmchess-1.5.0-py3-none-any.whl:
Publisher:
publish.yml on oemoem12/LLMChess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llmchess-1.5.0-py3-none-any.whl -
Subject digest:
72a24fc40becbd3e6c3dff1761efdf995ef2e503702429acf1009217ddfa413d - Sigstore transparency entry: 2255193351
- Sigstore integration time:
-
Permalink:
oemoem12/LLMChess@71d77f99c9a06c79c00e866af340109fec55bfbb -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/oemoem12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@71d77f99c9a06c79c00e866af340109fec55bfbb -
Trigger Event:
release
-
Statement type: