Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
MetaMath_7B_pytorch
Commits
abbb0799
Commit
abbb0799
authored
Nov 26, 2024
by
zhougaofeng
Browse files
Update inference.py
parent
a2e2d87b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
inference.py
inference.py
+20
-0
No files found.
inference.py
0 → 100644
View file @
abbb0799
from
transformers
import
AutoModelForCausalLM
,
AutoTokenizer
# 加载预训练的Metamath模型和分词器
model_name
=
"/home/practice/model/metamath_7b/MetaMath-7B-V1.0"
tokenizer
=
AutoTokenizer
.
from_pretrained
(
model_name
)
model
=
AutoModelForCausalLM
.
from_pretrained
(
model_name
)
# 准备输入文本
input_text
=
"3 + 4 × 2 = ?"
# 使用分词器将输入文本编码为模型所需的格式
input_ids
=
tokenizer
.
encode
(
input_text
,
return_tensors
=
"pt"
)
# 使用模型进行推理
outputs
=
model
.
generate
(
input_ids
)
# 将模型输出解码为文本
output_text
=
tokenizer
.
decode
(
outputs
[
0
],
skip_special_tokens
=
True
)
print
(
output_text
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment