train: share one corpus copy across DDP ranks via shared-memory tensors (gate: spike)

Đang mở
#445 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
12/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch

Hướng nghiên cứu

Start from the gate, not the code: the spike needs a 4-GPU node and must show RSS near 1x corpus with matching checkpoints before any implementation. Relevant code is LeechDataset.fill.finish() in src/leech/dataset.py, training._spawn_train, distributed.validate_request and distributed.use_fork_for_dataloader_workers, plus the mem_mb rule in train.smk. Done means the four listed tests pass and model_best.pt is bit-identical to the per-rank-copy run.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

At --gpus N every rank builds its own LeechDataset from the same corpus. Measured in CLAUDE.md ("Multi-GPU training") on the 6.72M-chunk charging corpus: peak RSS 40.6 GiB at 1 GPU, 88.3 at 2, 157.6 at 4, i.e. memory scales 1:1 with ranks, and every rank repeats the ~3 min corpus load, which is the non-sharding floor on the 2.25x speedup. #241 named a shared-memory approach as the contingency but only the per-rank copy shipped.

Spec

Load the corpus once in the launching process, move its tensors to shared memory, and hand the dataset to the ranks.

  • After LeechDataset finishes filling (fill.finish() in src/leech/dataset.py), add LeechDataset.share_memory_() which calls .share_memory_() on each large contiguous tensor/buffer (signal, sequence/kmer, features, labels, CSR map arrays). All remaining state must be picklable-small.
  • training._spawn_train / the spawn gate builds the dataset in the parent (rank-invariant parts only) and passes it via torch.multiprocessing so ranks receive shm handles, not copies. DataLoader workers inside a rank must keep forking (see distributed.use_fork_for_dataloader_workers).
  • distributed.validate_request currently refuses pre-loaded chunks; keep that refusal for the chunk-dict case and allow a shared-memory LeechDataset.
  • Nothing may write to the shared tensors. __getitems__ gathers already copy; add a test that asserts the shared buffers are unchanged after an epoch (checksum before/after) so a later in-place augmentation cannot silently corrupt every rank.
  • train.smk: mem_mb becomes corpus_mem_mb + per_gpu_overhead * train_gpus (new config keys, defaults reproducing today's 1-GPU request). Shared pages are charged to the cgroup, so under-requesting kills the job at the end rather than at the start.

Acceptance criteria (measure first, see the spike below)

  • Production corpus, TCNDwellResidualLN, --gpus 4: peak cgroup memory <= ~60 GiB (was 157.6).
  • Per-rank corpus load time paid once (job wall at 4 GPUs reduced by roughly the repeated ~3 min).
  • Final model_best.pt is bit-identical to the current per-rank-copy run for the same seed (the --gpus path must not change the recipe).
  • --gpus 1 unchanged (no process group, no shm).

Gate: spike first (~2 GPU-hours, one 4xA30 node)

Build the dataset once, share_memory_() it, run 4 independent single-GPU trainings for 2 epochs, and record memory.peak, per-epoch time against the 18:30 single-run baseline, and bit-equality of model_best.pt with a standalone same-seed run. Implementation proceeds only if RSS is near 1x the corpus and checkpoints match.

Tests

  • test_shared_dataset_tensors_are_shared
  • test_shared_dataset_not_mutated_by_epoch
  • test_two_rank_run_with_shared_dataset_matches_per_rank_copy (gloo/CPU)
  • test_validate_request_still_refuses_chunk_dicts

Non-goals

  • mmap-ing the npz (ADR 0006: degrades to ~1,668 rows/s on cache eviction).
  • Sharing a DataLoader or sampler across models: samplers stay per run so paired comparisons hold.
Ngôn ngữ chính
Python
Star
0
Fork
0
Merge trung bình
11 giờ 17 phút
Pull request đã merge (30 ngày)
23

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rnabioco/leech

Tất cả issue của rnabioco/leech

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.