{"record":{"id":"2272f66e725658f2","repo":"karpathy/nanochat","slug":"only-tensorwise-recipe-is-supported-got-recip","errorCode":null,"errorMessage":"Only 'tensorwise' recipe is supported, got '{recipe_name}'. Rowwise/axiswise recipes require the full torchao library.","messagePattern":"Only 'tensorwise' recipe is supported, got '(.+?)'\\. Rowwise/axiswise recipes require the full torchao library\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"nanochat/fp8.py","lineNumber":236,"sourceCode":"\n        Uses meta device to avoid allocating a temporary weight tensor — we\n        create the module shell on meta (shapes/dtypes only, no memory), then\n        point .weight and .bias to the original module's parameters.\n        \"\"\"\n        with torch.device(\"meta\"):\n            new_mod = cls(mod.in_features, mod.out_features, bias=False)\n        new_mod.weight = mod.weight\n        new_mod.bias = mod.bias\n        return new_mod\n\n\nclass Float8LinearConfig:\n    \"\"\"Minimal config matching torchao's API. Only tensorwise recipe is supported.\"\"\"\n\n    @staticmethod\n    def from_recipe_name(recipe_name):\n        if recipe_name != \"tensorwise\":\n            raise ValueError(\n                f\"Only 'tensorwise' recipe is supported, got '{recipe_name}'. \"\n                f\"Rowwise/axiswise recipes require the full torchao library.\"\n            )\n        return Float8LinearConfig()\n\n\ndef convert_to_float8_training(module, *, config=None, module_filter_fn=None):\n    \"\"\"Replace nn.Linear layers with Float8Linear throughout a module.\n\n    Walks the module tree in post-order (children before parents) and swaps\n    each nn.Linear that passes the optional filter. The new Float8Linear shares\n    the original weight and bias tensors — no copies, no extra memory.\n\n    Args:\n        module: Root module to convert.\n        config: Float8LinearConfig (accepted for API compat, only tensorwise supported).\n        module_filter_fn: Optional filter(module, fqn) -> bool. Only matching Linears\n            are converted. Common use: skip layers with dims not divisible by 16","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/karpathy/nanochat/blob/92d63d4e8bb4df75c3b71618f31ddde2378b2bcd/nanochat/fp8.py#L218-L254","documentation":"nanochat/fp8.py ships a minimal, vendored subset of torchao's float8 training API. `Float8LinearConfig.from_recipe_name` accepts only the 'tensorwise' recipe (cast the whole tensor with a single scaling factor). Rowwise/axiswise per-channel recipes are intentionally unsupported because they require the full torchao library, so requesting one raises ValueError.","triggerScenarios":"Calling `Float8LinearConfig.from_recipe_name('rowwise')` or `'axiswise'` (or any non-'tensorwise' string) — typically via a training script flag like --fp8 recipe that is passed through to this factory.","commonSituations":"Copying a torchao float8 config from another project that used 'rowwise' and running it under nanochat's built-in fp8 path; upgrading scripts expecting full torchao recipe support.","solutions":["Use recipe_name='tensorwise' (or omit it) with nanochat's built-in fp8 path.","If you truly need rowwise/axiswise scaling, install and use the full torchao library (torchao.float8) instead of nanochat/fp8.py.","Check the training script's fp8 recipe argument and change its default."],"exampleFix":"# before\ncfg = Float8LinearConfig.from_recipe_name(\"rowwise\")\n\n# after\ncfg = Float8LinearConfig.from_recipe_name(\"tensorwise\")","handlingStrategy":"validation","validationCode":"recipe = \"tensorwise\"  # nanochat/fp8.py supports only this\nassert recipe == \"tensorwise\", \"use the full torchao library for rowwise/axiswise\"","typeGuard":"def is_supported_fp8_recipe(name: str) -> bool:\n    return name == \"tensorwise\"","tryCatchPattern":null,"preventionTips":["Pin the fp8 recipe flag in run scripts to 'tensorwise'.","If per-channel scaling is required, switch to torchao.float8 rather than nanochat's vendored subset."],"tags":["nanochat","fp8","quantization","torchao","configuration"],"backgroundTag":null,"analyzedSha":"92d63d4e8bb4df75c3b71618f31ddde2378b2bcd","analyzedAt":"2026-08-15T03:11:54.371Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}