feat: add optional Unsloth training backendFeat/unsloth integration#2
Merged
Conversation
- Two-step filtering approach: 1: First pass uses estimated byte_per_token_ratio with max_token_sequence_length to calculate max_bytes_per_subblock = int(config.max_token_sequence_length * bytes_per_token_ratio) and discards code blocks exceeding that estimate. 2. Second pass applies _filter_overlong_tokenized_examples() with actual token counts as hard limit to guarantee no tokenized examples exceed max_token_sequence_length - Eliminates Unsloth max_seq_length overflow risk
- Branch model loading into _load_hf_model (existing) and _load_unsloth_model (lazy import) - Unsloth uses use_gradient_checkpointing="unsloth" internally, disables HF Trainer gradient_checkpointing when active - Unsloth max_seq_length set to exact max_token_sequence_length for precise memory allocation - Full compatibility with existing merge_lora_and_save and GGUF conversion pipeline
Empty subblocks caused np.random.choice(0, size=1) ValueError crash. Added early return [] when len(subblock_ranges) == 0. This is safe because empty blocks cannot generate FIM examples. Code block truncation code_block_utf8[:max_bytes_per_subblock] cut Tree-sitter nodes mid-Unicode (box chars █=e2 96 88 → e2 96), causing UnicodeDecodeError at 512-token limit. Removed truncation. This is safe because tokenizer post-filters overlong examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds optional Unsloth training support and improves data safety for the C‑based FIM pipeline.
Key Changes