openpi icon indicating copy to clipboard operation
openpi copied to clipboard

accelerate compute_norm_stats

Open ltlhuuu opened this issue 1 year ago • 2 comments

Hello, I'm running compute_norm_stats.py very slowly, it even takes more than 30 hours to finish the final calculation. Running speed peaks at 20it/s, averages out to maybe 10it/s, would you improve trying to speed up this part of the calculation? reference: compute_norm_stats.py

ltlhuuu avatar Jun 02 '25 05:06 ltlhuuu

I encountered the same issue. You can try the following approach using a larger batch size. I’ve tested it on a small dataset and it worked:

    batch_size = 128
    num_batches = (num_frames + batch_size - 1) // batch_size  
    
    data_loader = _data_loader.TorchDataLoader(
        dataset,
        local_batch_size=batch_size,
        num_workers=4,  
        shuffle=shuffle,
        num_batches=num_batches,  
    )

    keys = ["state", "actions"]
    stats = {key: normalize.RunningStats() for key in keys}

    for  batch in tqdm.tqdm(data_loader, total=num_batches, desc="Computing stats"): 
        for key in keys:
            values = np.asarray(batch[key]) # use full batch
            values_reshaped = values.reshape(-1, values.shape[-1])
            stats[key].update(values_reshaped)

    norm_stats = {key: stats.get_statistics() for key, stats in stats.items()}

Kalcy-U avatar Jun 18 '25 02:06 Kalcy-U

A recent PR switched default norm stat computation to be batched, so should hopefully be faster now!

kpertsch avatar Jun 19 '25 16:06 kpertsch