Skip to content

Store batch size samples in DB for all ranks #130

Open
ppraneth wants to merge 6 commits into
traceopt-ai:mainfrom
ppraneth:batch
Open

Store batch size samples in DB for all ranks #130
ppraneth wants to merge 6 commits into
traceopt-ai:mainfrom
ppraneth:batch

Conversation

@ppraneth

Copy link
Copy Markdown
Collaborator

Closes #81

Adds input batch size in bytes as a per-step, per-rank metric. Storage only, no rendering work.

What it does:

  • H2D auto-patch records element_size * numel bytes whenever a tensor moves from CPU to CUDA inside trace_step.
  • wrap_h2d does the same for manual mode (tensor + dict/list/tuple containers).
  • New BatchSizeSampler sums bytes within a step so gradient accumulation is handled naturally, then emits one record per (step, rank).
  • New SQLite projection writer persists rows to batch_size_samples for every rank, same retention rules as other per-rank tables.

Files:

  • new: utils/batch_size.py, samplers/batch_size_sampler.py, samplers/schema/batch_size_schema.py, aggregator/sqlite_writers/batch_size.py
  • edited: h2d_auto_timer_patch.py, sdk/wrappers.py, utils/flush_buffers.py, runtime/sampler_registry.py, aggregator/sqlite_writer.py
  • tests: tests/test_batch_size_sampler.py (24 tests), tests/runtime/test_sampler_registry.py (updated tuples)
  • demo: tests/batch_size_demo.py

Verified on RunPod:

  • Single GPU, batch 512, float32 input + int64 label, grad accum = 2.
  • Got 30 rows, bytes_total = 2,105,344, n_transfers = 4 per step. Matches expected 2 * (512*512*4 + 512*8).

ppraneth added 6 commits May 25, 2026 09:48
…Project folding).

  Git auto-applied the rename to my new files and surfaced content conflicts
  in the four files this PR also touches: sqlite_writer.py,
  h2d_auto_timer_patch.py, sampler_registry.py, and wrappers.py.

  Resolved by keeping main's traceml_ai.* import paths while preserving this
  PR's additions (batch_size writer, sampler import, record_batch_size_bytes
  call, tensor_bytes container traversal). Updated inner imports of the new
  batch_size modules and the test/demo files to use traceml_ai.
# Conflicts:
#	src/traceml_ai/runtime/sampler_registry.py
@abhinavsriva
abhinavsriva requested a review from Pendu June 12, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store batch size samples in DB for all ranks

1 participant