metastable-void
commited on
update
Browse files
app.py
CHANGED
@@ -24,6 +24,7 @@ if torch.cuda.is_available():
|
|
24 |
model_id = "vericava/llm-jp-3-1.8b-instruct-lora-vericava7-llama"
|
25 |
base_model_id = "llm-jp/llm-jp-3-1.8b-instruct"
|
26 |
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
|
|
|
27 |
base_model = AutoModelForCausalLM.from_pretrained(
|
28 |
base_model_id,
|
29 |
trust_remote_code=True,
|
@@ -34,7 +35,6 @@ if torch.cuda.is_available():
|
|
34 |
model=model,
|
35 |
tokenizer=tokenizer,
|
36 |
)
|
37 |
-
my_pipeline.tokenizer.chat_template = "{{bos_token}}{% for message in messages %}{% if message['role'] == 'user' %}{{ '\\n\\n### 前の投稿:\\n' + message['content'] + '' }}{% elif message['role'] == 'system' %}{{ '以下は、SNS上の投稿です。あなたはSNSの投稿生成botとして、次に続く投稿を考えなさい。説明はせず、投稿の内容のみを鉤括弧をつけずに答えよ。' }}{% elif message['role'] == 'assistant' %}{{ '\\n\\n### 次の投稿:\\n' + message['content'] + eos_token }}{% endif %}{% if loop.last and add_generation_prompt %}{{ '\\n\\n### 次の投稿:\\n' }}{% endif %}{% endfor %}"
|
38 |
|
39 |
@spaces.GPU
|
40 |
@torch.inference_mode()
|
@@ -52,8 +52,9 @@ def generate(
|
|
52 |
{"role": "user", "content": message},
|
53 |
]
|
54 |
|
|
|
55 |
output = my_pipeline(
|
56 |
-
|
57 |
)[-1]["generated_text"][-1]["content"]
|
58 |
yield output
|
59 |
|
|
|
24 |
model_id = "vericava/llm-jp-3-1.8b-instruct-lora-vericava7-llama"
|
25 |
base_model_id = "llm-jp/llm-jp-3-1.8b-instruct"
|
26 |
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
|
27 |
+
tokenizer.chat_template = "{{bos_token}}{% for message in messages %}{% if message['role'] == 'user' %}{{ '\\n\\n### 前の投稿:\\n' + message['content'] + '' }}{% elif message['role'] == 'system' %}{{ '以下は、SNS上の投稿です。あなたはSNSの投稿生成botとして、次に続く投稿を考えなさい。説明はせず、投稿の内容のみを鉤括弧をつけずに答えよ。' }}{% elif message['role'] == 'assistant' %}{{ '\\n\\n### 次の投稿:\\n' + message['content'] + eos_token }}{% endif %}{% if loop.last and add_generation_prompt %}{{ '\\n\\n### 次の投稿:\\n' }}{% endif %}{% endfor %}"
|
28 |
base_model = AutoModelForCausalLM.from_pretrained(
|
29 |
base_model_id,
|
30 |
trust_remote_code=True,
|
|
|
35 |
model=model,
|
36 |
tokenizer=tokenizer,
|
37 |
)
|
|
|
38 |
|
39 |
@spaces.GPU
|
40 |
@torch.inference_mode()
|
|
|
52 |
{"role": "user", "content": message},
|
53 |
]
|
54 |
|
55 |
+
t = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
56 |
output = my_pipeline(
|
57 |
+
t,
|
58 |
)[-1]["generated_text"][-1]["content"]
|
59 |
yield output
|
60 |
|