<jupyter_start><jupyter_text>How To Use MultiGPU<jupyter_code>import torch 
import torch.nn as nn 
from torch.autograd import Variable
from torch.utils.data import Dataset, DataLoader
input_size=5
output_size=2
batch_size=30
data_size=100 
class RandomDataset(Dataset):
    def __init__(self,size,length):
        self.len=length
        self.data=torch.randn(length,size)
    def __getitem__(self,index):
        return self.data[index]
    def __len__(self):
        return self.len
    
rand_loader=DataLoader(dataset=RandomDataset(input_size, length=100),
                       batch_size=batch_size,
                       shuffle=True)
class Model(nn.Module):
    def __init__(self, input_size, output_size):
        super(Model,self).__init__()
        self.fc=nn.Linear(input_size,output_size)
    def forward(self,input):
        output=self.fc(input)
        print(" In Model: input size",input.size(),"output size", output.size())
        return output
model=Model(input_size,output_size)
if torch.cuda.device_count() > 1:
    print("Let's use", torch.cuda.device_count(),"GPUs!!")
    model=nn.DataParallel(model)

if torch.cuda.is_available():
    model.cuda()

for data in rand_loader:
    if torch.cuda.is_available():
        input_var = Variable(data.cuda())
    else:
        input_var = Variable(data)

    output = model(input_var)
    print("Outside: input size", input_var.size(),
          "output_size", output.size())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11880515953835709, 'fraction_numerical': 0.00746775288526816, 'mean_word_length': 3.521472392638037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '92312', 'license': 'MIT', 'n_tokens_mistral': 490, 'n_tokens_neox': 481, 'n_words': 90, 'path': 'deeplearning/pyTorch/tutorial/classifier/Data Parallelism.ipynb', 'repo_name': 'terasakisatoshi/pythonCodes', 'size': '1473'}