From 890b2cf842292e9cf18214a34be17ff19668bba0 Mon Sep 17 00:00:00 2001 From: Ldpe2G Date: Tue, 8 Aug 2023 03:43:35 +0000 Subject: [PATCH 1/3] upgrad transformers to 4.31.0 --- projects/mock_transformers/dist_infer_opt.py | 18 ++++++++++-------- projects/mock_transformers/init_env.py | 14 +++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/projects/mock_transformers/dist_infer_opt.py b/projects/mock_transformers/dist_infer_opt.py index 6f03af86d..fe3fef29a 100644 --- a/projects/mock_transformers/dist_infer_opt.py +++ b/projects/mock_transformers/dist_infer_opt.py @@ -81,13 +81,20 @@ def __init__(self, *args, **kwargs): ) dist.setup_dist_util(parallel_config) - # initial and load model - model = AutoModelForCausalLM.from_pretrained("facebook/opt-2.7b", torch_dtype=flow.float16) + placement_sbp_dict = dict( + placement=flow.env.all_device_placement("cuda"), + sbp=flow.sbp.broadcast, + ) + + with global_mode(True, **placement_sbp_dict): + # initial and load model + model = AutoModelForCausalLM.from_pretrained("facebook/opt-125m", torch_dtype=flow.float16) + # set model to cuda dist.set_device_type("cuda") model._apply(dist.convert_to_distributed_default_setting) # initial tokenizer - tokenizer = AutoTokenizer.from_pretrained("facebook/opt-2.7b", use_fast=False) + tokenizer = AutoTokenizer.from_pretrained("facebook/opt-125m", use_fast=False) # get input_ids prompt = "Hello, I'm am conscious and" @@ -98,11 +105,6 @@ def __init__(self, *args, **kwargs): placement=dist.get_layer_placement(0), ) - # generate id - placement_sbp_dict = dict( - placement=flow.env.all_device_placement("cuda"), - sbp=flow.sbp.broadcast, - ) with global_mode(True, **placement_sbp_dict): generated_ids = model.generate(input_ids, max_length=30) out_put_ids = tokenizer.batch_decode(generated_ids, skip_special_tokens=True) diff --git a/projects/mock_transformers/init_env.py b/projects/mock_transformers/init_env.py index e059ba011..bef573520 100644 --- a/projects/mock_transformers/init_env.py +++ b/projects/mock_transformers/init_env.py @@ -113,14 +113,14 @@ def flow_softmax(*args, **kwargs): nn.functional.softmax = flow_softmax # -----------------mock flow.tensor--------------- -temp_tensor_func = flow.tensor +# temp_tensor_func = flow.tensor -def flow_tensor(input_x, **kwargs): - if isinstance(input_x, (int, float)): - return input_x - else: - return temp_tensor_func(input_x, **kwargs) +# def flow_tensor(input_x, **kwargs): +# if isinstance(input_x, (int, float)): +# return input_x +# else: +# return temp_tensor_func(input_x, **kwargs) -flow.tensor = flow_tensor +# flow.tensor = flow_tensor From 3c4de5a6d113d2a9083237b795a06e03acdddcf1 Mon Sep 17 00:00:00 2001 From: Ldpe2G Date: Tue, 8 Aug 2023 07:34:14 +0000 Subject: [PATCH 2/3] remove useless codes --- projects/mock_transformers/init_env.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/projects/mock_transformers/init_env.py b/projects/mock_transformers/init_env.py index bef573520..b4741871e 100644 --- a/projects/mock_transformers/init_env.py +++ b/projects/mock_transformers/init_env.py @@ -111,16 +111,3 @@ def flow_softmax(*args, **kwargs): nn.functional.softmax = flow_softmax - -# -----------------mock flow.tensor--------------- -# temp_tensor_func = flow.tensor - - -# def flow_tensor(input_x, **kwargs): -# if isinstance(input_x, (int, float)): -# return input_x -# else: -# return temp_tensor_func(input_x, **kwargs) - - -# flow.tensor = flow_tensor From 9822842837021fbe52a0c09fb5c27692c3e31724 Mon Sep 17 00:00:00 2001 From: Ldpe2G Date: Tue, 8 Aug 2023 07:35:56 +0000 Subject: [PATCH 3/3] format code --- projects/mock_transformers/dist_infer_opt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/mock_transformers/dist_infer_opt.py b/projects/mock_transformers/dist_infer_opt.py index fe3fef29a..4bd8728b4 100644 --- a/projects/mock_transformers/dist_infer_opt.py +++ b/projects/mock_transformers/dist_infer_opt.py @@ -89,7 +89,7 @@ def __init__(self, *args, **kwargs): with global_mode(True, **placement_sbp_dict): # initial and load model model = AutoModelForCausalLM.from_pretrained("facebook/opt-125m", torch_dtype=flow.float16) - + # set model to cuda dist.set_device_type("cuda") model._apply(dist.convert_to_distributed_default_setting)