Scan your whole stack
Are you using megadata-rs?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.3.0
megadata-rs was last scanned on 28 Nov 2026 at version 0.3.0. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.3.0 LATEST | 28 Nov 2026 | No rules fired |
Findings for v0.3.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.3.0; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
English | 简体中文
megadata_rs is a Rust-native, zero-copy data pipeline engine for LLM and
VLM training at cluster scale. It removes the usual causes of GPU starvation —
JSON parsing, the Python GIL, IPC copies between dataloader processes, and
disk I/O congestion — and moves samples from raw corpora to GPU tensors with
zero memory copies in between.
Dual packing engine
-100 masking, and
cu_seqlens output that plugs straight into FlashAttention-2 varlen
(no cross-document attention leakage).(B, S) tile, use
cu_seqlens to cut the EOS padding at the tail, or run varlen attention.batch_size × max_seq_len is laid out over several consecutive batches, and
each piece becomes its own cu_seqlens segment — no data is lost, but under
varlen training the cross-batch context is silently cut. The builder
aggregates a WARN and records global_stats.split_docs / split_tokens in
index.json; the loader warns again. Mitigation: raise max_seq_len until
it covers the vast majority of documents.Zero-copy FFI: a purpose-built DLPack C ABI plus the Arrow C Data Interface hand Rust heap buffers to PyTorch tensors in $O(1)$ time. No matter how large the batch, Python never copies a single byte.
Temperature mixer for multiple sources: mount Code / Math / Web streams at runtime; temperature scaling samples them concurrently underneath so you can steer the knowledge mix smoothly instead of shuffling statically.
Deterministic sharding and second-level resumption (MMP protocol): no centralised RPC. Thousands of ranks derive shard ownership from a deterministic PRNG with round-robin assignment, so every rank sees the same reproducible shard sequence within an epoch. File offsets and the PRNG state are captured too, so a crashed job resumes in milliseconds and replays the exact cross-source sampling order.
Production control plane
shards >= world_size so no rank idles.index.json.
Cloud downloads are atomic (.tmp + rename), verified after download,
re-downloaded on failure, retried with jittered exponential backoff,
de-duplicated across processes (flock) and bounded by an LRU cache
(MEGADATA_CACHE_LIMIT). Local datasets are not verified by default
(zero overhead); opt in with MEGADATA_VERIFY_LOCAL=1 or =sample:P
(results cached by size+mtime, so each file is hashed once).OSError with the shard name and batch index instead of looking like
"end of data" or hanging in an infinite retry. Local reads get bounded
retries (2 attempts, 50/200 ms backoff). EOF and user cancellation still
end normally, and the reader stays alive after EOF so resumption can seek.catch_unwind, so any panic (including lock poisoning) becomes a fatal
error at the consumer rather than a truncated epoch.Zstd-MDS, preserving O(1) random access) — on by default (real-corpus
benchmark: 42% of original size on a 151k vocab, 629 MB/s decompression,
+103 µs random access; disable with compression="none"). SFT uses Arrow
IPC's native zstd/lz4 (explicit).batches_per_shard is computed on uncompressed bytes
(PT+zstd lands at ~42% of that); plan disk capacity at ~0.42×.predownload caps in-flight batches
(default 16), smoothing I/O bursts and bounding prefetch memory.(seed, epoch), shrinking state_dict from gigabytes of buffer to a
few dozen bytes and making it reproducible across processes.relaxed partitioning with num_canonical_nodes
anchors, so global sample order is independent of cluster topology and a job
can resume after a resize.num_workers > 0 each
worker gets a disjoint shard subset (readers rebuilt lazily after fork).StreamingDataset(IterableDataset) and
MegadataDataLoader(DataLoader) work with HF Trainer / Lightning as-is.Install the published wheel from PyPI:
pip install megadata-rs
The distribution name is megadata-rs; the Python import name remains megadata.
To build from source, Rust 1.88+ (edition = "2024"), Python 3.8+ and maturin are required.
bbpe_rs (the tokenizer) is a regular crates.io dependency and is fetched
automatically — nothing to place by hand:
pip install maturin pytest torch pyarrow
maturin develop --release
To train or export your own tokenizer with bbpe_tokenizer:
pip install "git+https://github.com/hoare211/bbpe_rs@v0.5.0"
DataBuilder)DataBuilder uses Tokio async I/O and a Rayon thread pool to swallow JSONL
corpora and write the on-disk format in one pass.
from megadata import DataBuilder
builder = DataBuilder(tokenizer_path="./model_tokenizer", max_seq_len=8192)
# SFT chat dataset (written as Arrow IPC)
builder.build_dataset(
input_paths=["data/sft/raw.jsonl"],
output_dir="data/sft_processed",
mode="sft",
template_str="{% for msg in messages %}<|im_start|>{{ msg.role }}\n{{ msg.content }}<|im_end|>\n{% endfor %}",
batch_size=16,
)
# PT pretraining dataset (Megatron-style raw-stream .bin/.idx)
builder.build_dataset(
input_paths=["data/pt/raw.jsonl"],
output_dir="data/pt_processed",
mode="pt",
batch_size=16,
# optional control-plane knobs:
# batches_per_shard=0 # 0 = auto (~128MB/shard); loader checks shards >= world_size
# compression="zstd" # PT default (per-batch frame, Zstd-MDS); "none" to disable
)
import torch
from megadata import MixBatchStream
# temperature-controlled multi-source stream (Code/Math/Web, curriculum, annealing)
loader = MixBatchStream(
[
{"path": "data/pt_processed/index.json", "weight": 0.7},
{"path": "data/sft_processed/index.json", "weight": 0.3},
],
batch_size=16,
max_seq_len=8192,
world_size=1024,
rank=0, # DDP topology: no DistributedSampler needed
steps_per_epoch=1000, # required under DDP for a deterministic epoch length
)
loader.update_temperature(2.0) # smooth the mix towards smaller sources
# resume (millisecond-level jump)
# loader.load_state_dict(checkpoint["megadata_state"])
for batch in loader:
# tensors map Rust memory directly — zero copies
input_ids = batch["input_ids"].cuda()
loss = model(input_ids).loss
loss.backward()
# exact snapshot of file cursors + PRNG state
# checkpoint["megadata_state"] = loader.state_dict()
Single-source training loops should use
BatchStream; random access for evaluation usesRandomAccessBatchReader; HF Trainer / Lightning integration usesStreamingDataset+MegadataDataLoader. See the usage guide.
docs/guide/usage.md — English quickstart: build → load → train → resume → tune → troubleshootdocs/guide/使用指南.md — full reference guide (Chinese, most detailed)MIGRATION.md — v1/v2 → v3 rename, snapshot and behaviour changesdocs/README.md — documentation map.github/workflows/ci.yml runs four jobs: lint (ruff over python/ tests/ tools/),
docs (docs_lint.py check + self-test, stdlib only), rust-test
(cargo clippy --all-targets -p megadata_rs -- -D warnings + cargo test --lib)
and python-test (maturin build + pytest). bench.yml runs throughput
benchmarks on demand; nightly.yml runs the full proptest fuzz suite nightly.
No repository variables are required: bbpe_rs comes from crates.io.
Four test dimensions back the claims above (see tests/):
Issues and PRs are welcome — please read CONTRIBUTING.md
(local self-check commands included). For security reports use the private
channel in SECURITY.md.
Released under the MIT license.
Tokenization is provided by the sister project
bbpe_rs (a Rust BPE tokenizer
trainer/encoder). object_store, arrow, pyo3, tokio and rayon form the
infrastructure this engine is built on.
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.