Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/sft/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ def setup_data(self):
generation_config_path=os.path.join(
self.job_config.model.hf_assets_path, "generation_config.json"
),
chat_template_path=(
path
if os.path.exists(
path := os.path.join(
self.job_config.model.hf_assets_path, "chat_template.jinja"
)
)
else None
),
)

dataset = sft_iterable_dataset(
Expand Down
13 changes: 10 additions & 3 deletions src/forge/data/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ class HuggingFaceModelTokenizer(ModelTokenizer):
Args:
tokenizer_json_path (str): Path to tokenizer.json file
tokenizer_config_json_path (str | None): Path to tokenizer_config.json file. Default: None
generation_config_path (str | None): Path to generation_config.json file.
Default: None
generation_config_path (str | None): Path to generation_config.json file. Default: None
chat_template_path (str | None): Path to chat_template.jinja file. Default: None
truncation_type (str): type of truncation to apply, either "left" or "right".
Default is "right".
"""
Expand All @@ -227,6 +227,7 @@ def __init__(
*,
tokenizer_config_json_path: str | None = None,
generation_config_path: str | None = None,
chat_template_path: str | None = None,
truncation_type: str = "right",
):
self.base_tokenizer = HuggingFaceBaseTokenizer(
Expand All @@ -245,7 +246,13 @@ def __init__(

# It is used sometimes in HF chat_templates
_env.globals["raise_exception"] = self._raise_helper
self.template = _env.from_string(config["chat_template"])

if chat_template_path:
with open(chat_template_path, "r") as f:
self.template = _env.from_string(f.read())
else:
self.template = _env.from_string(config["chat_template"])

self.truncation_type = truncation_type

self.special_tokens_mapping = {}
Expand Down
Loading