2022-08-22 02:50:51 +00:00
|
|
|
import torch
|
2023-09-18 08:31:06 +00:00
|
|
|
from rpc_test_utils import RpcTestModel, parse_args, rpc_run
|
2022-08-22 02:50:51 +00:00
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
from colossalai.legacy.pipeline.rpc._pipeline_schedule import OneFOneBPipelineEngine
|
2022-08-22 02:50:51 +00:00
|
|
|
|
2022-09-20 10:00:39 +00:00
|
|
|
# global variable for model created
|
|
|
|
feat_num = 100
|
|
|
|
h = 100
|
|
|
|
|
|
|
|
|
|
|
|
def partition(pp_rank: int, chunk: int, stage_num: int):
|
|
|
|
torch.manual_seed(1024)
|
|
|
|
partition = RpcTestModel(pp_rank, stage_num, feat_num, h)
|
|
|
|
return partition
|
|
|
|
|
2022-08-22 02:50:51 +00:00
|
|
|
|
2022-08-25 02:49:01 +00:00
|
|
|
def run_master(args):
|
2022-08-22 02:50:51 +00:00
|
|
|
torch.manual_seed(100)
|
|
|
|
|
2022-08-26 06:04:23 +00:00
|
|
|
epoch = args.epoch
|
2022-08-22 02:50:51 +00:00
|
|
|
device = args.device
|
2022-08-24 03:19:46 +00:00
|
|
|
stage_num = args.world_size
|
|
|
|
chunk = args.chunk
|
|
|
|
num_microbatches = args.num_microbatches
|
|
|
|
use_checkpoint = args.use_checkpoint
|
|
|
|
|
|
|
|
sample_num = 1024
|
|
|
|
batch_size = 1024
|
|
|
|
|
2022-08-22 02:50:51 +00:00
|
|
|
assert sample_num % batch_size == 0
|
|
|
|
|
|
|
|
input_sample = torch.randn((sample_num, feat_num), device=device)
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
engine = OneFOneBPipelineEngine(
|
|
|
|
partition_fn=partition,
|
|
|
|
stage_num=stage_num,
|
|
|
|
num_microbatches=num_microbatches,
|
|
|
|
device=device,
|
|
|
|
chunk=chunk,
|
|
|
|
checkpoint=use_checkpoint,
|
|
|
|
)
|
2022-08-22 02:50:51 +00:00
|
|
|
|
2022-08-26 06:04:23 +00:00
|
|
|
for _ in range(epoch):
|
|
|
|
_ = engine.forward_backward(input_sample, forward_only=False)
|
2022-08-22 02:50:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = parse_args()
|
2022-08-25 02:49:01 +00:00
|
|
|
rpc_run(args, run_master)
|