Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrad transformers to 4.31.0 #516

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions projects/mock_transformers/dist_infer_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions projects/mock_transformers/init_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading