opendatalab/MinerU · error · ValueError
OCR_INFERENCE_PRECISION must be one of: auto, fp32, fp16
Error message
OCR_INFERENCE_PRECISION must be one of: auto, fp32, fp16
What it means
Raised by BaseOCRV20._resolve_inference_dtype when the OCR_INFERENCE_PRECISION constant (typically sourced from an environment variable) lowercases to something other than auto, fp32, or fp16. The value controls whether the OCR network runs float32 on CPU / forced-fp32, or float16 elsewhere.
Source
Thrown at mineru/model/utils/pytorchocr/base_ocr_v20.py:32
class BaseOCRV20:
def __init__(self, config, **kwargs):
self.config = config
self.build_net(**kwargs)
self.ocr_inference_dtype = torch.float32
self.net.eval()
def build_net(self, **kwargs):
self.net = BaseModel(self.config, **kwargs)
def _resolve_inference_dtype(self, device):
"""根据常量和设备类型解析 OCR 网络推理使用的浮点精度。"""
precision = OCR_INFERENCE_PRECISION.lower()
device_name = str(device).lower()
is_cpu = device_name.startswith("cpu")
if precision not in {"auto", "fp32", "fp16"}:
raise ValueError(
"OCR_INFERENCE_PRECISION must be one of: auto, fp32, fp16"
)
if precision == "fp32" or is_cpu:
return torch.float32
return torch.float16
def _apply_inference_precision(self, device):
"""将 OCR 网络移动到目标设备,并在非 CPU 半精度场景下切到 fp16。"""
self.net.to(device)
self.ocr_inference_dtype = self._resolve_inference_dtype(device)
if self.ocr_inference_dtype == torch.float16:
self.net.to(dtype=torch.float16)
def _to_inference_dtype(self, tensor):
"""将浮点输入 tensor 转为 OCR 推理精度,整型/布尔辅助输入保持原 dtype。"""
if torch.is_tensor(tensor) and torch.is_floating_point(tensor):
inference_dtype = getattr(self, "ocr_inference_dtype", torch.float32)
return tensor.to(dtype=inference_dtype)View on GitHub (pinned to 4fe4bde114)
Solutions
- Set OCR_INFERENCE_PRECISION to one of: auto (fp16 on GPU, fp32 on CPU), fp32, or fp16.
- Unset the variable to fall back to the built-in default (auto).
- Check for typos like 'float16' vs 'fp16' in your environment/deployment config.
Example fix
# before export OCR_INFERENCE_PRECISION=bf16 # after export OCR_INFERENCE_PRECISION=fp16 # or fp32 / auto
Defensive patterns
Strategy: validation
Validate before calling
import os
precision = os.getenv("OCR_INFERENCE_PRECISION", "auto").lower()
assert precision in {"auto", "fp32", "fp16"}, f"bad OCR_INFERENCE_PRECISION: {precision!r}" Prevention
- Validate env vars at process start with a central config checker
- Document the three allowed values wherever the variable is referenced
- Add allowed-values comments in deployment manifests
When it happens
Trigger: Setting OCR_INFERENCE_PRECISION to values like 'bf16', 'fp8', 'float16', or 'FP16 ' (with trailing space handled, but e.g. 'fp_16' is not) before running mineru's pytorchocr pipeline.
Common situations: Users trying bfloat16 on newer GPUs; typo in .env or CI variables; deployment manifests that set the variable to an unsupported precision name.
Related errors
- Language {lang} not supported. Allowed values: {allowed_valu
- Language {lang} not supported
- not support limit type, image
- Unsupported lmdeploy device type: {device_type}
- Unsupported lmdeploy backend: {lm_backend}
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/211cc1c82e7760e2.
Report an issue: GitHub.