speculators.data_generation.preprocessing
Functions:
-
build_eagle3_dataset–Build EAGLE3 dataset by tokenizing conversations and creating loss masks.
-
load_and_preprocess_dataset–Load, tokenize, and preprocess a dataset for EAGLE3 training.
-
load_raw_dataset–Load raw dataset from local file or HuggingFace.
build_eagle3_dataset
build_eagle3_dataset(
dataset: Dataset,
processor: ProcessorLike,
max_length: int = 2048,
num_proc: int = 8,
assistant_pattern: str | Pattern[str] | None = None,
turn_dropout: bool = False,
minimum_valid_tokens: int | None = None,
) -> HFDataset
Build EAGLE3 dataset by tokenizing conversations and creating loss masks.
Uses the processor's built-in chat template via apply_chat_template.
Args: dataset: Raw dataset with conversations processor: Processor with chat template support max_length: Maximum sequence length num_proc: Number of processes for parallel processing assistant_pattern: Optional custom regex pattern for matching assistant responses. If None, pattern will be auto-detected from chat template. turn_dropout: If True, randomly keeps first N consecutive turns per conversation minimum_valid_tokens: Number of tokens to consider for a valid sample
Source code in speculators/data_generation/preprocessing.py
load_and_preprocess_dataset
load_and_preprocess_dataset(
target_model_path: str,
train_data_paths: list[str],
*,
seq_length: int,
build_dataset_num_proc: int = 8,
seed: int = 0,
max_samples: int | None = None,
token_freq_path: Path | str = "./token_freq.pt",
assistant_pattern: str | None = None,
turn_dropout: bool = False,
minimum_valid_tokens: int | None = None,
trust_remote_code: bool = False,
) -> tuple[HFDataset, ProcessorLike]
Load, tokenize, and preprocess a dataset for EAGLE3 training.
Uses the processor's built-in chat template via apply_chat_template. Caching is handled automatically by HuggingFace datasets.
Args: target_model_path: HuggingFace model ID or local path train_data_path: Dataset name or path to JSON/JSONL file seq_length: Maximum sequence length build_dataset_num_proc: Number of processes for dataset building seed: Random seed for shuffling max_samples: Optional limit on number of samples token_freq_path: Path to save token frequency distribution cache_dir: Directory to cache HuggingFace datasets (optional) assistant_pattern: Optional custom regex pattern for matching assistant responses. If None, pattern will be auto-detected from chat template. turn_dropout: If True, randomly keeps first N consecutive turns per conversation minimum_valid_tokens: Number of tokens to consider for a valid sample trust_remote_code: If True, allows executing code from HF Hub.
Returns: Tuple of (preprocessed_dataset, processor)
Source code in speculators/data_generation/preprocessing.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
load_raw_dataset
Load raw dataset from local file or HuggingFace.