mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-08-09 20:07:41 +00:00
* fix for async io * test for upgrading transformers * add ci machine * fix * fix * fix * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_fp16_torch.py * Update build_on_pr.yml * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fiux * fix * fix * fix * upgrade llama * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * upgrade_bert * upgrade_bloom * [upgrade] upgrade gpt2 (#6291) * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * upgrade command * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * add explanation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * fix * fix * [upgrade]Upgrade qwen2 (#6302) * upgrade qwen2 * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * update_bloom * fix * add explantion * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upgrade_sam * add the explanation * upgrade_t * fix * fix * fix * upgrade_gptj * fix * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [upgrade]upgrade opt (#6307) * upgrade opt * fix * [upgrade]Upgrade mixtral (#6317) * upgrade mixtral * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upgrade infer * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * upgrade drafter * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * upgrade lazy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upgrade mixtral --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * [upgrade]Upgrade vit (#6308) * fix * fix * fix rotate embedding test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * [upgrade]upgrade mistral (#6296) * upgrade mistral * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix falcon * fix * Update test_shard_deepseek.py * Update build_on_pr.yml * Update requirements.txt * fix (#6327) * fix (#6328) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update bert.py * fix (#6329) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Hanks <hangxu0304@gmail.com> Co-authored-by: wangbluo <2538539015@qq.com> Co-authored-by: Wang Binluo <32676639+wangbluo@users.noreply.github.com>
94 lines
3.0 KiB
Python
94 lines
3.0 KiB
Python
import torch
|
|
import transformers
|
|
|
|
from ..registry import ModelAttribute, model_zoo
|
|
|
|
# ===============================
|
|
# Register single-sentence OPT
|
|
# ===============================
|
|
BATCH_SIZE = 2
|
|
SEQ_LENGTH = 16
|
|
|
|
|
|
def data_gen():
|
|
input_ids = torch.Tensor([[1, 15043, 29892, 590, 11203, 338, 274, 1082]]).long()
|
|
attention_mask = torch.Tensor([[1, 1, 1, 1, 1, 1, 1, 1]]).long()
|
|
return dict(input_ids=input_ids, attention_mask=attention_mask)
|
|
|
|
|
|
def data_gen_for_causal_lm():
|
|
# LM data gen
|
|
# the `labels` of LM is the token of the output, cause no padding, use `input_ids` as `labels`
|
|
data = data_gen()
|
|
labels = data["input_ids"].clone()
|
|
data["labels"] = labels
|
|
return data
|
|
|
|
|
|
def data_gen_for_sequence_classification():
|
|
# LM data gen
|
|
# the `labels` of LM is the token of the output, cause no padding, use `input_ids` as `labels`
|
|
data = data_gen()
|
|
data["input_ids"].clone()
|
|
data["labels"] = torch.tensor([1])
|
|
return data
|
|
|
|
|
|
def data_gen_for_question_answering():
|
|
# LM data gen
|
|
# the `labels` of LM is the token of the output, cause no padding, use `input_ids` as `labels`
|
|
data = data_gen()
|
|
data["start_positions"] = torch.tensor([0])
|
|
data["end_positions"] = torch.tensor([1])
|
|
return data
|
|
|
|
|
|
output_transform_fn = lambda x: x
|
|
loss_fn_for_opt_model = lambda x: torch.nn.functional.mse_loss(
|
|
x["last_hidden_state"], torch.ones_like(x["last_hidden_state"])
|
|
)
|
|
loss_fn_for_lm = lambda x: x["loss"]
|
|
config = transformers.OPTConfig(
|
|
hidden_size=128,
|
|
num_hidden_layers=2,
|
|
num_attention_heads=4,
|
|
dropout=0,
|
|
attn_implementation="eager",
|
|
)
|
|
|
|
# register the following models
|
|
# transformers.OPTModel,
|
|
# transformers.OPTForCausalLM,
|
|
model_zoo.register(
|
|
name="transformers_opt",
|
|
model_fn=lambda: transformers.OPTModel(config),
|
|
data_gen_fn=data_gen,
|
|
output_transform_fn=output_transform_fn,
|
|
loss_fn=loss_fn_for_opt_model,
|
|
model_attribute=ModelAttribute(has_control_flow=True),
|
|
)
|
|
model_zoo.register(
|
|
name="transformers_opt_for_causal_lm",
|
|
model_fn=lambda: transformers.OPTForCausalLM(config),
|
|
data_gen_fn=data_gen_for_causal_lm,
|
|
output_transform_fn=output_transform_fn,
|
|
loss_fn=loss_fn_for_lm,
|
|
model_attribute=ModelAttribute(has_control_flow=True),
|
|
)
|
|
model_zoo.register(
|
|
name="transformers_opt_for_question_answering",
|
|
model_fn=lambda: transformers.OPTForQuestionAnswering(config),
|
|
data_gen_fn=data_gen_for_question_answering,
|
|
output_transform_fn=output_transform_fn,
|
|
loss_fn=loss_fn_for_lm,
|
|
model_attribute=ModelAttribute(has_control_flow=True),
|
|
)
|
|
|
|
# TODO The loss and gradient check in the test are failing, to be fixed.
|
|
# model_zoo.register(name='transformers_opt_for_sequence_classification',
|
|
# model_fn=lambda: transformers.OPTForSequenceClassification(config),
|
|
# data_gen_fn=data_gen_for_sequence_classification,
|
|
# output_transform_fn=output_transform_fn,
|
|
# loss_fn=loss_fn_for_lm,
|
|
# model_attribute=ModelAttribute(has_control_flow=True))
|