{"record":{"id":"d953c9327848e815","repo":"huggingface/transformers","slug":"mode-is-not-a-valid-split-name-d953c9","errorCode":null,"errorMessage":"mode is not a valid split name","messagePattern":"mode is not a valid split name","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/datasets/squad.py","lineNumber":131,"sourceCode":"\n    def __init__(\n        self,\n        args: SquadDataTrainingArguments,\n        tokenizer: PreTrainedTokenizer,\n        limit_length: int | None = None,\n        mode: str | Split = Split.train,\n        is_language_sensitive: bool = False,\n        cache_dir: str | None = None,\n        dataset_format: str = \"pt\",\n    ):\n        self.args = args\n        self.is_language_sensitive = is_language_sensitive\n        self.processor = SquadV2Processor() if args.version_2_with_negative else SquadV1Processor()\n        if isinstance(mode, str):\n            try:\n                mode = Split[mode]\n            except KeyError:\n                raise KeyError(\"mode is not a valid split name\")\n        self.mode = mode\n        # Load data features from cache or dataset file\n        version_tag = \"v2\" if args.version_2_with_negative else \"v1\"\n        cached_features_file = os.path.join(\n            cache_dir if cache_dir is not None else args.data_dir,\n            f\"cached_{mode.value}_{tokenizer.__class__.__name__}_{args.max_seq_length}_{version_tag}\",\n        )\n\n        # Make sure only the first process in distributed training processes the dataset,\n        # and the others will use the cache.\n        lock_path = cached_features_file + \".lock\"\n        with FileLock(lock_path):\n            if os.path.exists(cached_features_file) and not args.overwrite_cache:\n                start = time.time()\n                check_torch_load_is_safe()\n                self.old_features = torch.load(cached_features_file, weights_only=True)\n\n                # Legacy cache files have only features, while new cache files","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/datasets/squad.py#L113-L149","documentation":"Raised by the deprecated SquadDataset constructor when the mode string is not a key of its Split enum (train/dev). Like GlueDataset, it resolves strings via Split[mode] and raises this bare KeyError for anything else, including the widely used 'validation'/'test' names. The class is legacy and intended to be replaced by the datasets library.","triggerScenarios":"SquadDataset(args, tokenizer=tokenizer, mode='test') or mode='validation'; only 'train' and 'dev' are valid string names.","commonSituations":"Adapting legacy run_squad.py pipelines; using split names from the HF datasets hub ('validation') against this older API; case or whitespace mismatches in the mode string.","solutions":["Use mode='dev' for evaluation and mode='train' for training.","Pass the enum member directly (Split.dev / Split.train) to bypass string lookup.","Migrate to datasets.load_dataset('squad_v2' or 'squad') and the processors in transformers.data.processors.squad for feature conversion."],"exampleFix":"# before\ndataset = SquadDataset(args, tokenizer=tok, mode='validation')\n\n# after\ndataset = SquadDataset(args, tokenizer=tok, mode='dev')","handlingStrategy":"validation","validationCode":"from transformers.data.datasets.squad import Split\n\nif isinstance(mode, str):\n    mode = {'validation': 'dev'}.get(mode, mode)\n    assert mode in Split.__members__, f'mode must be train/dev, got {mode!r}'\n    mode = Split[mode]","typeGuard":"def is_squad_split(mode) -> bool:\n    from transformers.data.datasets.squad import Split\n    return mode in Split.__members__","tryCatchPattern":null,"preventionTips":["Use Split.train / Split.dev enum members directly.","Remember this legacy API only knows 'train' and 'dev' — no 'validation' or 'test'."],"tags":["squad","deprecated","dataset","split-name","keyerror"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}