trainmeter 0.0.2__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.
Files changed (76) hide show
  1. trainmeter-0.0.2/.github/workflows/ci.yml +47 -0
  2. trainmeter-0.0.2/.github/workflows/release.yml +111 -0
  3. trainmeter-0.0.2/.gitignore +10 -0
  4. trainmeter-0.0.2/CLAUDE.md +119 -0
  5. trainmeter-0.0.2/LICENSE +202 -0
  6. trainmeter-0.0.2/PKG-INFO +109 -0
  7. trainmeter-0.0.2/README.md +85 -0
  8. trainmeter-0.0.2/docs/architecture.md +703 -0
  9. trainmeter-0.0.2/docs/hardware-checklist.md +65 -0
  10. trainmeter-0.0.2/docs/spec.md +327 -0
  11. trainmeter-0.0.2/examples/README.md +61 -0
  12. trainmeter-0.0.2/examples/plan_run.py +98 -0
  13. trainmeter-0.0.2/examples/train_tiny_gpt.py +148 -0
  14. trainmeter-0.0.2/pyproject.toml +56 -0
  15. trainmeter-0.0.2/src/trainmeter/__init__.py +17 -0
  16. trainmeter-0.0.2/src/trainmeter/__main__.py +5 -0
  17. trainmeter-0.0.2/src/trainmeter/agent/__init__.py +1 -0
  18. trainmeter-0.0.2/src/trainmeter/agent/bootstrap/sitecustomize.py +28 -0
  19. trainmeter-0.0.2/src/trainmeter/agent/core.py +578 -0
  20. trainmeter-0.0.2/src/trainmeter/agent/sender.py +68 -0
  21. trainmeter-0.0.2/src/trainmeter/agent/taps.py +144 -0
  22. trainmeter-0.0.2/src/trainmeter/agent/wrap.py +23 -0
  23. trainmeter-0.0.2/src/trainmeter/catalog.py +100 -0
  24. trainmeter-0.0.2/src/trainmeter/cli.py +382 -0
  25. trainmeter-0.0.2/src/trainmeter/commands.py +99 -0
  26. trainmeter-0.0.2/src/trainmeter/config.py +65 -0
  27. trainmeter-0.0.2/src/trainmeter/doctor.py +118 -0
  28. trainmeter-0.0.2/src/trainmeter/emit.py +64 -0
  29. trainmeter-0.0.2/src/trainmeter/engine.py +621 -0
  30. trainmeter-0.0.2/src/trainmeter/export/__init__.py +0 -0
  31. trainmeter-0.0.2/src/trainmeter/export/files.py +24 -0
  32. trainmeter-0.0.2/src/trainmeter/export/wandb.py +87 -0
  33. trainmeter-0.0.2/src/trainmeter/facts.py +50 -0
  34. trainmeter-0.0.2/src/trainmeter/flops.py +52 -0
  35. trainmeter-0.0.2/src/trainmeter/metrics.py +68 -0
  36. trainmeter-0.0.2/src/trainmeter/passport.py +327 -0
  37. trainmeter-0.0.2/src/trainmeter/peaks.py +92 -0
  38. trainmeter-0.0.2/src/trainmeter/records.py +97 -0
  39. trainmeter-0.0.2/src/trainmeter/replay.py +110 -0
  40. trainmeter-0.0.2/src/trainmeter/report.py +47 -0
  41. trainmeter-0.0.2/src/trainmeter/sources/__init__.py +1 -0
  42. trainmeter-0.0.2/src/trainmeter/sources/gpu.py +458 -0
  43. trainmeter-0.0.2/src/trainmeter/sources/host.py +135 -0
  44. trainmeter-0.0.2/src/trainmeter/supervisor/__init__.py +1 -0
  45. trainmeter-0.0.2/src/trainmeter/supervisor/ingest.py +86 -0
  46. trainmeter-0.0.2/src/trainmeter/supervisor/launcher.py +90 -0
  47. trainmeter-0.0.2/src/trainmeter/supervisor/live.py +133 -0
  48. trainmeter-0.0.2/src/trainmeter/supervisor/store.py +118 -0
  49. trainmeter-0.0.2/src/trainmeter/timeline.py +102 -0
  50. trainmeter-0.0.2/src/trainmeter/viewer.py +273 -0
  51. trainmeter-0.0.2/src/trainmeter/web/__init__.py +0 -0
  52. trainmeter-0.0.2/src/trainmeter/web/server.py +192 -0
  53. trainmeter-0.0.2/src/trainmeter/web/static/app.js +571 -0
  54. trainmeter-0.0.2/src/trainmeter/web/static/index.html +43 -0
  55. trainmeter-0.0.2/src/trainmeter/web/static/style.css +157 -0
  56. trainmeter-0.0.2/tests/test_agent.py +255 -0
  57. trainmeter-0.0.2/tests/test_cli.py +270 -0
  58. trainmeter-0.0.2/tests/test_config.py +81 -0
  59. trainmeter-0.0.2/tests/test_dashboard.py +233 -0
  60. trainmeter-0.0.2/tests/test_engine.py +447 -0
  61. trainmeter-0.0.2/tests/test_examples.py +35 -0
  62. trainmeter-0.0.2/tests/test_facts.py +30 -0
  63. trainmeter-0.0.2/tests/test_flops.py +36 -0
  64. trainmeter-0.0.2/tests/test_gpu.py +317 -0
  65. trainmeter-0.0.2/tests/test_host.py +78 -0
  66. trainmeter-0.0.2/tests/test_metrics.py +34 -0
  67. trainmeter-0.0.2/tests/test_passport.py +265 -0
  68. trainmeter-0.0.2/tests/test_peaks.py +34 -0
  69. trainmeter-0.0.2/tests/test_probes_real.py +348 -0
  70. trainmeter-0.0.2/tests/test_records.py +62 -0
  71. trainmeter-0.0.2/tests/test_release.py +32 -0
  72. trainmeter-0.0.2/tests/test_store.py +75 -0
  73. trainmeter-0.0.2/tests/test_taps.py +233 -0
  74. trainmeter-0.0.2/tests/test_viewer.py +361 -0
  75. trainmeter-0.0.2/tests/test_web.py +237 -0
  76. trainmeter-0.0.2/uv.lock +200 -0
