{"record":{"id":"e5640e4a0016fb38","repo":"unslothai/unsloth","slug":"an-audio-sample-should-have-one-of-path-or-byte","errorCode":null,"errorMessage":"An audio sample should have one of 'path' or 'bytes' but both are None in {value}.","messagePattern":"An audio sample should have one of 'path' or 'bytes' but both are None in (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/utils/datasets/audio_decode.py","lineNumber":85,"sourceCode":"    self,\n    value: dict,\n    token_per_repo_id: Optional[dict] = None,\n) -> dict:\n    \"\"\"Stand-in for `datasets.Audio.decode_example` that never needs FFmpeg.\"\"\"\n    import io\n\n    import numpy as np\n    import soundfile as sf\n    from datasets.download.download_config import DownloadConfig\n    from datasets.utils.file_utils import is_local_path, xopen\n\n    if not self.decode:\n        raise RuntimeError(\n            \"Decoding is disabled for this feature. Please use Audio(decode=True) instead.\"\n        )\n    path, raw = value[\"path\"], value[\"bytes\"]\n    if path is None and raw is None:\n        raise ValueError(\n            f\"An audio sample should have one of 'path' or 'bytes' but both are None in {value}.\"\n        )\n\n    if raw is not None:\n        source: Any = io.BytesIO(raw)\n    elif is_local_path(path):\n        source = path\n    else:\n        source = xopen(\n            path,\n            \"rb\",\n            download_config = DownloadConfig(token = _token_for_url(path, token_per_repo_id)),\n        )\n\n    array, sampling_rate = sf.read(source, dtype = \"float32\", always_2d = False)\n    if array.ndim > 1:\n        # soundfile returns (frames, channels); torchcodec returns (channels, frames).\n        array = np.mean(array, axis = -1)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/datasets/audio_decode.py#L67-L103","documentation":"ValueError from the patched Audio.decode_example when a sample dict has both value['path'] and value['bytes'] equal to None. The decoder needs exactly one source — in-memory bytes or a resolvable path — and a sample with neither is structurally invalid. This mirrors upstream HF datasets' validation and fires before any soundfile/xopen work begins.","triggerScenarios":"Rows where the audio field is {'path': None, 'bytes': None} — common when datasets built from a source with missing files are materialized, or when a map/flatten step constructs the dict and drops both keys' values.","commonSituations":"Corrupt or truncated dataset builds (upload interrupted so bytes never landed), parquet rows written with explicit nulls, datasets assembled from JSON where the audio entry was null, caching bugs that null out path fields.","solutions":["Filter the bad rows before decoding: dataset.filter(lambda r: r['audio']['path'] is not None or r['audio']['bytes'] is not None)","Repair the source dataset so each audio row carries either a valid path or bytes","If building the dataset yourself, ensure exactly one of path/bytes is populated when constructing audio samples"],"exampleFix":"# before\ndataset = dataset.map(lambda r: {'audio': feature.decode_example(r['audio'], ...)})\n\n# after\ndataset = dataset.filter(\n    lambda r: (r['audio'] or {}).get('path') is not None\n    or (r['audio'] or {}).get('bytes') is not None\n)\ndataset = dataset.map(lambda r: {'audio': feature.decode_example(r['audio'], ...)})","handlingStrategy":"validation","validationCode":"def audio_sample_is_valid(sample) -> bool:\n    if not isinstance(sample, dict):\n        return False\n    return sample.get(\"path\") is not None or sample.get(\"bytes\") is not None","typeGuard":"def has_audio_source(value: dict) -> bool:\n    \"\"\"Narrows an audio field to 'decodable' — exactly one of path/bytes set.\"\"\"\n    return (\n        isinstance(value, dict)\n        and (value.get(\"path\") is not None) ^ (value.get(\"bytes\") is not None)\n    )","tryCatchPattern":"try:\n    decoded = feature.decode_example(sample)\nexcept ValueError as e:\n    if \"both are None\" in str(e):\n        skip_row_and_log(sample)  # data defect — do not retry\n    else:\n        raise","preventionTips":["Filter null-path/null-bytes rows before any decode step","When building datasets, write either path or bytes per audio row, never both None","After interrupted dataset uploads, re-verify audio columns before training"],"tags":["audio","datasets","data-quality","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}