{"record":{"id":"cebe145688540005","repo":"hiyouga/LlamaFactory","slug":"unknown-sample-backend-args-sample-backend","errorCode":null,"errorMessage":"Unknown sample backend: {args.sample_backend}","messagePattern":"Unknown sample backend: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/core/base_sampler.py","lineNumber":43,"sourceCode":"\n    Args:\n        args: Sample arguments.\n        model_args: Model arguments.\n        model: Model.\n        renderer: Renderer.\n    \"\"\"\n\n    def __init__(\n        self,\n        args: SampleArguments,\n        model_args: ModelArguments,\n        model: HFModel,\n        renderer: Renderer,\n    ) -> None:\n        if args.sample_backend == SampleBackend.HF:\n            self.engine = HuggingFaceEngine(args, model_args, model, renderer)\n        else:\n            raise ValueError(f\"Unknown sample backend: {args.sample_backend}\")\n\n    async def generate(self, messages: list[Message], tools: str | None = None) -> AsyncGenerator[str, None]:\n        \"\"\"Generate tokens asynchronously.\n\n        Args:\n            messages: List of messages.\n            tools: Tools string.\n\n        Yields:\n            Generated tokens.\n        \"\"\"\n        async for token in self.engine.generate(messages, tools):\n            yield token\n\n    async def batch_infer(self, dataset: TorchDataset) -> list[Sample]:\n        \"\"\"Batch infer samples.\n\n        Args:","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/core/base_sampler.py#L25-L61","documentation":"`BaseSampler.__init__` in the v1 core only wires up `SampleBackend.HF` (the HuggingFace generation engine); any other value falls into the `else` branch and raises `Unknown sample backend`. It is an exhaustive-match guard: until more engines (vllm/sglang-style) are registered for v1 sampling, `hf` is the only accepted backend.","triggerScenarios":"Constructing a v1 `BaseSampler` (e.g. in RLHF/online sampling flows or `sample` entrypoint) with `sample_backend` set to anything other than `hf`, such as `vllm` or a typo.","commonSituations":"Porting a v0 chat/sampling config that used `vllm` or `sglang` engines into v1; assuming v1 supports the same backend list as v0's chat engines.","solutions":["Set `sample_backend: hf` in the v1 sample args","If you need vllm/sglang inference, use the v0 chat path (`USE_V1` unset) until v1 registers those engines","Check the `SampleBackend` enum for currently available members before choosing"],"exampleFix":"# before (yaml)\nsample:\n  sample_backend: vllm\n\n# after (yaml)\nsample:\n  sample_backend: hf","handlingStrategy":"type-guard","validationCode":"from llamafactory.v1.core.base_sampler import SampleBackend  # adjust import path\n\nif args.sample_backend not in {SampleBackend.HF}:\n    raise SystemExit(f\"v1 sampling currently supports only 'hf', got {args.sample_backend}\")","typeGuard":"def is_supported_sample_backend(value: object) -> bool:\n    return value == SampleBackend.HF","tryCatchPattern":null,"preventionTips":["Check the SampleBackend enum members shipped in your LlamaFactory version before configuring","Route vllm/sglang inference through the v0 chat engines until v1 support lands","Fail fast in orchestration code on unknown backend strings"],"tags":["v1","sampling","backend","configuration"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}