mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-23 10:30:03 +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:
@@ -3,12 +3,10 @@ import os
|
||||
import warnings
|
||||
|
||||
import torch
|
||||
import torch.distributed as dist
|
||||
import torch.distributed.rpc as rpc
|
||||
import torch.multiprocessing as mp
|
||||
from torch import nn
|
||||
from torch._C._distributed_rpc import _is_current_rpc_agent_set
|
||||
from torch.optim import SGD, Adam, Optimizer, RMSprop
|
||||
|
||||
from colossalai.legacy import launch
|
||||
from colossalai.legacy.pipeline.pipeline_process_group import ppg
|
||||
@@ -17,13 +15,12 @@ from colossalai.logging import disable_existing_loggers
|
||||
rpc_is_initialized = _is_current_rpc_agent_set
|
||||
|
||||
|
||||
def color_debug(text, prefix=' ', color='blue'):
|
||||
def color_debug(text, prefix=" ", color="blue"):
|
||||
color = color.upper()
|
||||
print(getattr(Back, color), prefix, Style.RESET_ALL, text)
|
||||
|
||||
|
||||
class MLP(nn.Module):
|
||||
|
||||
def __init__(self, dim: int, layers: int):
|
||||
super().__init__()
|
||||
self.layers = torch.nn.ModuleList()
|
||||
@@ -38,7 +35,6 @@ class MLP(nn.Module):
|
||||
|
||||
|
||||
class DAG_MLP(nn.Module):
|
||||
|
||||
def __init__(self, dim: int, layers: int):
|
||||
super().__init__()
|
||||
self.layers = torch.nn.ModuleList()
|
||||
@@ -55,12 +51,11 @@ class DAG_MLP(nn.Module):
|
||||
|
||||
|
||||
class RpcTestModel(nn.Module):
|
||||
|
||||
def __init__(self, stage_id, actual_stage_num, feat_num, h) -> None:
|
||||
super().__init__()
|
||||
self.rank = stage_id
|
||||
self.is_last_rank = stage_id == actual_stage_num - 1
|
||||
self.linear_name = f'linear_{stage_id}'
|
||||
self.linear_name = f"linear_{stage_id}"
|
||||
|
||||
if stage_id == 0:
|
||||
linear = nn.Linear(feat_num, h)
|
||||
@@ -82,38 +77,38 @@ class RpcTestModel(nn.Module):
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--epoch', type=int, default=1)
|
||||
parser.add_argument('--world_size', type=int, default=2)
|
||||
parser.add_argument('--batch_size', type=int, default=16)
|
||||
parser.add_argument('--dp_degree', type=int, default=1)
|
||||
parser.add_argument('--tp_degree', type=int, default=1)
|
||||
parser.add_argument('--num_microbatches', type=int, default=2)
|
||||
parser.add_argument('--chunk', type=int, default=1)
|
||||
parser.add_argument('--use_checkpoint', action='store_true')
|
||||
parser.add_argument('--optimizer', type=str, choices=['SGD', 'Adam', 'RMSprop'], default='SGD')
|
||||
parser.add_argument('--device', type=str, choices=['cpu', 'cuda'], default='cuda')
|
||||
parser.add_argument('--master_addr', type=str, default='localhost')
|
||||
parser.add_argument('--master_port', type=str, default='29020')
|
||||
parser.add_argument('--num_worker_threads', type=str, default=128)
|
||||
parser.add_argument("--epoch", type=int, default=1)
|
||||
parser.add_argument("--world_size", type=int, default=2)
|
||||
parser.add_argument("--batch_size", type=int, default=16)
|
||||
parser.add_argument("--dp_degree", type=int, default=1)
|
||||
parser.add_argument("--tp_degree", type=int, default=1)
|
||||
parser.add_argument("--num_microbatches", type=int, default=2)
|
||||
parser.add_argument("--chunk", type=int, default=1)
|
||||
parser.add_argument("--use_checkpoint", action="store_true")
|
||||
parser.add_argument("--optimizer", type=str, choices=["SGD", "Adam", "RMSprop"], default="SGD")
|
||||
parser.add_argument("--device", type=str, choices=["cpu", "cuda"], default="cuda")
|
||||
parser.add_argument("--master_addr", type=str, default="localhost")
|
||||
parser.add_argument("--master_port", type=str, default="29020")
|
||||
parser.add_argument("--num_worker_threads", type=str, default=128)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def pg_parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--world_size', type=int, default=4)
|
||||
parser.add_argument('--dp_degree', type=int, default=2)
|
||||
parser.add_argument('--tp_degree', type=int, default=1)
|
||||
parser.add_argument('--chunk', type=int, default=1)
|
||||
parser.add_argument('--num_worker_threads', type=str, default=128)
|
||||
parser.add_argument('--device', type=str, choices=['cpu', 'cuda'], default='cuda')
|
||||
parser.add_argument('--master_addr', type=str, default='localhost')
|
||||
parser.add_argument('--master_port', type=str, default='29020')
|
||||
parser.add_argument("--world_size", type=int, default=4)
|
||||
parser.add_argument("--dp_degree", type=int, default=2)
|
||||
parser.add_argument("--tp_degree", type=int, default=1)
|
||||
parser.add_argument("--chunk", type=int, default=1)
|
||||
parser.add_argument("--num_worker_threads", type=str, default=128)
|
||||
parser.add_argument("--device", type=str, choices=["cpu", "cuda"], default="cuda")
|
||||
parser.add_argument("--master_addr", type=str, default="localhost")
|
||||
parser.add_argument("--master_port", type=str, default="29020")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def run_worker(rank, args, master_func):
|
||||
os.environ['MASTER_ADDR'] = args.master_addr
|
||||
os.environ['MASTER_PORT'] = args.master_port
|
||||
os.environ["MASTER_ADDR"] = args.master_addr
|
||||
os.environ["MASTER_PORT"] = args.master_port
|
||||
|
||||
device = args.device
|
||||
world_size = args.world_size
|
||||
@@ -122,17 +117,19 @@ def run_worker(rank, args, master_func):
|
||||
num_worker_threads = args.num_worker_threads
|
||||
host = args.master_addr
|
||||
port = args.master_port
|
||||
backend = 'nccl' if device == 'cuda' else 'gloo'
|
||||
backend = "nccl" if device == "cuda" else "gloo"
|
||||
|
||||
disable_existing_loggers()
|
||||
|
||||
launch(dict(), rank, world_size, host, int(port), backend, verbose=False)
|
||||
ppg.set_global_info(rank=rank,
|
||||
world_size=world_size,
|
||||
dp_degree=dp_degree,
|
||||
tp_degree=tp_degree,
|
||||
num_worker_threads=num_worker_threads,
|
||||
device=device)
|
||||
ppg.set_global_info(
|
||||
rank=rank,
|
||||
world_size=world_size,
|
||||
dp_degree=dp_degree,
|
||||
tp_degree=tp_degree,
|
||||
num_worker_threads=num_worker_threads,
|
||||
device=device,
|
||||
)
|
||||
|
||||
# in rpc mode, only rank 0 is needed to be coded
|
||||
if rank == 0:
|
||||
|
Reference in New Issue
Block a user