On SubsetRandomSampler(indices)

on torch.utils.data.sampler.SubsetRandomSampler(), if I want to choose 5 indices out of 100 randomly, is it right?
torch.utils.data.sampler.SubsetRandomSampler(idx, 5)
where len(idx) = 100

in tutorial of Pytorch, I can’t find using it at this way, why?

No, your usage is wrong and won’t chose 5 out of 100 indices.
As described in the docs:

Samples elements randomly from a given list of indices, without replacement.

which means you are supposed to pass the indices the sampler should randomly sample from as the first argument.
E.g. if your original index is defined as idx = torch.arange(100), you could select the desired 5 indices and pass it to the sampler: SubsetRandomSampler(idx[:5]).
If you want to randomly pick these 5 indices, you could use:

idx_subset = idx[torch.randperm(len(idx))[:5]]

so, the name of this function is kinda ambiguous, where is the meaning of ramdom of this function itself?
and where is the meaning of “subset” this function itself?
e.g.
if idx = [1,2,3,4,5]
torch.utils.data.sampler.SubsetRandomSampler(idx, 100)
what’s sequeece of after call this function?
it looks like idx =[4,5,3,1,2], or [3,2,1,5,4] ramdomly?

Your won’t work, since the second argument is expected to be a generator as given in the docs.
If you remove it,

for i in sampler:
    print(i)

will return a random sequence of the passed indices.

The passed indices will be randomly sampled.

You are able to pass the indices of a subset to the sampler instead of a data source.