mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-05 19:13:01 +00:00
[misc] update pre-commit and run all files (#4752)
* [misc] update pre-commit * [misc] run pre-commit * [misc] remove useless configuration files * [misc] ignore cuda for clang-format
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from .option import set_jit_fusion_options
|
||||
from .bias_dropout_add import bias_dropout_add_fused_train, bias_dropout_add_fused_inference
|
||||
from .bias_dropout_add import bias_dropout_add_fused_inference, bias_dropout_add_fused_train
|
||||
from .bias_gelu import bias_gelu_impl
|
||||
from .option import set_jit_fusion_options
|
||||
|
||||
__all__ = [
|
||||
"bias_dropout_add_fused_train", "bias_dropout_add_fused_inference", "bias_gelu_impl",
|
||||
"set_jit_fusion_options"
|
||||
"bias_dropout_add_fused_train",
|
||||
"bias_dropout_add_fused_inference",
|
||||
"bias_gelu_impl",
|
||||
"set_jit_fusion_options",
|
||||
]
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import torch
|
||||
from torch import Tensor
|
||||
|
||||
|
||||
def bias_dropout_add(x, bias, residual, prob, training):
|
||||
@@ -10,16 +9,14 @@ def bias_dropout_add(x, bias, residual, prob, training):
|
||||
|
||||
|
||||
@torch.jit.script
|
||||
def bias_dropout_add_fused_train(x: torch.Tensor,
|
||||
bias: torch.Tensor,
|
||||
residual: torch.Tensor,
|
||||
prob: float) -> torch.Tensor:
|
||||
def bias_dropout_add_fused_train(
|
||||
x: torch.Tensor, bias: torch.Tensor, residual: torch.Tensor, prob: float
|
||||
) -> torch.Tensor:
|
||||
return bias_dropout_add(x, bias, residual, prob, True)
|
||||
|
||||
|
||||
@torch.jit.script
|
||||
def bias_dropout_add_fused_inference(x: torch.Tensor,
|
||||
bias: torch.Tensor,
|
||||
residual: torch.Tensor,
|
||||
prob: float) -> torch.Tensor:
|
||||
def bias_dropout_add_fused_inference(
|
||||
x: torch.Tensor, bias: torch.Tensor, residual: torch.Tensor, prob: float
|
||||
) -> torch.Tensor:
|
||||
return bias_dropout_add(x, bias, residual, prob, False)
|
||||
|
@@ -29,7 +29,6 @@ def bias_gelu_back(g, bias, y):
|
||||
|
||||
|
||||
class GeLUFunction(torch.autograd.Function):
|
||||
|
||||
@staticmethod
|
||||
# bias is an optional argument
|
||||
def forward(ctx, input, bias):
|
||||
|
@@ -10,15 +10,14 @@ JIT_OPTIONS_SET = False
|
||||
|
||||
|
||||
def set_jit_fusion_options():
|
||||
"""Set PyTorch JIT layer fusion options.
|
||||
"""
|
||||
"""Set PyTorch JIT layer fusion options."""
|
||||
# LSG: the latest pytorch and CUDA versions may not support
|
||||
# the following jit settings
|
||||
global JIT_OPTIONS_SET
|
||||
if JIT_OPTIONS_SET == False:
|
||||
# flags required to enable jit fusion kernels
|
||||
TORCH_MAJOR = int(torch.__version__.split('.')[0])
|
||||
TORCH_MINOR = int(torch.__version__.split('.')[1])
|
||||
TORCH_MAJOR = int(torch.__version__.split(".")[0])
|
||||
TORCH_MINOR = int(torch.__version__.split(".")[1])
|
||||
if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR >= 10):
|
||||
# nvfuser
|
||||
torch._C._jit_set_profiling_executor(True)
|
||||
@@ -38,12 +37,14 @@ def set_jit_fusion_options():
|
||||
JIT_OPTIONS_SET = True
|
||||
|
||||
|
||||
def warmup_jit_fusion(batch_size: int,
|
||||
hidden_size: int,
|
||||
seq_length: int = 512,
|
||||
vocab_size: int = 32768,
|
||||
dtype: torch.dtype = torch.float32):
|
||||
""" Compile JIT functions before the main training steps """
|
||||
def warmup_jit_fusion(
|
||||
batch_size: int,
|
||||
hidden_size: int,
|
||||
seq_length: int = 512,
|
||||
vocab_size: int = 32768,
|
||||
dtype: torch.dtype = torch.float32,
|
||||
):
|
||||
"""Compile JIT functions before the main training steps"""
|
||||
|
||||
embed = Embedding(vocab_size, hidden_size).to(get_current_device())
|
||||
linear_1 = Linear(hidden_size, hidden_size * 4, skip_bias_add=True).to(get_current_device())
|
||||
|
Reference in New Issue
Block a user