Download modules/misc.py from Jashan887/79_Self_Correction: direct link, hf CLI and curl.
- Browser
- Download file 601 Bytes
-
https://huggingface.co/Jashan887/79_Self_Correction/resolve/main/modules/misc.py
- Command line
-
hf download hf://Jashan887/79_Self_Correction/modules/misc.py
-
curl -L -o misc.py https://huggingface.co/Jashan887/79_Self_Correction/resolve/main/modules/misc.py
601 Bytes
| import torch.nn as nn | |
| import torch | |
| import torch.distributed as dist | |
| class GlobalAvgPool2d(nn.Module): | |
| def __init__(self): | |
| """Global average pooling over the input's spatial dimensions""" | |
| super(GlobalAvgPool2d, self).__init__() | |
| def forward(self, inputs): | |
| in_size = inputs.size() | |
| return inputs.view((in_size[0], in_size[1], -1)).mean(dim=2) | |
| class SingleGPU(nn.Module): | |
| def __init__(self, module): | |
| super(SingleGPU, self).__init__() | |
| self.module=module | |
| def forward(self, input): | |
| return self.module(input.cuda(non_blocking=True)) | |