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 a raw dataset from one of several source types.
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,
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. 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,
minimum_valid_tokens: int | None = None,
allow_empty_output: bool = False,
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. minimum_valid_tokens: Number of tokens to consider for a valid sample allow_empty_output: If True, allow returning an empty dataset instead of raising when no samples survive preprocessing. 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
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
load_raw_dataset
Load a raw dataset from one of several source types.
Resolution order: 1. Local .json/.jsonl file. 2. Local directory: recursively load all *.json/*.jsonl files as a single dataset. 3. Named preset from DATASET_CONFIGS. 4. hf:<id>[:<subset>:<split>] for an arbitrary HuggingFace dataset.
Args: train_data_path: File path, directory path, preset name, or hf: spec.
Returns: Tuple of (raw_dataset, normalize_fn). normalize_fn is None for sources already in conversations format.
Raises: ValueError: If the source cannot be resolved or a local directory contains no .json/.jsonl files.