DeepSeek-Coder icon indicating copy to clipboard operation
DeepSeek-Coder copied to clipboard

Deepseek coder 33B 模型测试输出重复问题

Open txy6666yr opened this issue 1 year ago • 3 comments

使用官方的推理代码,模型是官方的33B

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
input_text = "你好啊"
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_length=128)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

结果:

transformers 版本 4.35.2
loading tokenizer....
PAD Token: <|end▁of▁sentence|> 32014
BOS Token <|begin▁of▁sentence|> 32013
EOS Token <|end▁of▁sentence|> 32014
loading model....
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:31<00:00,  4.45s/it]
loading done!
Setting `pad_token_id` to `eos_token_id`:32014 for open-end generation.
你好啊,我叫李小龙
1999年,李小龙去世,享年32岁。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一生,是无奈的一生。
他的一生,是遗憾的一生。
他的一生,是传奇的一生。
他的一生,是辉煌的一生。
他的一生,是短暂的一生。
他的一生,是悲壮的一生。
他的一生,是孤独的一生。
他的一

pip list

Package                  Version
------------------------ -----------
absl-py                  1.4.0
accelerate               0.25.0
addict                   2.4.0
aiofiles                 22.1.0
aiohttp                  3.8.4
aiosignal                1.3.1
aiosqlite                0.19.0
aliyun-python-sdk-core   2.14.0
aliyun-python-sdk-kms    2.16.2
altair                   5.0.0
anyio                    3.6.2
appdirs                  1.4.4
argon2-cffi              21.3.0
argon2-cffi-bindings     21.2.0
arrow                    1.2.3
asttokens                2.2.1
async-timeout            4.0.2
attrdict                 2.0.1
attrs                    23.1.0
Babel                    2.12.1
backcall                 0.2.0
beautifulsoup4           4.12.2
bleach                   6.0.0
brotlipy                 0.7.0
cachetools               5.3.0
certifi                  2023.5.7
cffi                     1.15.1
charset-normalizer       3.1.0
click                    8.1.3
click-default-group      1.2.4
cmake                    3.26.3
comm                     0.1.3
conda                    23.1.0
conda-content-trust      0.1.3
conda-package-handling   2.0.2
conda_package_streaming  0.7.0
contourpy                1.0.7
cpm-kernels              1.0.11
crcmod                   1.7
cryptography             38.0.4
cycler                   0.11.0
datasets                 2.12.0
debugpy                  1.6.7
decorator                5.1.1
defusedxml               0.7.1
dill                     0.3.6
docker-pycreds           0.4.0
einops                   0.6.1
et-xmlfile               1.1.0
evaluate                 0.4.0
executing                1.2.0
fastapi                  0.95.1
fastjsonschema           2.16.3
ffmpy                    0.3.0
filelock                 3.12.0
fire                     0.5.0
flash-attn               1.0.4
fonttools                4.39.4
fqdn                     1.5.1
frozenlist               1.3.3
fschat                   0.2.33
fsspec                   2023.5.0
gast                     0.5.4
gevent                   22.10.2
gitdb                    4.0.10
GitPython                3.1.31
google-auth              2.18.0
google-auth-oauthlib     1.0.0
gradio                   3.23.0
greenlet                 2.0.2
grequests                0.6.0
grpcio                   1.54.0
h11                      0.14.0
hf_transfer              0.1.4
httpcore                 0.17.0
httpx                    0.24.0
huggingface-hub          0.17.3
idna                     3.4
importlib-metadata       7.0.0
importlib-resources      5.12.0
ipykernel                6.23.0
ipython                  8.13.2
ipython-genutils         0.2.0
isoduration              20.11.0
jedi                     0.18.2
Jinja2                   3.1.2
jmespath                 0.10.0
joblib                   1.2.0
json5                    0.9.11
jsonpointer              2.3
jsonschema               4.17.3
jupyter_client           8.2.0
jupyter_core             5.3.0
jupyter-events           0.6.3
jupyter_server           2.5.0
jupyter_server_fileid    0.9.0
jupyter_server_terminals 0.4.4
jupyter_server_ydoc      0.8.0
jupyter-ydoc             0.2.4
jupyterlab               3.6.3
jupyterlab-pygments      0.2.2
jupyterlab_server        2.22.1
kiwisolver               1.4.4
linkify-it-py            2.0.2
lit                      16.0.3
Markdown                 3.4.3
markdown-it-py           2.2.0
markdown2                2.4.8
MarkupSafe               2.1.2
matplotlib               3.7.1
matplotlib-inline        0.1.6
mdit-py-plugins          0.3.3
mdurl                    0.1.2
mistune                  2.0.5
modelscope               1.9.5
mpmath                   1.3.0
multidict                6.0.4
multiprocess             0.70.14
nbclassic                1.0.0
nbclient                 0.7.4
nbconvert                7.4.0
nbformat                 5.8.0
nest-asyncio             1.5.6
networkx                 3.1
nh3                      0.2.11
nltk                     3.8.1
notebook                 6.5.4
notebook_shim            0.2.3
numpy                    1.24.3
oauthlib                 3.2.2
openai                   0.28.0
openpyxl                 3.1.2
orjson                   3.8.12
oss2                     2.18.3
packaging                23.1
pandas                   2.1.3
pandocfilters            1.5.0
parso                    0.8.3
pathtools                0.1.2
Pebble                   5.0.4
pexpect                  4.8.0
pickleshare              0.7.5
Pillow                   9.5.0
pip                      23.1.2
pip-requirements.txt     100.10.7
platformdirs             3.5.1
pluggy                   1.0.0
prometheus-client        0.16.0
prompt-toolkit           3.0.38
protobuf                 4.23.0
psutil                   5.9.5
ptyprocess               0.7.0
pure-eval                0.2.2
pyarrow                  12.0.0
pyasn1                   0.5.0
pyasn1-modules           0.3.0
pybind11                 2.10.4
pycosat                  0.6.4
pycparser                2.21
pycryptodome             3.19.0
pydantic                 1.10.7
pydub                    0.25.1
Pygments                 2.15.1
pylcs                    0.0.8
pyOpenSSL                22.0.0
pyparsing                3.0.9
pyrsistent               0.19.3
PySocks                  1.7.1
python-dateutil          2.8.2
python-json-logger       2.0.7
python-multipart         0.0.6
python-ulid              2.2.0
pytz                     2023.3
PyYAML                   6.0
pyzmq                    25.0.2
regex                    2023.5.5
requests                 2.30.0
requests-oauthlib        1.3.1
responses                0.18.0
rfc3339-validator        0.1.4
rfc3986-validator        0.1.1
rich                     13.3.5
rouge                    1.0.1
rouge-score              0.1.2
rsa                      4.9
ruamel.yaml              0.17.21
ruamel.yaml.clib         0.2.6
safetensors              0.4.1
scipy                    1.11.4
semantic-version         2.10.0
Send2Trash               1.8.2
sentencepiece            0.1.99
sentry-sdk               1.22.2
setproctitle             1.3.2
setuptools               65.6.3
shortuuid                1.0.11
simplejson               3.19.2
six                      1.16.0
smmap                    5.0.0
sniffio                  1.3.0
sortedcontainers         2.4.0
soupsieve                2.4.1
sqlite-fts4              1.0.3
sqlite-migrate           0.1b0
sqlite-utils             3.35.2
stack-data               0.6.2
starlette                0.26.1
supervisor               4.2.5
svgwrite                 1.4.3
sympy                    1.12
tabulate                 0.9.0
tensorboard              2.13.0
tensorboard-data-server  0.7.0
termcolor                2.3.0
terminado                0.17.1
tiktoken                 0.5.1
timeout-decorator        0.5.0
tinycss2                 1.2.1
tokenizers               0.15.0
tomli                    2.0.1
toolz                    0.12.0
torch                    2.0.0+cu118
tornado                  6.3.1
tqdm                     4.65.0
traitlets                5.9.0
transformers             4.35.2
triton                   2.0.0
typing_extensions        4.5.0
tzdata                   2023.3
uc-micro-py              1.0.2
uri-template             1.2.0
urllib3                  2.0.2
uvicorn                  0.22.0
wandb                    0.15.2
wavedrom                 2.0.3.post3
wcwidth                  0.2.6
webcolors                1.13
webencodings             0.5.1
websocket-client         1.5.1
websockets               11.0.3
Werkzeug                 2.3.4
wheel                    0.37.1
xxhash                   3.2.0
y-py                     0.5.9
yapf                     0.40.2
yarl                     1.9.2
ypy-websocket            0.8.2
zipp                     3.15.0
zope.event               4.6
zope.interface           6.0
zstandard                0.18.0

然后我测试官方训练脚本训练完的模型也是,会重复输出: 20231206-093548

txy6666yr avatar Dec 06 '23 01:12 txy6666yr

i have the same question with deepseek-coder-33b-instruct

netrookiecn avatar Dec 16 '23 07:12 netrookiecn

i have the same question with deepseek-coder-33b-instruct

sir, I have solved the issue by setting the end token id and the end token ,when generate

txy6666yr avatar Dec 19 '23 01:12 txy6666yr

i have the same question with deepseek-coder-33b-instruct

if u use the instruct model,I think u should generate with the method :

from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-instruct", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
messages=[
    { 'role': 'user', 'content': "write a quick sort algorithm in python."}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
# 32021 is the id of <|EOT|> token
outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=32021)
print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))

It means we should use the eos_token_id.

txy6666yr avatar Dec 19 '23 01:12 txy6666yr