TinyExp 0.1.4__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tinyexp-0.1.4 → tinyexp-0.2.1}/.gitignore +7 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/CHANGELOG.md +20 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/CONTRIBUTING.md +44 -4
- {tinyexp-0.1.4 → tinyexp-0.2.1}/Makefile +41 -5
- tinyexp-0.2.1/PKG-INFO +163 -0
- tinyexp-0.2.1/README.md +71 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/pyproject.toml +27 -1
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tests/conftest.py +7 -0
- tinyexp-0.2.1/tests/dataset/test_sampler.py +123 -0
- tinyexp-0.2.1/tests/examples/test_examples_help_smoke.py +225 -0
- tinyexp-0.2.1/tests/examples/test_examples_run.py +165 -0
- tinyexp-0.2.1/tests/examples/test_minimind_dpo_exp.py +21 -0
- tinyexp-0.2.1/tests/examples/test_minimind_grpo_exp.py +16 -0
- tinyexp-0.2.1/tests/examples/test_minimind_lora_exp.py +41 -0
- tinyexp-0.2.1/tests/examples/test_minimind_ppo_exp.py +120 -0
- tinyexp-0.2.1/tests/examples/test_minimind_sft_exp.py +27 -0
- tinyexp-0.2.1/tests/examples/test_mnist_exp.py +173 -0
- tinyexp-0.2.1/tests/examples/test_pi_exp.py +31 -0
- tinyexp-0.2.1/tests/examples/test_resnet_exp.py +358 -0
- tinyexp-0.2.1/tests/examples/test_vit_tp_exp.py +285 -0
- tinyexp-0.2.1/tests/examples/test_wan21_lora_exp.py +96 -0
- tinyexp-0.2.1/tests/scripts/test_run_with_ray_cluster.py +140 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tests/scripts/test_run_with_redis.py +154 -116
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tests/test_ray_multinode_integration.py +8 -1
- tinyexp-0.2.1/tests/test_tinyexp.py +166 -0
- tinyexp-0.2.1/tests/test_tinyexp_artifacts.py +314 -0
- tinyexp-0.2.1/tests/tiny_engine/test_cpu_accelerator_unit.py +188 -0
- tinyexp-0.2.1/tests/tiny_engine/test_ddp_accelerator.py +72 -0
- tinyexp-0.2.1/tests/tiny_engine/test_ddp_fsdp_accelerator_unit.py +206 -0
- tinyexp-0.2.1/tests/tiny_engine/test_hf_accelerator_unit.py +29 -0
- tinyexp-0.2.1/tests/utils/test_ray_utils_unit.py +652 -0
- tinyexp-0.1.4/tests/utils/test_redis_utils_unit.py → tinyexp-0.2.1/tests/utils/test_redis_utils.py +271 -156
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/__init__.py +128 -10
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/cli/run_with_ray_cluster.py +10 -2
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/cli/run_with_redis.py +81 -21
- tinyexp-0.2.1/tinyexp/dataset/__init__.py +13 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/dataset/fake_dataloader.py +7 -1
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/dataset/sampler.py +11 -0
- tinyexp-0.2.1/tinyexp/examples/README.md +40 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/train/circle/circle.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/train/cross/cross.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/train/diamond/diamond.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/train/square/square.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/train/triangle/triangle.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/val/circle/circle.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/val/cross/cross.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/val/diamond/diamond.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/val/square/square.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/imagenet_smoke/val/triangle/triangle.jpg +0 -0
- tinyexp-0.2.1/tinyexp/examples/assets/minimind/dpo_smoke.jsonl +4 -0
- tinyexp-0.2.1/tinyexp/examples/assets/minimind/rlaif_smoke.jsonl +4 -0
- tinyexp-0.2.1/tinyexp/examples/assets/minimind/sft_smoke.jsonl +4 -0
- tinyexp-0.2.1/tinyexp/examples/assets/minimind/tokenizer.json +31191 -0
- tinyexp-0.2.1/tinyexp/examples/assets/minimind/tokenizer_config.json +335 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/LICENSE +201 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/__init__.py +5 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/dataset.py +162 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/minimind_dpo_exp.py +154 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/minimind_grpo_exp.py +312 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/minimind_lora_exp.py +151 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/minimind_ppo_exp.py +348 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/minimind_sft_exp.py +202 -0
- tinyexp-0.2.1/tinyexp/examples/minimind/model.py +413 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/examples/mnist_exp.py +85 -51
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/examples/pi_exp.py +17 -15
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/examples/resnet_exp.py +145 -62
- tinyexp-0.2.1/tinyexp/examples/vit_tp_exp.py +1363 -0
- tinyexp-0.2.1/tinyexp/examples/wan21_lora_exp.py +356 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/exceptions.py +17 -1
- tinyexp-0.2.1/tinyexp/exp_mixins/__init__.py +27 -0
- tinyexp-0.2.1/tinyexp/exp_mixins/basic_mixins.py +739 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/__init__.py +6 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/__init__.py +31 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/base_accelerator.py +309 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/tiny_engine/accelerator/cpu_accelerator.py +32 -14
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/ddp_accelerator.py +140 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/fsdp_accelerator.py +233 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/hf_accelerator.py +63 -0
- tinyexp-0.2.1/tinyexp/tiny_engine/accelerator/tp_accelerator.py +148 -0
- tinyexp-0.2.1/tinyexp/utils/__init__.py +7 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/utils/log_utils.py +7 -1
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/utils/model_utils.py +5 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/utils/ray_utils.py +8 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/utils/redis_utils.py +68 -2
- tinyexp-0.1.4/PKG-INFO +0 -317
- tinyexp-0.1.4/README.md +0 -251
- tinyexp-0.1.4/tests/dataset/test_sampler.py +0 -180
- tinyexp-0.1.4/tests/examples/test_cli_overrides.py +0 -40
- tinyexp-0.1.4/tests/examples/test_mnist_exp_run.py +0 -115
- tinyexp-0.1.4/tests/examples/test_mnist_exp_unit.py +0 -153
- tinyexp-0.1.4/tests/examples/test_pi_exp_run.py +0 -101
- tinyexp-0.1.4/tests/examples/test_resnet_exp_run.py +0 -622
- tinyexp-0.1.4/tests/scripts/test_run_with_ray_cluster.py +0 -228
- tinyexp-0.1.4/tests/test_tinyexp.py +0 -189
- tinyexp-0.1.4/tests/test_tinyexp_artifacts.py +0 -284
- tinyexp-0.1.4/tests/tine_engine/test_accelerator_protocol.py +0 -26
- tinyexp-0.1.4/tests/tine_engine/test_cpu_accelerator.py +0 -89
- tinyexp-0.1.4/tests/tine_engine/test_cpu_accelerator_unit.py +0 -78
- tinyexp-0.1.4/tests/tine_engine/test_ddp_accelerator.py +0 -105
- tinyexp-0.1.4/tests/tine_engine/test_ddp_accelerator_unit.py +0 -35
- tinyexp-0.1.4/tests/utils/test_ray_utils_unit.py +0 -1091
- tinyexp-0.1.4/tests/utils/test_redis_utils.py +0 -29
- tinyexp-0.1.4/tinyexp/dataset/__init__.py +0 -7
- tinyexp-0.1.4/tinyexp/exp_mixins/__init__.py +0 -3
- tinyexp-0.1.4/tinyexp/exp_mixins/basic_mixins.py +0 -442
- tinyexp-0.1.4/tinyexp/tiny_engine/accelerator/__init__.py +0 -12
- tinyexp-0.1.4/tinyexp/tiny_engine/accelerator/base_accelerator.py +0 -133
- tinyexp-0.1.4/tinyexp/tiny_engine/accelerator/ddp_accelerator.py +0 -166
- tinyexp-0.1.4/tinyexp/tiny_engine/accelerator/hf_accelerator.py +0 -41
- tinyexp-0.1.4/tinyexp/utils/__init__.py +0 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/LICENSE +0 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tests/utils/test_log_utils.py +0 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tests/utils/test_model_utils.py +0 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/cli/__init__.py +0 -0
- {tinyexp-0.1.4 → tinyexp-0.2.1}/tinyexp/examples/__init__.py +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
docs/source
|
|
2
2
|
|
|
3
|
+
# macOS metadata
|
|
4
|
+
.DS_Store
|
|
5
|
+
**/.DS_Store
|
|
6
|
+
|
|
3
7
|
# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
|
|
4
8
|
|
|
5
9
|
# Byte-compiled / optimized / DLL files
|
|
@@ -152,3 +156,6 @@ wandb/
|
|
|
152
156
|
|
|
153
157
|
# Local/private launch adapters and machine-specific scripts.
|
|
154
158
|
local/
|
|
159
|
+
|
|
160
|
+
# Generated from the local virtual environment.
|
|
161
|
+
pyrightconfig.json
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.1] - 2026-12-05
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added mixed-precision training across accelerators, FSDP support for the ResNet recipe, and a tensor-parallel DeiT-S recipe (#30).
|
|
8
|
+
- Added MiniMind recipes for SFT, LoRA, DPO, PPO, and GRPO, plus a Wan 2.1 LoRA video training recipe (#36).
|
|
9
|
+
- Added Trackio and SwanLab experiment tracking and SOCKS proxy support for the SwanLab extra (#33).
|
|
10
|
+
- Bundled a synthetic ImageNet dataset for CPU smoke runs.
|
|
11
|
+
- Added Redis authentication and bound the Ray dashboard to the loopback interface by default (#34).
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Reorganized the README around training tasks and expanded the experiment, launcher, and accelerator documentation (#35).
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Bound NCCL collectives to rank devices and applied autocast in `prepare_model` for mixed-precision runs.
|
|
20
|
+
- Hardened config, checkpoint, and launcher handling and restored Python 3.9 configuration support for the tensor-parallel ViT example.
|
|
21
|
+
- Logged tracker metrics at `global_step`, named tracker runs after `exp_name`, and flattened nested SwanLab settings for the local dashboard.
|
|
22
|
+
|
|
3
23
|
## [0.1.4] - 2026-09-05
|
|
4
24
|
|
|
5
25
|
|
|
@@ -62,13 +62,30 @@ git clone git@github.com:YOUR_NAME/TinyExp.git
|
|
|
62
62
|
cd TinyExp
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
Install the core environment and pre-commit hooks:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
make install
|
|
68
|
+
make install
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
`make install` preserves any optional accelerator packages already selected for the machine. For a fresh test
|
|
72
|
+
environment, install the `vit` and `video` extras with automatic PyTorch backend selection.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
make install-pytorch EXTRAS=vit,video
|
|
76
|
+
source .venv/bin/activate
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For a preselected CUDA, ROCm, or vendor build, use `make install` (or `make install-without-pytorch`) and install
|
|
80
|
+
`torch`, `torchvision`, and `accelerate` together for that backend. Ordinary `uv run` keeps these optional packages;
|
|
81
|
+
you do not need to repeat `--no-sync`. Avoid `uv sync` without `--inexact` in that environment. For Ray, launch with
|
|
82
|
+
the active environment’s `python`; see [backend setup](docs/running-modes.md#common-requirements) and
|
|
83
|
+
[Ray’s interaction with `uv run`](docs/running-modes.md#local-ray-workers).
|
|
84
|
+
|
|
85
|
+
If the project environment already has a compatible PyTorch stack, add the example extras for the test suite with
|
|
86
|
+
`uv pip install --python .venv -e '.[vit,video]'`. This keeps compatible installed builds.
|
|
87
|
+
|
|
88
|
+
4. If you set up the environment without `make install`, install the pre-commit hooks separately:
|
|
72
89
|
|
|
73
90
|
```bash
|
|
74
91
|
uv run pre-commit install
|
|
@@ -90,7 +107,15 @@ Now you can make your changes locally.
|
|
|
90
107
|
make check
|
|
91
108
|
```
|
|
92
109
|
|
|
93
|
-
|
|
110
|
+
8. Run the full suite without coverage during development:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
make test-fast
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This runs example help and documentation checks, Ray integration tests, and the remaining tests in three parallel
|
|
117
|
+
pytest sessions. The GPU DDP test skips when fewer than two CUDA GPUs are available. For coverage, run the same
|
|
118
|
+
groups and combine their results into `coverage.xml` with:
|
|
94
119
|
|
|
95
120
|
```bash
|
|
96
121
|
make test
|
|
@@ -116,6 +141,21 @@ git push origin name-of-your-bugfix-or-feature
|
|
|
116
141
|
|
|
117
142
|
11. Submit a pull request through the GitHub website.
|
|
118
143
|
|
|
144
|
+
## Build and release
|
|
145
|
+
|
|
146
|
+
Build the documentation strictly and build the package:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
make docs-test
|
|
150
|
+
make build
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Maintainers can cut a release by setting `VERSION` to the version being released, for example:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
make release VERSION=0.0.4
|
|
157
|
+
```
|
|
158
|
+
|
|
119
159
|
# Pull Request Guidelines
|
|
120
160
|
|
|
121
161
|
Before you submit a pull request, check that it meets these guidelines:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
EXTRAS ?= pytorch
|
|
2
|
+
|
|
1
3
|
.PHONY: install
|
|
2
4
|
install: ## Install core dependencies while preserving machine-selected optional packages
|
|
3
5
|
@echo "🚀 Creating virtual environment using uv"
|
|
@@ -5,13 +7,17 @@ install: ## Install core dependencies while preserving machine-selected optional
|
|
|
5
7
|
@uv run pre-commit install
|
|
6
8
|
|
|
7
9
|
.PHONY: install-pytorch
|
|
8
|
-
install-pytorch: ## Install
|
|
9
|
-
@uv
|
|
10
|
+
install-pytorch: install-without-pytorch ## Install PyTorch for this machine, with optional EXTRAS=video,vit
|
|
11
|
+
@uv pip install --python "$${UV_PROJECT_ENVIRONMENT:-.venv}" --torch-backend auto -e '.[$(EXTRAS)]'
|
|
10
12
|
|
|
11
13
|
.PHONY: install-without-pytorch
|
|
12
14
|
install-without-pytorch: ## Install core dependencies while preserving machine-selected accelerator packages
|
|
13
15
|
@uv sync --locked --no-extra pytorch --inexact
|
|
14
16
|
|
|
17
|
+
.PHONY: generate-pyrightconfig
|
|
18
|
+
generate-pyrightconfig: ## Generate pyrightconfig.json from .venv Python
|
|
19
|
+
@uv run python scripts/generate_pyrightconfig.py
|
|
20
|
+
|
|
15
21
|
.PHONY: check
|
|
16
22
|
check: ## Run code quality tools.
|
|
17
23
|
@echo "🚀 Checking lock file consistency with 'pyproject.toml'"
|
|
@@ -21,10 +27,40 @@ check: ## Run code quality tools.
|
|
|
21
27
|
# @echo "🚀 Static type checking: Running mypy"
|
|
22
28
|
# @uv run mypy
|
|
23
29
|
|
|
30
|
+
test_shards := test-fast-help test-fast-ray test-fast-rest
|
|
31
|
+
test_help_file := tests/examples/test_examples_help_smoke.py
|
|
32
|
+
test_ray_files := tests/test_ray_multinode_integration.py tests/tiny_engine/test_ddp_accelerator.py
|
|
33
|
+
test_ray_redis := tests/utils/test_redis_utils.py::test_redis_cluster_manager_with_real_redis_on_ray
|
|
34
|
+
|
|
35
|
+
test_coverage_args := --no-cov
|
|
36
|
+
ifneq ($(test_coverage_dir),)
|
|
37
|
+
test_coverage_env = COVERAGE_FILE="$(test_coverage_dir)/.coverage.$@"
|
|
38
|
+
test_coverage_args := --cov --cov-config=pyproject.toml --cov-report=
|
|
39
|
+
endif
|
|
40
|
+
test_pytest = $(test_coverage_env) RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 uv run python -m pytest -p no:cacheprovider $(test_coverage_args)
|
|
41
|
+
|
|
42
|
+
.PHONY: test-fast $(test_shards)
|
|
43
|
+
test-fast: ## Run the full test suite in parallel without coverage
|
|
44
|
+
@$(MAKE) -j3 $(test_shards)
|
|
45
|
+
|
|
46
|
+
test-fast-help:
|
|
47
|
+
@$(test_pytest) $(test_help_file)
|
|
48
|
+
|
|
49
|
+
# Keep the Ray integration tests in one pytest session so DDP and Redis share their fixture.
|
|
50
|
+
test-fast-ray:
|
|
51
|
+
@$(test_pytest) $(test_ray_files) $(test_ray_redis)
|
|
52
|
+
|
|
53
|
+
test-fast-rest:
|
|
54
|
+
@$(test_pytest) $(addprefix --ignore=,$(test_help_file) $(test_ray_files)) \
|
|
55
|
+
--deselect=$(test_ray_redis)
|
|
56
|
+
|
|
24
57
|
.PHONY: test
|
|
25
|
-
test: ##
|
|
26
|
-
@
|
|
27
|
-
|
|
58
|
+
test: ## Run the full test suite in parallel and write coverage.xml
|
|
59
|
+
@coverage_dir=$$(mktemp -d) && \
|
|
60
|
+
trap 'rm -rf "$$coverage_dir"' EXIT && \
|
|
61
|
+
$(MAKE_COMMAND) -j3 $(test_shards) test_coverage_dir="$$coverage_dir" && \
|
|
62
|
+
uv run coverage combine --rcfile=pyproject.toml $(foreach shard,$(test_shards),"$$coverage_dir/.coverage.$(shard)") && \
|
|
63
|
+
uv run coverage xml --rcfile=pyproject.toml
|
|
28
64
|
|
|
29
65
|
.PHONY: build
|
|
30
66
|
build: clean-build ## Build wheel file
|
tinyexp-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: TinyExp
|
|
3
|
+
Version: v0.2.1
|
|
4
|
+
Summary: A minimalist Python project for deep learning experiment management. It uses Ray for core distributed environment and backend setup, and provides basic, no-frills tracking for models, optimizers, and LR schedulers.
|
|
5
|
+
Project-URL: Homepage, https://zengarden.github.io/TinyExp/
|
|
6
|
+
Project-URL: Repository, https://github.com/zengarden/TinyExp
|
|
7
|
+
Project-URL: Documentation, https://zengarden.github.io/TinyExp/
|
|
8
|
+
Author-email: Zeming LI <zane.li@connect.ust.hk>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2025 Zeming LI
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: python
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
43
|
+
Requires-Python: <4.0,>=3.9
|
|
44
|
+
Requires-Dist: hydra-core
|
|
45
|
+
Requires-Dist: loguru
|
|
46
|
+
Requires-Dist: loguru>=0.7.3
|
|
47
|
+
Requires-Dist: numpy; python_version < '3.14'
|
|
48
|
+
Requires-Dist: numpy>=2.3.2; python_version >= '3.14'
|
|
49
|
+
Requires-Dist: omegaconf
|
|
50
|
+
Requires-Dist: psutil
|
|
51
|
+
Requires-Dist: ray; python_version >= '3.10'
|
|
52
|
+
Requires-Dist: ray<2.52; python_version < '3.10'
|
|
53
|
+
Requires-Dist: redis
|
|
54
|
+
Requires-Dist: rpds-py>=0.26; python_version >= '3.14'
|
|
55
|
+
Requires-Dist: tabulate
|
|
56
|
+
Requires-Dist: tqdm
|
|
57
|
+
Requires-Dist: trackio; python_version >= '3.10'
|
|
58
|
+
Requires-Dist: wandb
|
|
59
|
+
Provides-Extra: pytorch
|
|
60
|
+
Requires-Dist: accelerate; extra == 'pytorch'
|
|
61
|
+
Requires-Dist: pillow>=11.3; (python_version >= '3.14') and extra == 'pytorch'
|
|
62
|
+
Requires-Dist: torch; (python_version < '3.14') and extra == 'pytorch'
|
|
63
|
+
Requires-Dist: torch>=2.13; (python_version >= '3.14') and extra == 'pytorch'
|
|
64
|
+
Requires-Dist: torchvision; (python_version < '3.14') and extra == 'pytorch'
|
|
65
|
+
Requires-Dist: torchvision>=0.28; (python_version >= '3.14') and extra == 'pytorch'
|
|
66
|
+
Provides-Extra: swanlab
|
|
67
|
+
Requires-Dist: pysocks; extra == 'swanlab'
|
|
68
|
+
Requires-Dist: swanlab>=0.10.6; extra == 'swanlab'
|
|
69
|
+
Provides-Extra: video
|
|
70
|
+
Requires-Dist: accelerate; extra == 'video'
|
|
71
|
+
Requires-Dist: diffusers>=0.34; extra == 'video'
|
|
72
|
+
Requires-Dist: ftfy; extra == 'video'
|
|
73
|
+
Requires-Dist: imageio[ffmpeg]; extra == 'video'
|
|
74
|
+
Requires-Dist: peft>=0.15; extra == 'video'
|
|
75
|
+
Requires-Dist: pillow>=11.3; (python_version >= '3.14') and extra == 'video'
|
|
76
|
+
Requires-Dist: sentencepiece; extra == 'video'
|
|
77
|
+
Requires-Dist: torch; (python_version < '3.14') and extra == 'video'
|
|
78
|
+
Requires-Dist: torch>=2.1; extra == 'video'
|
|
79
|
+
Requires-Dist: torch>=2.13; (python_version >= '3.14') and extra == 'video'
|
|
80
|
+
Requires-Dist: torchvision; (python_version < '3.14') and extra == 'video'
|
|
81
|
+
Requires-Dist: torchvision>=0.28; (python_version >= '3.14') and extra == 'video'
|
|
82
|
+
Requires-Dist: transformers>=4.44.2; extra == 'video'
|
|
83
|
+
Provides-Extra: vit
|
|
84
|
+
Requires-Dist: accelerate; extra == 'vit'
|
|
85
|
+
Requires-Dist: pillow>=11.3; (python_version >= '3.14') and extra == 'vit'
|
|
86
|
+
Requires-Dist: timm>=1.0; extra == 'vit'
|
|
87
|
+
Requires-Dist: torch; (python_version < '3.14') and extra == 'vit'
|
|
88
|
+
Requires-Dist: torch>=2.13; (python_version >= '3.14') and extra == 'vit'
|
|
89
|
+
Requires-Dist: torchvision; (python_version < '3.14') and extra == 'vit'
|
|
90
|
+
Requires-Dist: torchvision>=0.28; (python_version >= '3.14') and extra == 'vit'
|
|
91
|
+
Description-Content-Type: text/markdown
|
|
92
|
+
|
|
93
|
+
<a name="tinyexp"></a>
|
|
94
|
+
|
|
95
|
+
# TinyExp — Self-contained examples you can learn from and run with one command.
|
|
96
|
+
|
|
97
|
+
Each `*_exp.py` file keeps the run commands, configuration, and training loop together, as in the [MNIST example](tinyexp/examples/mnist_exp.py).
|
|
98
|
+
Start on a CPU or a single GPU, then scale your research experiments to [multi-node training](docs/running-modes.md#static-ray-cluster).
|
|
99
|
+
For example, [DeiT-S](docs/vit_tp.md#cross-check-record) reached 79.84% top-1 accuracy on ImageNet after training from scratch for 17h 56m on a single node with eight H200 GPUs.
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
<details>
|
|
104
|
+
|
|
105
|
+
<summary>Preview a bundled Wan training clip</summary>
|
|
106
|
+
|
|
107
|
+

|
|
108
|
+
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
<a name="pick-a-task"></a><a name="example-experiments"></a>
|
|
112
|
+
|
|
113
|
+
## Run a recipe
|
|
114
|
+
|
|
115
|
+
| Task | Runnable examples | Hardware to start with |
|
|
116
|
+
| :--- | :--- | :--- |
|
|
117
|
+
| Image classification | [MNIST](#try-mnist-on-cpu) · [ResNet-50 (shapes)](docs/getting-started.md#try-resnet-50-without-imagenet) · [ResNet-50 (ImageNet)](tinyexp/examples/resnet_exp.py) · [DeiT-S](docs/vit_tp.md#usage) | CPU for MNIST and shapes; GPUs for the full ImageNet recipes |
|
|
118
|
+
| Language model fine-tuning & alignment | MiniMind-3 Dense (64M): [SFT](docs/getting-started.md#fine-tune-minimind-on-one-gpu) · [LoRA](tinyexp/examples/minimind/minimind_lora_exp.py) · [DPO](tinyexp/examples/minimind/minimind_dpo_exp.py) · [GRPO](tinyexp/examples/minimind/minimind_grpo_exp.py) · [PPO](tinyexp/examples/minimind/minimind_ppo_exp.py) | One BF16-capable CUDA GPU |
|
|
119
|
+
| Video generation | [Wan 2.1 T2V 1.3B (LoRA)](tinyexp/examples/wan21_lora_exp.py) | One BF16-capable CUDA GPU |
|
|
120
|
+
|
|
121
|
+
**Read a minimal trainer:** [MNIST](tinyexp/examples/mnist_exp.py) shows training, evaluation, and checkpoint resume in one file; [MiniMind SFT](tinyexp/examples/minimind/minimind_sft_exp.py) shows the loop for supervised fine-tuning on chat data.
|
|
122
|
+
|
|
123
|
+
[All recipes and hardware requirements](tinyexp/examples/README.md) · [Distributed Monte Carlo π on CPU](tinyexp/examples/pi_exp.py)
|
|
124
|
+
|
|
125
|
+
## Which recipe should I try?
|
|
126
|
+
|
|
127
|
+
<a name="image-classification"></a>**Image classification.** Use the ten bundled shapes to check a full training run without a dataset download. Choose MNIST to measure accuracy on held-out digits, or DeiT-S to compare tensor and data parallelism on ImageNet.
|
|
128
|
+
|
|
129
|
+
<a name="language-model-fine-tuning-and-alignment"></a>**Language models.** Start with SFT to fine-tune on four example chats and save a checkpoint. Choose LoRA to train and merge a small adapter, DPO if you have preferred and rejected replies, or GRPO/PPO to train with a reward model.
|
|
130
|
+
|
|
131
|
+
<a name="video-generation"></a>**Video generation.** Fine-tune Wan 2.1 with LoRA on four synthetic clips, or supply your own clips and captions in a `video,prompt` CSV. Sample the base model and the adapter with the same prompt and seed to compare their MP4 outputs.
|
|
132
|
+
|
|
133
|
+
**Planned recipes:** image generation and image editing, with small runs for consumer GPUs.
|
|
134
|
+
|
|
135
|
+
<a name="quick-start-1-minute"></a><a name="option-a-install-with-pip-and-run-the-bundled-example"></a>
|
|
136
|
+
|
|
137
|
+
## Try MNIST on CPU
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install "tinyexp[pytorch]"
|
|
141
|
+
python -m tinyexp.examples.mnist_exp
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
MNIST downloads on the first run. After three epochs, `./output/mnist_exp/log.txt` shows the test accuracy and
|
|
145
|
+
`best.ckpt` in the same directory holds the best model. See the guide to
|
|
146
|
+
<a name="option-b-run-the-bundled-example-from-source-for-development"></a>[install from source](docs/getting-started.md#from-source),
|
|
147
|
+
<a name="common-commands"></a><a name="run-and-inspect-an-experiment"></a>[inspect or override settings and evaluate a checkpoint](docs/getting-started.md#run-and-inspect-an-experiment).
|
|
148
|
+
|
|
149
|
+
## Documentation
|
|
150
|
+
|
|
151
|
+
- <a name="why-tinyexp"></a>**Why TinyExp:** [project overview](docs/index.md),
|
|
152
|
+
<a name="design-philosophy"></a>[design philosophy](docs/philosophy.md), and
|
|
153
|
+
<a name="how-it-works"></a>[how an experiment works](docs/getting-started.md#how-it-works).
|
|
154
|
+
- <a name="choose-how-workers-are-created"></a>**Run experiments:** [launcher choices and environment requirements](docs/running-modes.md#mode-matrix), [Redis and experiment tracking](docs/running-modes.md#optional-services), and [Redis ownership in multi-node jobs](docs/running-modes.md#redis-helper-lifecycle-in-multi-node-jobs).
|
|
155
|
+
- **Write your own:** [example catalog and run instructions](tinyexp/examples/README.md), [API reference](docs/modules.md), and
|
|
156
|
+
<a name="codex-skill"></a>[TinyExp agent skill](SKILL.md) ([setup](docs/index.md#use-the-tinyexp-agent-skill)).
|
|
157
|
+
- <a name="development"></a>**Develop TinyExp:** [environment setup, checks, and tests](CONTRIBUTING.md#get-started) and [building the docs, package, and releases](CONTRIBUTING.md#build-and-release).
|
|
158
|
+
|
|
159
|
+
[Documentation site](https://zengarden.github.io/TinyExp/) ·
|
|
160
|
+
<a name="contributing"></a>[Contributing: issues and PRs welcome](CONTRIBUTING.md) · <a name="license"></a>[MIT License](LICENSE)
|
|
161
|
+
|
|
162
|
+
[](https://github.com/zengarden/tinyexp/actions/workflows/main.yml)
|
|
163
|
+
[](https://codecov.io/gh/zengarden/tinyexp)
|
tinyexp-0.2.1/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<a name="tinyexp"></a>
|
|
2
|
+
|
|
3
|
+
# TinyExp — Self-contained examples you can learn from and run with one command.
|
|
4
|
+
|
|
5
|
+
Each `*_exp.py` file keeps the run commands, configuration, and training loop together, as in the [MNIST example](tinyexp/examples/mnist_exp.py).
|
|
6
|
+
Start on a CPU or a single GPU, then scale your research experiments to [multi-node training](docs/running-modes.md#static-ray-cluster).
|
|
7
|
+
For example, [DeiT-S](docs/vit_tp.md#cross-check-record) reached 79.84% top-1 accuracy on ImageNet after training from scratch for 17h 56m on a single node with eight H200 GPUs.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
<details>
|
|
12
|
+
|
|
13
|
+
<summary>Preview a bundled Wan training clip</summary>
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
</details>
|
|
18
|
+
|
|
19
|
+
<a name="pick-a-task"></a><a name="example-experiments"></a>
|
|
20
|
+
|
|
21
|
+
## Run a recipe
|
|
22
|
+
|
|
23
|
+
| Task | Runnable examples | Hardware to start with |
|
|
24
|
+
| :--- | :--- | :--- |
|
|
25
|
+
| Image classification | [MNIST](#try-mnist-on-cpu) · [ResNet-50 (shapes)](docs/getting-started.md#try-resnet-50-without-imagenet) · [ResNet-50 (ImageNet)](tinyexp/examples/resnet_exp.py) · [DeiT-S](docs/vit_tp.md#usage) | CPU for MNIST and shapes; GPUs for the full ImageNet recipes |
|
|
26
|
+
| Language model fine-tuning & alignment | MiniMind-3 Dense (64M): [SFT](docs/getting-started.md#fine-tune-minimind-on-one-gpu) · [LoRA](tinyexp/examples/minimind/minimind_lora_exp.py) · [DPO](tinyexp/examples/minimind/minimind_dpo_exp.py) · [GRPO](tinyexp/examples/minimind/minimind_grpo_exp.py) · [PPO](tinyexp/examples/minimind/minimind_ppo_exp.py) | One BF16-capable CUDA GPU |
|
|
27
|
+
| Video generation | [Wan 2.1 T2V 1.3B (LoRA)](tinyexp/examples/wan21_lora_exp.py) | One BF16-capable CUDA GPU |
|
|
28
|
+
|
|
29
|
+
**Read a minimal trainer:** [MNIST](tinyexp/examples/mnist_exp.py) shows training, evaluation, and checkpoint resume in one file; [MiniMind SFT](tinyexp/examples/minimind/minimind_sft_exp.py) shows the loop for supervised fine-tuning on chat data.
|
|
30
|
+
|
|
31
|
+
[All recipes and hardware requirements](tinyexp/examples/README.md) · [Distributed Monte Carlo π on CPU](tinyexp/examples/pi_exp.py)
|
|
32
|
+
|
|
33
|
+
## Which recipe should I try?
|
|
34
|
+
|
|
35
|
+
<a name="image-classification"></a>**Image classification.** Use the ten bundled shapes to check a full training run without a dataset download. Choose MNIST to measure accuracy on held-out digits, or DeiT-S to compare tensor and data parallelism on ImageNet.
|
|
36
|
+
|
|
37
|
+
<a name="language-model-fine-tuning-and-alignment"></a>**Language models.** Start with SFT to fine-tune on four example chats and save a checkpoint. Choose LoRA to train and merge a small adapter, DPO if you have preferred and rejected replies, or GRPO/PPO to train with a reward model.
|
|
38
|
+
|
|
39
|
+
<a name="video-generation"></a>**Video generation.** Fine-tune Wan 2.1 with LoRA on four synthetic clips, or supply your own clips and captions in a `video,prompt` CSV. Sample the base model and the adapter with the same prompt and seed to compare their MP4 outputs.
|
|
40
|
+
|
|
41
|
+
**Planned recipes:** image generation and image editing, with small runs for consumer GPUs.
|
|
42
|
+
|
|
43
|
+
<a name="quick-start-1-minute"></a><a name="option-a-install-with-pip-and-run-the-bundled-example"></a>
|
|
44
|
+
|
|
45
|
+
## Try MNIST on CPU
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install "tinyexp[pytorch]"
|
|
49
|
+
python -m tinyexp.examples.mnist_exp
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
MNIST downloads on the first run. After three epochs, `./output/mnist_exp/log.txt` shows the test accuracy and
|
|
53
|
+
`best.ckpt` in the same directory holds the best model. See the guide to
|
|
54
|
+
<a name="option-b-run-the-bundled-example-from-source-for-development"></a>[install from source](docs/getting-started.md#from-source),
|
|
55
|
+
<a name="common-commands"></a><a name="run-and-inspect-an-experiment"></a>[inspect or override settings and evaluate a checkpoint](docs/getting-started.md#run-and-inspect-an-experiment).
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
- <a name="why-tinyexp"></a>**Why TinyExp:** [project overview](docs/index.md),
|
|
60
|
+
<a name="design-philosophy"></a>[design philosophy](docs/philosophy.md), and
|
|
61
|
+
<a name="how-it-works"></a>[how an experiment works](docs/getting-started.md#how-it-works).
|
|
62
|
+
- <a name="choose-how-workers-are-created"></a>**Run experiments:** [launcher choices and environment requirements](docs/running-modes.md#mode-matrix), [Redis and experiment tracking](docs/running-modes.md#optional-services), and [Redis ownership in multi-node jobs](docs/running-modes.md#redis-helper-lifecycle-in-multi-node-jobs).
|
|
63
|
+
- **Write your own:** [example catalog and run instructions](tinyexp/examples/README.md), [API reference](docs/modules.md), and
|
|
64
|
+
<a name="codex-skill"></a>[TinyExp agent skill](SKILL.md) ([setup](docs/index.md#use-the-tinyexp-agent-skill)).
|
|
65
|
+
- <a name="development"></a>**Develop TinyExp:** [environment setup, checks, and tests](CONTRIBUTING.md#get-started) and [building the docs, package, and releases](CONTRIBUTING.md#build-and-release).
|
|
66
|
+
|
|
67
|
+
[Documentation site](https://zengarden.github.io/TinyExp/) ·
|
|
68
|
+
<a name="contributing"></a>[Contributing: issues and PRs welcome](CONTRIBUTING.md) · <a name="license"></a>[MIT License](LICENSE)
|
|
69
|
+
|
|
70
|
+
[](https://github.com/zengarden/tinyexp/actions/workflows/main.yml)
|
|
71
|
+
[](https://codecov.io/gh/zengarden/tinyexp)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "TinyExp"
|
|
3
|
-
version = "
|
|
3
|
+
version = "v0.2.1"
|
|
4
4
|
description = "A minimalist Python project for deep learning experiment management. It uses Ray for core distributed environment and backend setup, and provides basic, no-frills tracking for models, optimizers, and LR schedulers."
|
|
5
5
|
authors = [{ name = "Zeming LI", email = "zane.li@connect.ust.hk" }]
|
|
6
6
|
readme = "README.md"
|
|
@@ -39,10 +39,15 @@ dependencies = [
|
|
|
39
39
|
"tqdm",
|
|
40
40
|
"redis",
|
|
41
41
|
"wandb",
|
|
42
|
+
# Trackio requires Python 3.10+.
|
|
43
|
+
"trackio; python_version >= '3.10'",
|
|
42
44
|
"loguru",
|
|
43
45
|
]
|
|
44
46
|
|
|
45
47
|
[project.optional-dependencies]
|
|
48
|
+
# pysocks: SOCKS proxy support for swanlab's requests, e.g. socks5h:// through an ssh tunnel on machines
|
|
49
|
+
# without direct internet.
|
|
50
|
+
swanlab = ["swanlab>=0.10.6", "pysocks"]
|
|
46
51
|
pytorch = [
|
|
47
52
|
"accelerate",
|
|
48
53
|
# Python 3.14 requires releases that publish cp314 wheels. The CPU/CUDA/
|
|
@@ -54,6 +59,26 @@ pytorch = [
|
|
|
54
59
|
# TorchVision pulls Pillow; use a release with CPython 3.14 wheels.
|
|
55
60
|
"pillow>=11.3; python_version >= '3.14'",
|
|
56
61
|
]
|
|
62
|
+
vit = [
|
|
63
|
+
# vit_tp_exp example: data pipeline (Mixup/RandAugment), losses, scheduler, and
|
|
64
|
+
# DropPath/trunc_normal_ used by the ported DeiT model. The model itself is
|
|
65
|
+
# ported verbatim from timm 0.3.2 into tinyexp/examples/vit_tp_exp.py.
|
|
66
|
+
# timm does not pull torch, and the example imports torch/torchvision directly,
|
|
67
|
+
# so pull the pytorch extra via a self-referential extra instead of duplicating
|
|
68
|
+
# its per-interpreter version pins.
|
|
69
|
+
"TinyExp[pytorch]",
|
|
70
|
+
"timm>=1.0",
|
|
71
|
+
]
|
|
72
|
+
video = [
|
|
73
|
+
"TinyExp[pytorch]",
|
|
74
|
+
"torch>=2.1",
|
|
75
|
+
"diffusers>=0.34",
|
|
76
|
+
"peft>=0.15",
|
|
77
|
+
"transformers>=4.44.2",
|
|
78
|
+
"imageio[ffmpeg]",
|
|
79
|
+
"ftfy",
|
|
80
|
+
"sentencepiece",
|
|
81
|
+
]
|
|
57
82
|
|
|
58
83
|
[project.urls]
|
|
59
84
|
Homepage = "https://zengarden.github.io/TinyExp/"
|
|
@@ -161,6 +186,7 @@ ignore = [
|
|
|
161
186
|
[tool.ruff.lint.per-file-ignores]
|
|
162
187
|
"tests/*" = ["S101"]
|
|
163
188
|
"tinyexp/utils/redis_utils.py" = ["S603"]
|
|
189
|
+
"tinyexp/examples/vit_tp_exp.py" = ["S101", "TRY003"]
|
|
164
190
|
|
|
165
191
|
[tool.ruff.format]
|
|
166
192
|
preview = true
|
|
@@ -2,6 +2,13 @@ import pytest
|
|
|
2
2
|
import ray
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
@pytest.fixture(scope="session", autouse=True)
|
|
6
|
+
def isolate_redis_password():
|
|
7
|
+
with pytest.MonkeyPatch.context() as env:
|
|
8
|
+
env.delenv("TINYEXP_REDIS_PASSWORD", raising=False)
|
|
9
|
+
yield
|
|
10
|
+
|
|
11
|
+
|
|
5
12
|
@pytest.fixture(scope="session")
|
|
6
13
|
def ray_session():
|
|
7
14
|
"""
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from types import SimpleNamespace
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from torch.utils.data import DataLoader, Dataset
|
|
7
|
+
|
|
8
|
+
from tinyexp.dataset.fake_dataloader import HoldOnesampleDataLoader
|
|
9
|
+
from tinyexp.dataset.sampler import InfiniteSampler
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _take(sampler: InfiniteSampler, count: int) -> list[int]:
|
|
13
|
+
stream = iter(sampler)
|
|
14
|
+
return [next(stream) for _ in range(count)]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.parametrize(
|
|
18
|
+
("kwargs", "match"),
|
|
19
|
+
[
|
|
20
|
+
({"size": 0}, "size"),
|
|
21
|
+
({"size": -1}, "size"),
|
|
22
|
+
({"size": 3, "accelerator": SimpleNamespace(rank=0, world_size=0)}, "world_size"),
|
|
23
|
+
({"size": 3, "accelerator": SimpleNamespace(rank=0, world_size=-1)}, "world_size"),
|
|
24
|
+
({"size": 3, "accelerator": SimpleNamespace(rank=-1, world_size=2)}, "rank"),
|
|
25
|
+
({"size": 3, "accelerator": SimpleNamespace(rank=2, world_size=2)}, "rank"),
|
|
26
|
+
],
|
|
27
|
+
)
|
|
28
|
+
def test_infinite_sampler_rejects_invalid_arguments(kwargs: dict, match: str) -> None:
|
|
29
|
+
with pytest.raises(ValueError, match=match):
|
|
30
|
+
InfiniteSampler(**kwargs)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize(
|
|
34
|
+
("size", "rank", "world_size", "expected"),
|
|
35
|
+
[(3, 0, 1, [0, 1, 2, 0, 1, 2, 0]), (4, 1, 2, [1, 3, 1, 3, 1, 3])],
|
|
36
|
+
)
|
|
37
|
+
def test_infinite_sampler_no_shuffle_repeats_the_rank_slice(
|
|
38
|
+
size: int, rank: int, world_size: int, expected: list[int]
|
|
39
|
+
) -> None:
|
|
40
|
+
accelerator = SimpleNamespace(rank=rank, world_size=world_size)
|
|
41
|
+
sampler = InfiniteSampler(size=size, shuffle=False, seed=0, accelerator=accelerator)
|
|
42
|
+
|
|
43
|
+
assert _take(sampler, len(expected)) == expected
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_infinite_sampler_non_divisible_stream_with_drop_last() -> None:
|
|
47
|
+
rank_zero = SimpleNamespace(rank=0, world_size=2)
|
|
48
|
+
rank_one = SimpleNamespace(rank=1, world_size=2)
|
|
49
|
+
|
|
50
|
+
keep_remainder = InfiniteSampler(size=5, shuffle=False, accelerator=rank_zero, drop_last=False)
|
|
51
|
+
drop_remainder = InfiniteSampler(size=5, shuffle=False, accelerator=rank_zero, drop_last=True)
|
|
52
|
+
other_rank = InfiniteSampler(size=5, shuffle=False, accelerator=rank_one, drop_last=False)
|
|
53
|
+
|
|
54
|
+
assert len(keep_remainder) == 3
|
|
55
|
+
assert len(drop_remainder) == 2
|
|
56
|
+
assert _take(keep_remainder, 4) == [0, 2, 4, 1]
|
|
57
|
+
assert _take(other_rank, 4) == [1, 3, 0, 2]
|
|
58
|
+
|
|
59
|
+
drop_remainder.set_epoch(1)
|
|
60
|
+
assert _take(drop_remainder, 2) == [4, 1]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_infinite_sampler_seed_none_is_resolved_once() -> None:
|
|
64
|
+
sampler = InfiniteSampler(size=5, shuffle=True, seed=None)
|
|
65
|
+
first_values = _take(sampler, 10)
|
|
66
|
+
|
|
67
|
+
sampler.set_epoch(0)
|
|
68
|
+
assert _take(sampler, 10) == first_values
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_infinite_sampler_set_epoch_continues_fixed_stream() -> None:
|
|
72
|
+
expected_values = _take(InfiniteSampler(size=10, shuffle=True, seed=17), 20)
|
|
73
|
+
|
|
74
|
+
sampler = InfiniteSampler(size=10, shuffle=True, seed=17)
|
|
75
|
+
sampler.set_epoch(1)
|
|
76
|
+
assert _take(sampler, 10) == expected_values[10:20]
|
|
77
|
+
|
|
78
|
+
sampler.set_epoch(0)
|
|
79
|
+
assert _take(sampler, 10) == expected_values[:10]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_infinite_sampler_set_epoch_preserves_distributed_stream_position() -> None:
|
|
83
|
+
expected_global = _take(InfiniteSampler(size=12, shuffle=True, seed=23), 40)
|
|
84
|
+
|
|
85
|
+
sampler = InfiniteSampler(size=12, shuffle=True, seed=23, accelerator=SimpleNamespace(rank=1, world_size=2))
|
|
86
|
+
sampler.set_epoch(2)
|
|
87
|
+
|
|
88
|
+
assert _take(sampler, 5) == expected_global[2 * 6 * 2 + 1 :: 2][:5]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_infinite_sampler_reuses_one_dataloader_iterator_across_epochs() -> None:
|
|
92
|
+
class IndexDataset(Dataset[int]):
|
|
93
|
+
def __len__(self) -> int:
|
|
94
|
+
return 4
|
|
95
|
+
|
|
96
|
+
def __getitem__(self, index: int) -> int:
|
|
97
|
+
return index
|
|
98
|
+
|
|
99
|
+
class CountingInfiniteSampler(InfiniteSampler):
|
|
100
|
+
iterator_count = 0
|
|
101
|
+
|
|
102
|
+
def __iter__(self):
|
|
103
|
+
type(self).iterator_count += 1
|
|
104
|
+
return super().__iter__()
|
|
105
|
+
|
|
106
|
+
sampler = CountingInfiniteSampler(size=4, shuffle=False, seed=0)
|
|
107
|
+
dataloader = DataLoader(IndexDataset(), batch_size=2, sampler=sampler, num_workers=0)
|
|
108
|
+
iterator = iter(dataloader)
|
|
109
|
+
|
|
110
|
+
epochs = [[next(iterator).tolist() for _ in range(len(dataloader))] for _ in range(3)]
|
|
111
|
+
|
|
112
|
+
assert CountingInfiniteSampler.iterator_count == 1
|
|
113
|
+
assert epochs == [[[0, 1], [2, 3]]] * 3
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_hold_one_sample_dataloader_deepcopies() -> None:
|
|
117
|
+
it = iter(HoldOnesampleDataLoader([{"x": [1]}, {"x": [2]}]))
|
|
118
|
+
first = next(it)
|
|
119
|
+
second = next(it)
|
|
120
|
+
|
|
121
|
+
assert first == second == {"x": [1]}
|
|
122
|
+
assert first is not second
|
|
123
|
+
assert first["x"] is not second["x"]
|