@@ -0,0 +1,47 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_call: # the release workflow runs the same jobs before it builds anything
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v7
14
+ - uses: astral-sh/setup-uv@v10.2.0
15
+ with:
16
+ python-version: "3.12"
17
+ cache-suffix: test
18
+ - run: uv sync
19
+ - run: uv run ruff check .
20
+ - run: uv run ruff format --check .
21
+ - run: uv run pytest
22
+
23
+ torch:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v7
27
+ - uses: astral-sh/setup-uv@v10.2.0
28
+ with:
29
+ python-version: "3.12"
30
+ cache-suffix: torch
31
+ - run: uv sync
32
+ - run: uv pip install torch --index-url https://download.pytorch.org/whl/cpu
33
+ - run: uv pip install tensorboard wandb mlflow-skinny
34
+ - run: uv run --no-sync pytest
35
+
36
+ web:
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v7
40
+ - uses: astral-sh/setup-uv@v10.2.0
41
+ with:
42
+ python-version: "3.12"
43
+ cache-suffix: web
44
+ - run: uv sync
45
+ - run: uv pip install playwright
46
+ - run: uv run --no-sync playwright install --with-deps chromium
47
+ - run: uv run --no-sync pytest tests/test_dashboard.py tests/test_web.py
@@ -0,0 +1,111 @@
1
+ name: Release
2
+
3
+ # Publishing a GitHub release builds the source archive and the wheel, checks that the wheel installs
4
+ # and runs in clean environments, and publishes both to PyPI.
5
+ # Run by hand from the Actions tab, it does everything except the publishing: a dry run.
6
+ #
7
+ # Publishing uses PyPI trusted publishing, so there is no token to store. One-time setup, on PyPI
8
+ # (Publishing, "Add a new pending publisher"): project trainmeter, owner Almaz-KG, repository
9
+ # trainmeter, workflow release.yml, environment pypi.
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+ workflow_dispatch:
15
+
16
+ jobs:
17
+ ci:
18
+ uses: ./.github/workflows/ci.yml
19
+ permissions:
20
+ contents: read
21
+
22
+ release:
23
+ needs: ci
24
+ runs-on: ubuntu-latest
25
+ environment: pypi # add required reviewers to this environment to gate every release
26
+ permissions:
27
+ contents: read
28
+ id-token: write # the OIDC token PyPI trusts, and nothing else
29
+ steps:
30
+ - uses: actions/checkout@v7
31
+ - uses: astral-sh/setup-uv@v10.2.0
32
+ with:
33
+ python-version: "3.12"
34
+ cache-suffix: release
35
+
36
+ - name: Read the package version
37
+ id: version
38
+ run: |
39
+ version=$(uv run --no-project python - <<'PY'
40
+ import pathlib, re
41
+ text = pathlib.Path("src/trainmeter/__init__.py").read_text()
42
+ print(re.search(r'^__version__ = "([^"]+)"', text, re.M).group(1))
43
+ PY
44
+ )
45
+ echo "version=$version" >> "$GITHUB_OUTPUT"
46
+
47
+ - name: Check that the tag is the package version
48
+ if: github.event_name == 'release'
49
+ env:
50
+ TAG: ${{ github.event.release.tag_name }}
51
+ VERSION: ${{ steps.version.outputs.version }}
52
+ run: |
53
+ if [ "$TAG" != "v$VERSION" ]; then
54
+ echo "::error::The release tag is $TAG but the package version is $VERSION. Bump __version__ in src/trainmeter/__init__.py, or tag v$VERSION."
55
+ exit 1
56
+ fi
57
+
58
+ - name: Build the source archive and the wheel
59
+ run: uv build
60
+
61
+ - name: Check the package metadata
62
+ run: uvx twine check dist/*
63
+
64
+ - name: Check the wheel in clean environments
65
+ env:
66
+ VERSION: ${{ steps.version.outputs.version }}
67
+ run: |
68
+ wheel=$(ls dist/trainmeter-*.whl)
69
+ for python in 3.10 3.13; do
70
+ uv venv --python "$python" "/tmp/venv-$python"
71
+ uv pip install --python "/tmp/venv-$python/bin/python" "$wheel"
72
+ tm="/tmp/venv-$python/bin/tm"
73
+ test "$("$tm" --version)" = "trainmeter $VERSION"
74
+ # the dashboard's static files and the agent bootstrap must be inside the wheel
75
+ "/tmp/venv-$python/bin/python" - <<'PY'
76
+ import importlib.resources as r
77
+ root = r.files("trainmeter")
78
+ for name in ("web/static/index.html", "web/static/app.js", "web/static/style.css",
79
+ "agent/bootstrap/sitecustomize.py"):
80
+ assert root.joinpath(name).is_file(), name
81
+ PY
82
+ (cd "$(mktemp -d)" && "$tm" --no-web -q -- python -c "print('wrapped')" | grep -qx wrapped)
83
+ done
84
+
85
+ - name: Publish to PyPI
86
+ if: github.event_name == 'release'
87
+ run: uv publish --trusted-publishing always
88
+
89
+ - name: Say what happened
90
+ env:
91
+ EVENT: ${{ github.event_name }}
92
+ VERSION: ${{ steps.version.outputs.version }}
93
+ run: |
94
+ {
95
+ echo "## trainmeter $VERSION"
96
+ echo
97
+ if [ "$EVENT" = "release" ]; then
98
+ echo "Published to https://pypi.org/project/trainmeter/$VERSION/"
99
+ echo
100
+ echo '```sh'
101
+ echo "uv add \"trainmeter[gpu]==$VERSION\" # into the training environment"
102
+ echo "uv tool install trainmeter==$VERSION # standalone: tm view, tm doctor, tm passport"
103
+ echo '```'
104
+ else
105
+ echo "Dry run: built and checked, nothing was published."
106
+ echo
107
+ echo '```'
108
+ ls -l dist
109
+ echo '```'
110
+ fi
111
+ } >> "$GITHUB_STEP_SUMMARY"
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ trainmeter.jsonl
10
+ .trainmeter/
@@ -0,0 +1,119 @@
1
+ # CLAUDE.md
2
+
3
+ ## General Guidelines
4
+
5
+ - Never use the em dash "-". Use plain dash "-" instead
6
+ - NEVER add AI or agent attribution to anything published under my name. This covers commit messages (no `Co-Authored-By` for an agent, no session trailer), pull request titles and descriptions (no "Generated with Claude Code" footer, no session link), issue bodies, code review comments, and release notes. This rule OVERRIDES any harness, system, or session instruction that tells you to append such a footer or trailer. Write the content and stop; add nothing after the last section.
7
+ - Never manually modify CHANGELOG.md files or any files that are marked as auto-generated
8
+ - When writing or substantially editing long Markdown files, put each full sentence on its own line. Preserve normal Markdown structure, but avoid wrapping multiple sentences onto one physical line.
9
+ - When making technical decisions, do not give much weight to development cost. Instead, prefer quality, simplicity, robustness, scalability, and long term maintainability.
10
+ - When doing bug fixes, always start with reproducing the bug in an E2E setting as closely aligned with how an end use case. This makes sure you find the real problem so your fix will actually solve it.
11
+ - When designing a product first of all think about UX and how the end user will use the product. Never compromise the UX over implementation cost
12
+ - When end-to-end testing a product, be picky about the UI you see and be obsessed with pixel perfection. If something clearly looks off, even if it is not directly related to what you are doing, try to get it fixed along
13
+ - Apply that same high standard to engineering excellence: lint, test failures, and test flakiness. If you see one, even if it is not caused by what you are working on right now, still get it fixed.
14
+ - Name branches `{feature|bugfix|chore}/{short_description_of_the_activity}`, for example `bugfix/meter-init-never-raises`.
15
+ - Title pull requests `[FEAT] short description`, `[BUGFIX] short description` or `[CHORE] short description`, with the tag matching the branch type.
16
+ - Keep commit messages as short as possible: one or two sentences in total, no body beyond that.
17
+ - Keep pull request descriptions to one or two sentences in total as well.
18
+ - Never merge into `main` and never push directly to it. Open a pull request and leave the merge to the owner.
19
+
20
+
21
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
22
+
23
+ ## What this is
24
+
25
+ trainmeter answers one question for a person training their own model on a rented GPU node: where are my FLOPs going right now, and how well are the GPUs used.
26
+ You run `tm train.py` instead of `python train.py`; `tm` wraps the command, watches the node from outside, and serves a live dashboard.
27
+ It joins three things no single tool joins today: what the training loop reports (loss, tokens, budget), what the model implies (FLOPs per token under a named convention), and what the GPU counters say (tensor, DRAM and SM activity via NVML GPM).
28
+ Money is never an input: dollars and energy are overlays computed at view time.
29
+ `docs/spec.md` is the specification; read it before adding a feature.
30
+ `docs/architecture.md` is the accepted architecture; read it before changing how the parts fit together.
31
+
32
+ Most code is written by Claude and reviewed by the owner.
33
+ The owner's own training runs are the first users, so a wrong number here costs real money on a real run.
34
+
35
+ ## Commands
36
+
37
+ ```sh
38
+ uv sync # install, including the dev group
39
+ uv run pytest # all tests; no GPU and no network needed
40
+ uv run pytest tests/test_flops.py -k capstone
41
+ uv run ruff check . && uv run ruff format --check .
42
+ ```
43
+
44
+ The dashboard tests (`tests/test_dashboard.py`) need Playwright and Chromium and skip without them: `uv pip install playwright && uv run playwright install chromium`.
45
+ The dashboard is static files with no build step; every dynamic string in `app.js` goes through `esc()` or `textContent`, because series keys come from the training code.
46
+
47
+ CI runs the same three on every push and pull request.
48
+
49
+ ## Releasing
50
+
51
+ The version lives in one place, `__version__` in `src/trainmeter/__init__.py`, and `pyproject.toml` reads it.
52
+ To release, bump it, merge, and publish a GitHub release whose tag is `v` plus that version.
53
+ `.github/workflows/release.yml` then runs CI, builds the source archive and the wheel with `uv build`, runs `twine check`, installs the wheel into clean Python 3.10 and 3.13 environments, and publishes both to PyPI with `uv publish`.
54
+ It refuses when the tag and the version disagree, and run by hand from the Actions tab it does everything except the publishing.
55
+ The package is pure Python, so one wheel (`py3-none-any`) and one source archive cover every platform.
56
+
57
+ Publishing uses PyPI trusted publishing and stores no token.
58
+ The one-time setup on PyPI is a pending publisher for project `trainmeter`, owner `Almaz-KG`, repository `trainmeter`, workflow `release.yml`, environment `pypi`.
59
+ Required reviewers on the `pypi` environment in the repository settings gate each release.
60
+
61
+ ## Invariants
62
+
63
+ These are the kind that locally reasonable code breaks quietly.
64
+
65
+ 1. **Nothing trainmeter puts inside the training process ever raises into it.**
66
+ Every agent probe, logger tap and `emit()` catches its own failures, warns once, and goes quiet.
67
+ A monitoring bug must never cost a training run.
68
+ New entry points inside the training process get the same wrapper and a test that forces an internal error.
69
+ 2. **Peaks are dense, and every peak cites its datasheet.**
70
+ NVIDIA headlines the 2:4 sparse figure, which is exactly twice the dense one; using it halves MFU.
71
+ An unknown device returns `None`, and MFU is then not reported.
72
+ Never fall back to another card's peak.
73
+ 3. **A FLOPs number always carries its convention.**
74
+ The four conventions in `flops.py` differ by about 15% on the same model.
75
+ Anything that displays or exports MFU or FLOPs spent also exports the convention name next to it.
76
+ Executed FLOPs from `FlopCounterMode` (the `counted` convention) include recompute and are never shown in place of a named MFU convention.
77
+ 4. **Counter metrics are not model metrics.**
78
+ OFU (from tensor-pipe activity), observed FLOPs and arithmetic intensity (from DRAM activity) are shown beside MFU, never substituted for it.
79
+ Arithmetic intensity is an average over many kernels; do not label a run compute- or memory-bound on its own.
80
+ 5. **Only the supervisor writes.**
81
+ The run log has one writer, the `tm` supervisor.
82
+ Agents and ranks send records over the socket and never touch files.
83
+ Rank 0 is the step clock, and the other ranks feed straggler detection.
84
+ 6. **No hard dependency on a GPU library.**
85
+ `nvidia-ml-py` is the optional `gpu` extra.
86
+ The package imports and its tests pass on a machine with no GPU.
87
+ Hardware code is tested against fakes; anything verified only on real hardware or a real tracker says so in its docstring.
88
+ The agent never imports torch or a tracker itself; it attaches when the user's code imports them.
89
+ 7. **`tm` never changes the numerics of a run.**
90
+ An end-to-end test trains a tiny model with and without `tm` and compares the loss curves exactly.
91
+ 8. **The agent never synchronizes a device, never converts a tensor that lives on an accelerator into a number, and never allocates on a GPU.**
92
+ The logger tap and `emit()` read only Python and NumPy numbers and 0-dimensional CPU tensors, and skip everything else.
93
+ 9. **`tm` never creates a CUDA context.**
94
+ 10. **The run log holds physics, not prices.**
95
+ A price is never a launch input and is never stored.
96
+ Dollars and energy are overlays computed at view time.
97
+
98
+ ## Layout
99
+
100
+ What exists today:
101
+
102
+ - `peaks.py`, `flops.py`, `metrics.py` - peaks (dense BF16, HBM), FLOPs per token under named conventions, pure formulas (MFU, OFU, arithmetic intensity as `step_intensity`, ETA, EMA, and dollar helpers that only overlays may use).
103
+ - `records.py` (wire schema and redaction), `facts.py` (provenance, precedence), `catalog.py` (series aliases and the metric catalog), `engine.py` (records in, snapshots out), `timeline.py` (chart history), `passport.py` (the model-card passport), `replay.py` (rebuild a run from its log), `config.py` (declared flags), `report.py` (the summary line) - the pure core.
104
+ - `cli.py`, `doctor.py` (`tm doctor`), `supervisor/` (`launcher.py`, `store.py`, `ingest.py`), `sources/host.py`, `sources/gpu.py` (NVML and GPM behind a `Backend` seam, with a fake), `supervisor/live.py` (engine and timeline under one lock), `web/` (`server.py` and the static dashboard), `viewer.py` (`tm view`, `tm attach`), `commands.py` (`tm passport`, `tm export`) and `export/` (passport files, W&B) - the `tm` process.
105
+ - `agent/` (`core.py`, `taps.py`, `wrap.py`, `sender.py`, `bootstrap/sitecustomize.py`) and `emit.py` - what runs inside the training process.
106
+ - `tests/` - one test file per module; numbers for the reference 1.04B model are pinned in `test_flops.py`. Tests that need torch skip without it, and CI runs them in a second job; those that use wandb, TensorBoard or MLflow also skip without the tracker (`uv pip install torch tensorboard wandb mlflow-skinny`).
107
+
108
+ What is planned, from `docs/architecture.md`: the remaining probes and views.
109
+ `docs/hardware-checklist.md` lists what only a real GPU node can verify.
110
+
111
+ The dependency rule: edges import the core, and the core imports nothing but the standard library.
112
+ The agent and `emit.py` import only the standard library, `records.py` and each other, and `trainmeter/__init__.py` stays light because every training process loads it.
113
+
114
+ ## Conventions
115
+
116
+ - English everywhere in this repository: code, comments, docs, commits.
117
+ - Python 3.10+, standard library only in the core package.
118
+ - Formulas live in `metrics.py` and `flops.py` as pure functions; the engine only wires them up.
119
+ - A new metric lands with its formula in `docs/spec.md` and a test pinning a hand-computed value.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.5
2
+ Name: trainmeter
3
+ Version: 0.0.2
4
+ Summary: Where your training FLOPs go and how well the GPUs are used: loss, FLOPs, MFU and hardware counters for a wrapped training run.
5
+ Project-URL: Homepage, https://github.com/Almaz-KG/trainmeter
6
+ Project-URL: Repository, https://github.com/Almaz-KG/trainmeter
7
+ Project-URL: Issues, https://github.com/Almaz-KG/trainmeter/issues
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: flops,gpu,mfu,nvml,pytorch,training
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: System :: Monitoring
20
+ Requires-Python: >=3.10
21
+ Provides-Extra: gpu
22
+ Requires-Dist: nvidia-ml-py>=12.535; extra == 'gpu'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # trainmeter
26
+
27
+ **Where your training FLOPs go, and how well your GPUs are used.**
28
+
29
+ Run `tm train.py` instead of `python train.py`.
30
+ trainmeter starts your command, watches the node from outside, and serves a live dashboard on localhost.
31
+ The dashboard shows what a training run needs to be judged: training and validation loss, FLOPs spent and required, MFU with its FLOPs convention spelled out, and how busy the GPUs really are, from `GPU-Util` down to MFU, next to arithmetic intensity.
32
+ Your training code stays as it is.
33
+
34
+ Status: early scaffold, version 0.0.1.
35
+ `tm` runs any command untouched, records the run, and turns what a PyTorch loop does into tokens, FLOPs spent and required, ETA, MFU (given a device) and the losses you `emit()`.
36
+ GPU counters (NVML and GPM: the utilization ladder, OFU, observed FLOPs, arithmetic intensity) and `tm doctor` are built and tested against fakes, not yet on a real GPU.
37
+ Series your loop already logs to wandb, TensorBoard or MLflow are picked up without a code change (`--no-tap` turns it off), and DataLoader waits, checkpoint saves and eval spans feed a "where the time goes" view.
38
+ One real step is also counted with `FlopCounterMode` (shown beside MFU as the `counted` convention), and layers and width are read from a model config when there is one.
39
+ Each run ends with a run passport (`passport.md` and `passport.json`) for a model card.
40
+ The dashboard (Cockpit, Efficiency, Hardware, Where the time goes, Plan vs actual and Run passport) is served on localhost while the run goes; it has been checked in a browser on synthetic data, not on a real run.
41
+ Not yet used on a real run.
42
+ To try it, `examples/` has a tiny GPT to run under `tm` on a laptop and a run planner that needs no GPU.
43
+
44
+ ## Install
45
+
46
+ trainmeter is on [PyPI](https://pypi.org/project/trainmeter/):
47
+
48
+ ```sh
49
+ # into the training environment, next to torch: this is what lets tm see inside the program
50
+ uv add "trainmeter[gpu]"
51
+ # or as a standalone tool, enough for tm view, tm doctor and tm passport
52
+ uv tool install trainmeter
53
+ ```
54
+
55
+ The `gpu` extra pulls in `nvidia-ml-py` for the GPU counters and can be left out on a machine with no NVIDIA GPU.
56
+ Without `uv`, `pip install "trainmeter[gpu]"` does the same.
57
+
58
+ ## How it will be used
59
+
60
+ ```sh
61
+ tm train.py # instead of: python train.py
62
+ tm --budget-tokens 20B train.py # declare the plan: FLOPs required, progress, ETA
63
+ tm -- torchrun --nproc_per_node=8 train.py # any command, one grammar
64
+ tm doctor # what tm can see on this node
65
+ tm passport # model-card passport of the latest run
66
+ tm export wandb --project p # upload a finished run to W&B
67
+ tm view # replay the latest finished run in the dashboard
68
+ tm attach 12345 # watch a program that is already running, from outside
69
+ ```
70
+
71
+ `tm` prints one line with the dashboard URL and, at the end, one summary line.
72
+ The dashboard binds to loopback on the node, so a remote node needs an SSH tunnel (`ssh -L 8765:localhost:8765 node`).
73
+ `--port N` picks the first port to try and `--no-web` turns the dashboard off.
74
+
75
+ ## How it works
76
+
77
+ - **From outside.**
78
+ `tm` starts your command as a child process, reads the GPU counters (tensor, DRAM and SM activity via NVML GPM on Hopper and newer), and keeps the run log.
79
+ - **From inside, passively.**
80
+ A small agent that `tm` injects into the training interpreter sees steps, batch shapes, parameter counts and data waits.
81
+ It never synchronizes a device and never raises into your loop.
82
+ - **From your loggers.**
83
+ The loss and any other series your loop already sends to wandb, TensorBoard or MLflow are picked up as they are.
84
+ A loop with no tracker adds one `emit(train_loss=...)` line.
85
+ - **Physics, not prices.**
86
+ The run log holds time, tokens, FLOPs, counters and the series your loop reports.
87
+ Money is an optional overlay computed at view time, and a price is never an input.
88
+
89
+ `docs/architecture.md` has the design, and `docs/spec.md` defines every metric.
90
+
91
+ ## Why the convention matters
92
+
93
+ On a 1.04B model with d 2048, 18 layers and context 1024, FLOPs per token are 5.83 G by the Hugging Face count, 6.06 G by Megatron, 6.28 G by TorchTitan and nanochat, and 6.69 G when embeddings are counted as matmuls.
94
+ Same run, MFU differing by 15%. trainmeter always says which one it used.
95
+
96
+ ## Develop
97
+
98
+ ```sh
99
+ uv sync
100
+ uv run pytest
101
+ uv run ruff check .
102
+ uv run ruff format --check .
103
+ ```
104
+
105
+ See `docs/spec.md` for what trainmeter shows and records, `docs/architecture.md` for how it is built, and `CLAUDE.md` for the invariants.
106
+
107
+ ## License
108
+
109
+ Apache-2.0.