"vscode:/vscode.git/clone" did not exist on "20149d84d9b3081c9099436e11322ad97958e99d"
Commit da3f0934 authored by zhuwenwen's avatar zhuwenwen
Browse files

delete unused files

parent c4dd1fd4
import torch
from colossalai.nn.layer.parallel_2d import reduce_by_batch_2d, split_tensor_2d
from torch import nn
from ._utils import calc_acc
class Accuracy2D(nn.Module):
"""Accuracy for 2D parallelism
"""
def __init__(self):
super().__init__()
def forward(self, logits, targets):
"""Calculate the accuracy of predicted labels.
:param logits: Predicted labels
:param targets: True labels from data
"""
with torch.no_grad():
targets = split_tensor_2d(targets)
correct = calc_acc(logits, targets)
correct = reduce_by_batch_2d(correct)
return correct
import torch
from colossalai.nn.layer.parallel_2p5d import reduce_by_batch_2p5d
from torch import nn
from ._utils import calc_acc
class Accuracy2p5D(nn.Module):
"""Accuracy for 2p5D parallelism
"""
def __init__(self):
super().__init__()
def forward(self, logits, targets):
"""Calculate the accuracy of predicted labels.
:param logits: Predicted labels
:param targets: True labels from data
"""
with torch.no_grad():
targets = split_tensor_2p5d(targets)
correct = calc_acc(logits, targets)
correct = reduce_by_batch_2p5d(correct)
return correct
import torch
from colossalai.constants import INPUT_GROUP_3D, WEIGHT_GROUP_3D
from colossalai.nn.layer.parallel_3d import reduce_by_batch_3d, split_tensor_3d
from colossalai.nn.layer.parallel_3d._utils import get_parallel_mode_from_env
from torch import nn
from ._utils import calc_acc
class Accuracy3D(nn.Module):
"""Accuracy for 3D parallelism
"""
def __init__(self):
super().__init__()
self.input_parallel_mode = get_parallel_mode_from_env(INPUT_GROUP_3D)
self.weight_parallel_mode = get_parallel_mode_from_env(WEIGHT_GROUP_3D)
def forward(self, logits, targets):
"""Calculate the accuracy of predicted labels.
:param logits: Predicted labels
:param targets: True labels from data
"""
with torch.no_grad():
targets = split_tensor_3d(targets, 0, self.weight_parallel_mode)
targets = split_tensor_3d(targets, 0, self.input_parallel_mode)
correct = calc_acc(logits, targets)
correct = reduce_by_batch_3d(correct, self.input_parallel_mode, self.weight_parallel_mode)
return correct
from .model_from_config import ModelFromConfig
__all__ = ['ModelFromConfig']
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from abc import ABC, abstractmethod
import torch.nn as nn
from colossalai.builder import build_layer
class ModelFromConfig(nn.Module, ABC):
def __init__(self):
super(ModelFromConfig, self).__init__()
self.layers = nn.ModuleList()
self.layers_cfg = []
def build_from_cfg(self, start=None, end=None):
assert hasattr(self, 'layers_cfg'), 'Cannot find attribute layers_cfg from the module, please check the ' \
'spelling and if you have initialized this variable'
if start is None:
start = 0
if end is None:
end = len(self.layers_cfg)
for cfg in self.layers_cfg[start: end]:
layer = build_layer(cfg)
self.layers.append(layer)
@abstractmethod
def init_weights(self):
pass
def state_dict_for_save_checkpoint(self, destination=None, prefix='',
keep_vars=False):
"""Use this function to override the state dict for
saving checkpoints."""
return self.state_dict(destination, prefix, keep_vars)
from .colossalai_optimizer import ColossalaiOptimizer
from .fused_adam import FusedAdam
from .fused_lamb import FusedLAMB
from .fused_sgd import FusedSGD
from .lamb import Lamb
from .lars import Lars
__all__ = [
'ColossalaiOptimizer', 'FusedLAMB', 'FusedAdam', 'FusedSGD', 'Lamb', 'Lars'
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment