openpi
openpi copied to clipboard
accelerate compute_norm_stats
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
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()}
A recent PR switched default norm stat computation to be batched, so should hopefully be faster now!