{"record":{"id":"bdfbb471ea081d06","repo":"huggingface/transformers","slug":"mode-is-not-a-valid-split-name","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/glue.py","lineNumber":96,"sourceCode":"        tokenizer: PreTrainedTokenizerBase,\n        limit_length: int | None = None,\n        mode: str | Split = Split.train,\n        cache_dir: str | None = None,\n    ):\n        warnings.warn(\n            \"This dataset will be removed from the library soon, preprocessing should be handled with the Hugging Face Datasets \"\n            \"library. You can have a look at this example script for pointers: \"\n            \"https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py\",\n            FutureWarning,\n        )\n        self.args = args\n        self.processor = glue_processors[args.task_name]()\n        self.output_mode = glue_output_modes[args.task_name]\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        # Load data features from cache or dataset file\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}_{args.task_name}\",\n        )\n        label_list = self.processor.get_labels()\n        if args.task_name in [\"mnli\", \"mnli-mm\"] and tokenizer.__class__.__name__ in (\n            \"RobertaTokenizer\",\n            \"XLMRobertaTokenizer\",\n            \"BartTokenizer\",\n            \"BartTokenizerFast\",\n        ):\n            # HACK(label indices are swapped in RoBERTa pretrained model)\n            label_list[1], label_list[2] = label_list[2], label_list[1]\n        self.label_list = label_list\n\n        # Make sure only the first process in distributed training processes the dataset,\n        # and the others will use the cache.","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/datasets/glue.py#L78-L114","documentation":"Raised by the deprecated GlueDataset constructor when the mode argument is a string that is not a member of the Split enum (train/dev). The constructor looks the string up in Split[mode]; a miss raises this bare KeyError with no echo of the bad value. The whole class also emits a FutureWarning because it is scheduled for removal in favor of the datasets library.","triggerScenarios":"GlueDataset(args, tokenizer=tokenizer, mode='validation') or mode='test' — the enum only contains train and dev, so common split names from the datasets ecosystem fail.","commonSituations":"Migrating old run_glue.py-style scripts and passing modern split names ('validation', 'test') instead of 'dev'; typos like 'Train' (case-sensitive lookup).","solutions":["Use mode='dev' for evaluation data (or the Split.dev enum member) and mode='train' for training.","Pass the enum directly: from transformers.data.datasets.glue import Split; mode=Split.dev.","Better: migrate off GlueDataset entirely and use the datasets library with load_dataset('glue', task), as the FutureWarning advises."],"exampleFix":"# before\ndataset = GlueDataset(args, tokenizer=tok, mode='validation')\n\n# after\ndataset = GlueDataset(args, tokenizer=tok, mode='dev')\n# or modern replacement\nfrom datasets import load_dataset\nds = load_dataset('glue', args.task_name, split='validation')","handlingStrategy":"validation","validationCode":"from transformers.data.datasets.glue import Split\n\nVALID = {s.name for s in Split}\nmode = mode if mode in VALID else {'validation': 'dev', 'test': 'dev'}.get(mode, mode)\nassert mode in VALID, f'mode must be one of {sorted(VALID)}, got {mode!r}'","typeGuard":"def is_glue_split(mode) -> bool:\n    from transformers.data.datasets.glue import Split\n    return mode in Split.__members__","tryCatchPattern":"try:\n    ds = GlueDataset(args, tokenizer=tok, mode=mode)\nexcept KeyError:\n    ds = GlueDataset(args, tokenizer=tok, mode={'validation': 'dev', 'train': 'train'}.get(mode, 'dev'))","preventionTips":["Pass Split enum members instead of strings to avoid lookup failures.","Map modern split names ('validation' -> 'dev') at your config boundary.","Migrate to the datasets library; GlueDataset is deprecated and will be removed."],"tags":["glue","deprecated","dataset","split-name","keyerror"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}