{"record":{"id":"18ca87490b06c169","repo":"huggingface/transformers","slug":"unknown-backend-backend-r-expected-auto-tor","errorCode":null,"errorMessage":"Unknown backend {backend!r}; expected 'auto', 'torchcodec', 'librosa', or 'torchaudio'.","messagePattern":"Unknown backend (.+?); expected 'auto', 'torchcodec', 'librosa', or 'torchaudio'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/audio_utils.py","lineNumber":237,"sourceCode":"        `np.ndarray`: A numpy array representing the audio.\n    \"\"\"\n    if isinstance(audio, np.ndarray):\n        return audio\n    if not isinstance(audio, str):\n        raise TypeError(\n            \"Incorrect format used for `audio`. Should be a numpy array or a `str`: an `http(s)://` URL, \"\n            \"a local file path, or a base64-encoded string (optionally wrapped as a `data:...` URI).\"\n        )\n\n    # torchcodec handles audio/video; librosa only plain audio. `backend` lets callers pin one.\n    if backend == \"auto\":\n        resolved_backend = (\n            \"torchcodec\" if is_torchcodec_available() and version.parse(\"0.3.0\") <= TORCHCODEC_VERSION else \"librosa\"\n        )\n    elif backend in (\"torchcodec\", \"librosa\", \"torchaudio\"):\n        resolved_backend = backend\n    else:\n        raise ValueError(f\"Unknown backend {backend!r}; expected 'auto', 'torchcodec', 'librosa', or 'torchaudio'.\")\n    # soundfile-based backends (librosa / torchaudio) cannot decode the video-ish formats below.\n    use_torchcodec = resolved_backend == \"torchcodec\"\n\n    # 1. Identify the format from the source string (extension / `data:` media type), without fetching.\n    filetype = _format_from_source(audio)\n    # 2. With librosa as the only backend, fail fast and clearly on a format it cannot decode.\n    if not use_torchcodec and filetype in TORCHCODEC_ONLY_FILETYPES:\n        raise RuntimeError(\n            f\"The audio source is a '{filetype}' file, which librosa cannot decode. {_NEEDS_TORCHCODEC}\"\n        )\n\n    # 3. Resolve to local path or bytes; sniff format for raw base64 payloads before passing to librosa.\n    source = _resolve_audio_source(audio, timeout=timeout)\n    if not use_torchcodec and filetype is None and isinstance(source, bytes):\n        try:\n            filetype = get_audio_filetype(source)\n        except ValueError:\n            filetype = None","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/audio_utils.py#L219-L255","documentation":"The DeepGEMM Mega MoE fused path (`fp8_fp4_mega_moe`) requires both `hidden_dim` and the per-expert `intermediate_hidden` to be divisible by 32, because FP8 scale factors are laid out at 32-element granularity and the SF layout transform (`transform_sf_into_required_layout` with recipe (1, 32)) cannot handle remainders. The guard checks `module.hidden_dim % 32` and `module.intermediate_dim % 32` before packing weights.","triggerScenarios":"Selecting `experts_implementation='deepgemm_megamoe'` on an MoE whose `hidden_size` or `moe_intermediate_size` is not a multiple of 32 (e.g. 4096 is fine; 2048+4, 6144+16, or odd research dimensions are not).","commonSituations":"Custom/truncated architectures (pruned or width-modified MoEs) with unusual hidden sizes; converting non-standard checkpoints; student models distilled with irregular dims.","solutions":["Use a model whose `hidden_size` and `moe_intermediate_size` are multiples of 32 (virtually all published DeepSeek-style models are)","If you control the architecture, pad/adjust the dims to a multiple of 32","Otherwise use the standard `deepgemm` or `grouped_mm` experts dispatch, which does not have this fused-layout constraint"],"exampleFix":"# before\nclass CustomMoE(nn.Module):\n    hidden_dim = 4100      # not divisible by 32\n    intermediate_dim = 1100\nmodel.set_experts_implementation(\"deepgemm_megamoe\")  # -> ValueError\n\n# after\nclass CustomMoE(nn.Module):\n    hidden_dim = 4096      # divisible by 32\n    intermediate_dim = 1104","handlingStrategy":"validation","validationCode":"cfg = model.config\nh, i = cfg.hidden_size, cfg.moe_intermediate_size\nif h % 32 or i % 32:\n    model.set_experts_implementation(\"deepgemm\")  # megamoe needs dims divisible by 32","typeGuard":"def megamoe_compatible(cfg) -> bool:\n    return cfg.hidden_size % 32 == 0 and getattr(cfg, \"moe_intermediate_size\", 1) % 32 == 0","tryCatchPattern":null,"preventionTips":["Keep hidden and MoE intermediate dims multiples of 32 when designing for FP8 kernels","Validate model dims against kernel granularity before selecting megamoe"],"tags":["deepgemm","megamoe","tensor-shape","moe","model-config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}