Skip to content

Commit

Permalink
modified according to comments
Browse files Browse the repository at this point in the history
Signed-off-by: ftgreat <[email protected]>
  • Loading branch information
ftgreat committed Mar 2, 2023
1 parent 948e3f9 commit df91be4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/bminf_generate/galactica_6.7b_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

loader = AutoLoader(task_name="lm",
model_name="galactica-6.7b-en",
model_dir="/share/projset/baaishare/baai-mrnd/xingzhaohu/")
model_dir="./checkpoints/")

model = loader.get_model()
with torch.cuda.device(0):
Expand Down
7 changes: 4 additions & 3 deletions examples/glm_blank_filling/glm_generate_samples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright © 2022 BAAI. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License")

import torch
from flagai.model.glm_model import GLMModel
from flagai.data.tokenizer import Tokenizer
Expand All @@ -20,7 +21,7 @@
model.cuda(torch.cuda.current_device())

predictor = Predictor(model, tokenizer)

# generate samples
text = [
'问题:啤酒伤胃吗?回答:[gMASK]', "问题:隔夜菜能吃吗?回答:[gMASK]", "问题:如何评价许嵩?回答:[gMASK]"
]
Expand All @@ -34,12 +35,12 @@
output = predictor.predict_generate_randomsample(
t, top_k=50, repetition_penalty=4.0, top_p=1.0)
print(t, '\n', output)

#
text = [
"人工智能是一个以计算机科学为基础,由计算机、数学、哲学等多学科交叉融合的交叉学科,[sMASK],具有非常巨大的前景。",
"最近十多年来,人工神经网络的研究工作不断深入,已经取得了很大的进展,[sMASK],表现出了良好的智能特性。"
]
for t in text:
output = predictor.predict_generate_randomsample(
t, top_k=50, repetition_penalty=4.0, top_p=1.0)
print(t, '\n', output)
print(t, '\n', output)
2 changes: 1 addition & 1 deletion examples/gpt2_title_generation/deepspeed.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"steps_per_print": 50,
"gradient_clipping": 1.0,
"zero_optimization": {
"stage": 2,
"stage": 1,
"contiguous_gradients": false,
"overlap_comm": true,
"reduce_scatter": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/gpt2_title_generation/train_multi_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# device = torch.device("cpu")
# single gpu
trainer = Trainer(
env_type="deepspeed+mpu",
env_type="pytorchDDP",
experiment_name="roberta_seq2seq",
batch_size=1,
gradient_accumulation_steps=1,
Expand Down
14 changes: 7 additions & 7 deletions examples/t5_title_generation/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
beam_size=3,
input_max_length=512,
out_max_length=100)
# out_2 = predictor.predict_generate_randomsample(text,
# input_max_length=512,
# out_max_length=100,
# repetition_penalty=1.5,
# top_k=20,
# top_p=0.8)
out_2 = predictor.predict_generate_randomsample(text,
input_max_length=512,
out_max_length=100,
repetition_penalty=1.5,
top_k=20,
top_p=0.8)

print(f"out_1 is {out_1}")
# print(f"out_2 is {out_2}")
print(f"out_2 is {out_2}")
1 change: 0 additions & 1 deletion flagai/model/galactica_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from torch.nn import CrossEntropyLoss
from flagai.model.layers.activations import ACT2FN
from flagai.model.gpt2_model import GPT2Model, GPT2Stack, GPT2Config
# import bminf


class OPTLearnedPositionalEmbedding(nn.Embedding):
Expand Down
8 changes: 0 additions & 8 deletions flagai/model/gpt2_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from flagai.model.utils import normal_init_method
from flagai.model.base_model import BaseModel
import torch.nn.functional as F
# import bminf
if os.getenv('ENV_TYPE') == 'deepspeed+mpu':
from flagai.mpu.utils import divide
from flagai.mpu.random import checkpoint
Expand Down Expand Up @@ -112,10 +111,6 @@ def __init__(self, config):
self.drop = nn.Dropout(config.embd_pdrop)
self.project_in = None
self.project_out = None
# self.h = bminf.TransformerBlockList([
# GPT2Block(config.n_ctx, config, scale=True)
# for _ in range(config.n_layer)
# ],[0])
self.h = nn.ModuleList([
GPT2Block(config.n_ctx, config, scale=True)
for _ in range(config.n_layer)
Expand Down Expand Up @@ -279,9 +274,6 @@ def __init__(self, config, **kwargs):
self.parallel_output = True

self.transformer = GPT2Stack(config_gpt)
# self.lm_head = bminf.QuantizedLinear(nn.Linear(config_gpt.n_embd,
# config_gpt.vocab_size,
# bias=False))
self.lm_head = nn.Linear(config_gpt.n_embd,
config_gpt.vocab_size,
bias=False)
Expand Down
7 changes: 3 additions & 4 deletions flagai/mp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import copy

from_1_to_n_models = {
"gpt2": {
"gpt": {
"wte.weight": 0,
"attn.c_attn.weight": 30,
"attn.c_attn.bias": 30,
Expand Down Expand Up @@ -238,8 +238,7 @@ def change_pytorch_model_mp_from_1_to_n_new(model_name_brief, checkpoint: str, t
d = d["module"]

for k, v in d.items():
if len(v.shape)>2:
continue
assert len(v.shape) < 3
flag = 0
for keys in trans_keys:
if keys in k:
Expand Down Expand Up @@ -413,4 +412,4 @@ def change_pytorch_model_mp_from_n_to_1(model_name_brief, checkpoint):

if __name__ == "__main__":
change_pytorch_model_mp_from_1_to_n(
'/mnt/test_10b_models/state_dict/GLM-10b-en', 2)
'/mnt/test_10b_models/state_dict/GLM-10b-en', 2)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="flagai",
version="v1.6.2",
version="v1.6.0",
description="FlagAI aims to help researchers and developers to freely train and test large-scale models for NLP/CV/VL tasks.",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit df91be4

Please sign in to comment.