How to train/test on a subset of your FastAI data

If you have a large FastAI (v2) DataLoaders and you're trying to debug something at epoch-scale (such as a custom metric), an easy way to train on a small subset of your data is:

subset_size = 100 # Or whatever
selected_items = np.random.choice(dls.train_ds.items, subset_size, replace=False)
# Swap in the subset for the whole thing (Note: this mutates dls, so re-initialize before full training!)
dls.train = dls.test_dl(selected_items, with_labels=True)
learn.fit_one_cycle(1)