SFT with tool-key failed / Without tool-key training example
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.5k
- Forks
- 1.3k
- Avg merge
- 5h 36m
- Merged PRs (30d)
- 22
Description
Without training example with 'tool-key'
When the tool-key argument is provided, the prompt field gets converted to a string type after apply_chat_template processing, but downstream code expects it to remain as List[Dict]. This causes a type mismatch error.
prompt = data[prompt_key]
if apply_chat_template:
if tool_key is not None:
tools = data[tool_key]
if isinstance(tools, str):
tools = json.loads(tools)
elif isinstance(tools, np.ndarray):
tools = tools.tolist()
assert isinstance(tools, list), f"tools must be a list, got {type(tools)} instead"
else:
tools = None
prompt = tokenizer.apply_chat_template(prompt, tools, tokenize=False, add_generation_prompt=True)
also the following messages is Str
for sample in samples:
(sample,) = sample
messages = sample.prompt
token_ids, loss_mask = MASK_GENERATOR.get_loss_mask(messages)
But later code requires messages to be List[Dict]
def get_loss_mask(self, messages: List[Dict]) -> List[int]:
if self.tokenizer_type == "qwen":
if "<|Assistant|>" in self.tokenizer.get_added_vocab():
return self.gen_multi_turn_loss_mask_distill_qwen(messages)
return self.gen_multi_turn_loss_mask_qwen(messages)
elif self.tokenizer_type == "distill_qwen":
return self.gen_multi_turn_loss_mask_distill_qwen(messages)
else:
raise ValueError(f"Unsupported tokenizer type: {self.tokenizer_type}")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the tool_key handling around tokenizer.apply_chat_template and the later sample.prompt passed to MASK_GENERATOR.get_loss_mask. Reproduce SFT with a tool-key training example, then verify that the loss-mask path receives the expected List[Dict] messages without the reported type mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100