Downloads · 30 days
6
20% of all-time downloads
ce-lery/mistral-300m-sft
mistral-300m-sft is a text generation model from ce-lery. Use it when you need the model to write or continue text. It is set up for peft.
Downloads · 30 days
6
20% of all-time downloads
All-time downloads
30
Public
Repo size
324 MB
Likes
0
Public
Click a slice to open those files.
.safetensors214 MB · 66%
From the Hugging Face model README
Welcome to my model card!
This Model feature is ...
Yukkuri shite ittene!
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
def inference(model_path:str, device: str = "cuda", prompt:str = ""):
if (device != "cuda" and device != "cpu"):
device = "cpu"
if not torch.cuda.is_available():
device = "cpu"
print("device:", device)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path,trust_remote_code=True).to(device)
messages = [{"role": "user", "content": prompt}]
tokenized_chat = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
)
# token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
# print("token_ids:",token_ids)
with torch.no_grad():
generated_tokens = model.generate(
tokenized_chat.to("cuda"),
use_cache=True,
early_stopping=False,
max_new_tokens=1024,
top_p=0.95,
top_k=50,
temperature=0.2,
do_sample=True,
no_repeat_ngram_size=2,
num_beams=3,
)
generated_text = tokenizer.decode(generated_tokens[0])
print(generated_text.replace(tokenizer.eos_token, "\n"))
prompt = "こんにちは!"
inference("ce-lery/mistral-300m-sft", "cuda", prompt)
#<s>User:こんにちは!
#<s>Assistant:おはようございます。私はオープンアシスタントです。あなたの質問に答えたり、あなたの質問にお答えします。何かお手伝いできることがあれば、遠慮なく聞いてください。
prompt = "自動車を運転する際に必要なものは?"
inference("ce-lery/mistral-300m-sft", "cuda", prompt)
#<s>User:自動車を運転する際に必要なものは?
#<s>Assistant:運転に必要なすべての道具と装備をそろえるには、いくつかのステップを踏む必要があります。以下はそのステップのステップ・バイ・ステップです。
#
#1. 運転する場所の道路状況を調べる。これは、道路の状況を把握するのに役立ちます。また、交通量や道路の混雑状況など、さまざまな要因を考慮することも重要です。例えば、高速道路での運転は、渋滞や事故のリスクが高まるため、避けるべきである。さらに、車間距離を十分にとって、周囲の状況に注意を払い、危険を回避し、安全を確保するために十分な注意を払うことも重要である。更に、安全な運転をするために、ブレーキとアクセルの踏み間違いや、アクセルとブレーキを間違えるなどのミスを犯さないよう、注意深く運転することも必要です。
prompt = "日本の首都は?"
inference("ce-lery/mistral-300m-sft", "cuda", prompt)
#<s>User:日本の首都は?
#<s>Assistant:東京は日本で最も人口の多い都市であり、人口密度の高い都市です。
If you want to restruct this model, you can refer this Github repository.
And the manual of this repository is here. Please refer it.
If you find my mistake,error,...etc, please create issue. If you create pulreqest, I'm very happy!