r/MachineLearning • • Oct 02 '26

Discussion [D] Self-Promotion Thread

Please post your personal projects, startups, product placements, collaboration needs, blogs etc.

Please mention the payment and pricing requirements for products and services.

Please do not post link shorteners, link aggregator websites , or auto-subscribe links.

--

Any abuse of trust will lead to bans.

Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

--

Meta: This is an experiment. If the community doesnt like this, we will cancel it. This is to encourage those in the community to promote their work by not spamming the main threads.

3 Upvotes

124 comments sorted by

View all comments

1

u/cosmicBb0y ML Engineer Oct 14 '26

Pandera is a dataframe validation library (disclosure: I created Pandera and work at Union AI, which stewards it) and 0.34 adds support for validating pytorch TensorDicts. I added it because many of the training bugs I encounter when I train RL models are data-related bugs:

  • float64 observations coming out of NumPy that blow up memory
  • action indexes outside the action space that only shows up as a CUDA device-side assert
  • NaN reward that kills the loss curve an hour in.

These tensors all had implicit contracts that weren't actually checked.

A TensorDict maps onto a dataframe schema pretty directly. Keys play the role of columns, each tensor's dtype and shape play the role of a column dtype, and batch_size is the row count:

import torch
import pandera.tensordict as pa
    
class Transition(pa.TensorDictModel):
    observation: torch.float32 = pa.Field(shape=(None, 8))
    action: torch.int64 = pa.Field(shape=(None,), isin=[0, 1, 2, 3])
    reward: torch.float32 = pa.Field(shape=(None,), ge=-1.0, le=1.0)
    done: torch.bool = pa.Field(shape=(None,))
    
    class Config:
        batch_size = (None,)
    
Transition.validate(batch, lazy=True)  # raises SchemaErrors listing every failure

It works on TensorDicts, lazy_stack results, and @tensorclass instances. You also get infer_schema from a known-good batch, YAML/JSON serialization, coerce=True for dtype casting, and Hypothesis strategies that generate schema-valid batches for property tests.

What it costs to validate. I timed validate() against the training step of an MLP policy on CPU, holding the 256-row batch and schema fixed while the model grew from 9K to 17M parameters.

  • Validation took 0.3 to 0.5 ms per batch at every size, which was 29% of the step for the 9K-parameter model (a 1 ms step), 4% at 1.1M parameters, and 0.3% at 17M.
  • Most of that is the value checks, which scan every element; dtype, shape, and key checks alone took about a third as long.
  • Validating a whole in-memory dataset once was cheap too: 4 GB took 112 ms to 1.8 s depending on the data, and million-row chunks were 31x faster than validating the same data in 256-row batches, because each call has a fixed overhead.

What it costs not to validate. I wanted to get at what it costs to not validate the training data. I trained REINFORCE on CartPole and corrupted 1%, 5%, or 20% of batches, either with a NaN reward (the weights go NaN, the next rollout crashes, and the loop rolls back to its last good checkpoint) or with observations scaled 100x (nothing crashes). The metric is environment steps to reach a 475 return, counting steps lost to rollbacks and skipped batches, over 30 seeds per cell:

Corruption1%5%20%
NaN reward, no validation1.0x1.1x2.1x
Observations x100, no validation1.1x2.0x>10.6x (15/30 runs never solved it in 1M steps)
Either, validate and skip bad batches1.0x1.0–1.1x1.2x

(Relative to a clean run, which took about 70K steps.) Validation took 0.5% of wall-clock time in those runs. The crash was the cheap failure, since it costs at most a checkpoint interval, and the silent one was the expensive failure, since nothing stops the loop from learning from bad data.

Caveats: these are CPU numbers on small models. CartPole recovers from bad updates quickly and the checkpoints were only 10 updates apart, so I'd expect a larger model with sparser checkpoints to pay more, but I haven't measured that yet. Corruption rates are per batch, not per row. Building the harness also turned up a subtle trap: Optimizer.load_state_dict keeps references to the tensors you give it, so restoring a checkpoint directly let the next NaN update poison the stored checkpoint (one run crashed 574 times before I fixed it).

Gaps in this first version:

  • Nested keys like ("next", "observation") aren't supported yet, which matters for TorchRL users.
  • A failed check tells you the key and the check, not which indices failed.
  • TensorDictModel fields don't accept custom checks yet, so one-off checks need the object API.

I'd love to hear from people using TensorDict or TorchRL: is nested-key support the first thing you'd need, or something else? Do you encounter any of these failure modes and what do you do today to check them? Do you use assert statements?

Post with charts: https://www.union.ai/blog-post/pandera-0-34-tensordict Benchmark code (Flyte scripts, each runs locally with --local):