Skip to content

Conversation

e-mon
Copy link
Collaborator

@e-mon e-mon commented Jun 9, 2025

apply_chat_template というフラグを用意し、chat_templateが存在する場合にチャット形式でpromptを作成出来るように機能実装しました。
また、vllmのreasoning parserを利用したreasoning contentのparse機能を実装しました。

以下のようなconfigを用意し、thinking enable/disableで動作確認をしました。

run_name: null  # This value will be applied to both offline_inference.run_name and wandb.run_name with the highest priority.

apply_chat_template: true
wandb:
  launch: false
  entity: entity
  project: project

tokenize_kwargs:
  add_special_tokens: true
  enable_thinking: true

model:
  model: Qwen/Qwen3-1.7B
  reasoning_parser: qwen3
  gpu_memory_utilization: 0.6

tokenizer:
  pretrained_model_name_or_path: Qwen/Qwen3-1.7B

generation_config:
  max_tokens: 2048 
  temperature: 0.6
  top_k: 20
  top_p: 0.95
  stop_token_ids:
    - 151645
    - 151643

prompt_json_path: '../../../local_files/datasets/2.0.0/evaluation/test/prompts_vGDLmes109IvxwQ_gp7A6A==/*.json'

出力の一部

 {
   "input": "コミック・リリーフは1985年に設立され、それ以来ほぼ10億ポンドの寄付を得た。",
   "prompt": "\n### 指示\nこれから提示する日本語の文章を英語に翻訳してください。必ず英語の訳文のみを出力し、それ以外には何も含めないことを厳守してください。\n\n<examples>\n<example_1>\n### 入力:\n昨日、スティーヴ・ライトは、5人の女性をイギリスのサフォーク州のイプスウィッチで殺害したことで有罪判決を受け、本日、イプスウィッチ刑事裁判所で終身刑を言い渡された。\n### 応答:\nSteve Wright, yesterday convicted of the murder of five women in Ipswich, Suffolk, England, has today been sentenced at Ipswich Crown Court to life imprisonment.\n</example_1>\n<example_2>\n### 入力:\nイプスウィッチで売春婦として働いていた5人の女性の遺体は、2006年12月に町の周辺で見つかった。\n### 応答:\nThe bodies of the five women who worked as sex workers in Ipswich were found around the town in December 2006.\n</example_2>\n<example_3>\n### 入力:\nグロス裁判官は、「かなりの程度、予謀と計画性」があり、ライトに対する終身刑の判決は適切である、と述べた。\n### 応答:\nThe judge, Mr Justice Gross said that a \"substantial degree of pre-meditation and planning\" was involved meaning the requirments for a whole life sentence for Wright was met.\n</example_3>\n<example_4>\n### 入力:\n「あなたが全人生を刑務所で過ごすべきだというのは当然のことである。」\n### 応答:\n\"It is right you should spend your whole life in prison.\"\n</example_4>\n</examples>\n### 入力:\nコミック・リリーフは1985年に設立され、それ以来ほぼ10億ポンドの寄付を得た。\n### 応答:",
   "system_prompt": "あなたは日本語の質問応答システムです。以下の質問に対して、正確かつ簡潔な回答を提供してください。\n",
   "gold": "Comic Relief was founded in 1985, and since then has taken in nearly £1 billion in donations.",
   "reasoning_content": "Okay, let's tackle this translation. The input is a Japanese sentence about a comic relief company established in 1985 and having received almost £100 million in donations since then.\n\nFirst, I need to identify the key elements: \"コミック・リリーフ\" is the company name, \"1985年\" is the establishment year, \"それ以来\" means since then, \"ほぼ10億ポンド\" is almost £100 million, and \"寄付を得た\" is received donations.\n\nThe output examples show that company names are kept in katakana, so \"コミック・リリーフ\" should stay as is. The year is translated as \"1985\" in English. The phrase \"それ以来ほぼ10億ポンドの寄付を得た\" becomes \"has received almost £100 million in donations since then.\"\n\nI need to make sure the structure is correct. The sentence should start with the company name, followed by the establishment year, then the donations. The word \"since then\" is used in the example, so that's appropriate here. Also, the amount is in British pounds, so \"£100 million\" is correct. No additional information is needed, just the direct translation.\n",
   "generated": "Comic Relief was established in 1985 and has received almost £100 million in donations since then."
  },

outputs = self.model.generate(sampling_params=sampling_params, prompt_token_ids=prompt_tokens)
for i, output in enumerate(outputs):
results["samples"][i]["generated"] = output.outputs[0].text
if hasattr(self.cfg.model, "reasoning_parser"):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基本的にはparseするようにしただけなので影響はないはずなんですが、データセット途中から以下のような出力を繰り返すようになっており、こちらは原因調査中です
(reasoning enable時のみで、モデル起因か、vllm起因なので今回の修正には基本関係ないと思われます)

"أستاره تamientos\n\nتamientos\n\nتamientos\n\nتamientos\n\nتamientos\n\nتamientos\n\nتamientos

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらおそらく enable_prefix_caching のせいでした

"vllm==0.6.3",
"vllm-flash-attn",
"transformers>=4.45.1",
"vllm==v0.9.0.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新までversionを上げました

@e-mon e-mon requested a review from namgiH June 9, 2025 15:04
@e-mon e-mon marked this pull request as ready for review June 9, 2025 15:04
for target_dataset, target_data in dataset.items():
samples = [sample["prompt"] for sample in target_data["samples"]]
prompt_tokens = self.tokenizer(samples, **self.cfg.tokenize_kwargs)["input_ids"]
if self.cfg.apply_chat_template and self.tokenizer.chat_template is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらは、トークナイザーに chat template が存在しない場合(=モデルが chat template をサポートしない)、
それをメッセージとしてユーザーに知らせても良いと思いましたが、いかがでしょう?

ただこれはどちらかというとこちらの親切なメッセージであって、
特に必須というわけではありませんので、
堀江さんがいらないと判断しましたなら、なくても全然良いと思います。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます、こちら以下のように警告文を追加しました 🙏
00e1003

@namgiH
Copy link
Collaborator

namgiH commented Jun 11, 2025

確認が遅くなり申し訳ありません。
コードを読んだところでは大丈夫と思いますが、
せっかくですので、こちらのPRと一緒にこちらの手元で確認してからApproveいたします。
よろしくお願いいたします。

@namgiH
Copy link
Collaborator

namgiH commented Jun 16, 2025

まだ理由は把握しておりませんが、こちらのブランチを適用すると、
$ make eval_inference がエラーを吐いて動きません。
基本、llm-jp-eval 側の README.md にあるコマンド通りに動かしていて、
以下のエラーは出ますが、情報が少なすぎて役に立ちませんでした。

Inference result directory does not exist. Running inference... 
make[1]: Entering directory '/model/hng88/llm-jp-eval'
/bin/sh: 4: Syntax error: end of file unexpected (expecting "fi") 
make[1]: *** [Makefile:69: inference] Error 2
make[1]: Leaving directory '/model/hng88/llm-jp-eval' 
make[1]: Entering directory '/model/hng88/llm-jp-eval'

ここの修正がどうしてエラーに繋がるかは分かりませんが、取り急ぎ報告します。
よろしければ、そちらの環境でも確認もお願いいたします。

@namgiH
Copy link
Collaborator

namgiH commented Jun 22, 2025

こちら、 llm-jp-eval 側の問題でしたので、このPRは問題ないと思います。
このままマージさせていただきます 🙇

@namgiH namgiH merged commit e4870dc into main Jun 22, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants