Skip to content

Add new Chat Transform for dataset-level prompt formatting - #401

Open
dameikle wants to merge 5 commits into
eole-nlp:mainfrom
dameikle:hf-streaming-chat-transform
Open

Add new Chat Transform for dataset-level prompt formatting#401
dameikle wants to merge 5 commits into
eole-nlp:mainfrom
dameikle:hf-streaming-chat-transform

Conversation

@dameikle

Copy link
Copy Markdown
Contributor

This pull request introduces support for Hugging Face streaming datasets and dataset-level transform configuration overrides, along with a new chat transform for rendering chat-style prompts. It also improves tokenizer truncation and updates documentation to reflect these new features. The most important changes are grouped below:

Hugging Face Streaming Dataset Support:

  • Added support for specifying datasets via hf:// URIs in config files, allowing direct streaming from Hugging Face with flexible URI forms for split and config selection. All fields (source, target, score) must reference the same dataset/split except for the last field name. [1] [2] [3] [4]
  • Improved internal parsing and validation for hf:// URIs to ensure correct dataset, config, and split alignment between source and target fields. [1] [2]

Dataset-Level Transform Overrides:

  • Introduced per-corpus transforms_configs in the data config, enabling dataset-level overrides for supported transforms (currently only chat). Validation ensures overrides are only used with enabled transforms that support them. [1] [2] [3] [4]

New Chat Transform:

  • Added a new chat transform (eole.transforms.chat.ChatTransform) to render chat-style prompts using a configurable message template, with support for dataset-level message overrides. [1] [2] [3]
  • The transform uses Jinja2 for template rendering and validates that each chat corpus has appropriate messages configured, either globally or via per-corpus overrides.

Tokenizer Improvements:

  • Enhanced the Hugging Face tokenizer transform to truncate token IDs and strings according to max_length, with special handling for decoder-only models to preserve legacy truncation behavior.

Documentation and Dependency Updates:

  • Updated documentation to describe Hugging Face streaming dataset usage, dataset-level transform overrides, and the new chat transform with configuration examples. [1] [2]
  • Added jinja2 as a new dependency for chat template rendering.

Comment thread eole/transforms/tokenize_id.py Outdated
Comment on lines +95 to +103
ids, tokens = encoding.ids, encoding.tokens
if self.max_length is not None:
max_length = self.max_length
decoder_start_token = self.full_config.decoder_start_token
if side == "tgt" and getattr(self.full_config.model, "encoder", None) is None and decoder_start_token == "":
# Decoder-only LM targets are shifted later, so keep one extra token to preserve legacy truncation.
max_length += 1
ids, tokens = ids[:max_length], tokens[:max_length]
return ids, tokens

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vince62s I noticed the max_length from config was being ignored, having got removed in previous commits. Not sure if it was intentional or not, so reintroduced, but can remove if preferred

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't looked at the PR yet but:

  1. the existing HF streaming support did not work properly for you ?
  2. yes I removed it because it was conflicting with our max length, the point was maximum generated token including or not including the prompt length, so it was easier to remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

HF streaming needed some extra dataset/config/split URI handling and arbitrary column selection for the datasets I’ve been using. This PR mostly adds on-the-fly chat prompt formatting plus metadata passthrough for prompts.

Thanks, I get the max_length context now. I’d noticed it in the EuroLLM recipes and went down the rabbit hole. I’ve pulled the huggingface_tokenize.max_length restoration out of this PR.

@vince62s

Copy link
Copy Markdown
Contributor

maybe it can be done in another PR, but bear in mind that https://github.com/eole-nlp/eole/blob/main/eole/bin/run/serve.py uses a "apply_chat_template" that could be refactored with the chat transform. That may simplify a little bit the work in serve.py

@dameikle

Copy link
Copy Markdown
Contributor Author

I started doing the above and have ended up with a bigger refactor to accommodate other shapes, so I'll probably close this PR and come back with another. Sorry for the wasted time on this one.

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