<img src="https://res.cloudinary.com/montaigne-io/image/upload/v1732157409/4306DB44-5AF8-44F7-89C4-E77E83145E3B.png" style="background-color:initial;max-width:min(100%,852px);max-height:min(438px);;background-image:url(https://res.cloudinary.com/montaigne-io/image/upload/v1732157409/4306DB44-5AF8-44F7-89C4-E77E83145E3B.png);height:auto;width:100%;object-fit:cover;background-size:cover;display:block;" width="852" height="438"> torch.Generator是PyTorch中用于生成随机数的类,可以指定种子生成固定的随机数。 需要注意的是,在使用过一次该随机数后,需要再次生成同样的随机数时需要再次调用该类生成,否则得到的结果不一样。 也就是说重复使用generator时,其产生的随机效果不一样(其产生的随机序列是一致的),要想重复同样的结果,需要每次调用生成的方法时,重新指定一下generator。