Skip to main content

Experiment framework for ML/LLM workflows with reproducible run artifacts.

Project description

ztxexp

PyPI version License: MIT Python Versions

ztxexp 是一个面向深度学习和大模型实验的抽象框架,目标是让实验迭代更快、更可复现。

问题

在真实项目里,实验常见痛点是:

  • 参数空间大,配置组合容易失控。
  • 并行执行后目录结构混乱,成功/失败难追溯。
  • 结果聚合脚本碎片化,清理成本高。

方案

ztxexp 提供四个核心抽象:

  1. ExpManager: 负责配置构建(gridvariantsmodifywhere)。
  2. ExpRunner: 负责执行调度(sequential / process_pool / joblib / dynamic)。
  3. ResultAnalyzer: 负责聚合与清理。
  4. ExperimentPipeline: 一体化入口,适合绝大多数场景。

v0.2 统一了 run 产物协议(schema v2):

  • config.json
  • run.json
  • metrics.json(可选)
  • artifacts/

成功判定规则:run.json.status == "succeeded"

5 分钟跑通

安装

pip install ztxexp

可选:启用 PyTorch 辅助工具。

pip install "ztxexp[torch]"

如果你要导出 Excel 透视表:

pip install "ztxexp[excel]"

最小示例

from ztxexp import ExperimentPipeline, RunContext


def exp_fn(ctx: RunContext):
    lr = ctx.config["lr"]
    model = ctx.config["model"]

    # 业务产物统一放 artifacts 目录
    (ctx.run_dir / "artifacts" / "info.txt").write_text(
        f"run={ctx.run_id}, model={model}, lr={lr}\n",
        encoding="utf-8",
    )

    # 返回 dict 会自动写入 metrics.json
    return {"score": round((1.0 - lr) + (0.05 if model == "tiny" else 0.02), 4)}


summary = (
    ExperimentPipeline("./results_demo", base_config={"seed": 42})
    .grid({"lr": [0.001, 0.01]})
    .variants([{"model": "tiny"}, {"model": "base"}])
    .exclude_completed()
    .run(exp_fn, mode="sequential")
)

print(summary)

聚合结果

from ztxexp import ResultAnalyzer

analyzer = ResultAnalyzer("./results_demo")
df = analyzer.to_dataframe(statuses=("succeeded",))
print(df[["run_id", "model", "lr", "score"]])
analyzer.to_csv("./results_demo/summary.csv", sort_by=["model", "lr"])

常见坑

  1. 返回值不是 dict | None 会被判定为失败,并写入 error.log

  2. 仍按旧版 _SUCCESS 判断成功 v0.2 不再使用 _SUCCESS,以 run.json 为准。

  3. 直接把大文件写在 run 根目录 建议统一放到 artifacts/,便于后续清理和归档。

  4. dynamic 模式用于生产实时场景 dynamic 是实验特性(experimental),更适合离线批任务。

API 导航

贡献

欢迎提交 Issue 或 PR:

许可证

MIT License

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

ztxexp-0.2.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

ztxexp-0.2.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file ztxexp-0.2.0.tar.gz.

File metadata

  • Download URL: ztxexp-0.2.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for ztxexp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 01b1744f5d19bd5c2b5089a7bc94c2652b3a29080e1d0e08732de4a40f3d46e6
MD5 a9c2d62fa052151f58694f2a9bc98c8e
BLAKE2b-256 40feff6a9eccd19b78b414eec7077f94533a5fd510712c01902b814a72f121e1

See more details on using hashes here.

File details

Details for the file ztxexp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ztxexp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for ztxexp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f66c04a6d16005231df2d480ddf5345d75a657065ecddc3dba87f6a1cd6546
MD5 e543d9a27650b19b257e7797ddcdcaea
BLAKE2b-256 44124d758e29d49e9bef852e60005b190ccb6fdca06093578b9874885d62a8d4

See more details on using hashes here.

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