{"record":{"id":"7aec4eceb404bbb5","repo":"invoke-ai/InvokeAI","slug":"expected-llavaonevisionforconditionalgeneration-g","errorCode":null,"errorMessage":"Expected LlavaOnevisionForConditionalGeneration, got {type(model).__name__}","messagePattern":"Expected LlavaOnevisionForConditionalGeneration, got (.+?)","errorType":"http","errorClass":"TypeError","httpStatus":422,"severity":"error","filePath":"invokeai/app/api/routers/utilities.py","lineNumber":266,"sourceCode":"    events = ApiDependencies.invoker.services.events\n    model_config = model_manager.store.get_model(model_key)\n\n    if model_config.type != ModelType.LlavaOnevision:\n        raise ValueError(f\"Model '{model_key}' is not a LLaVA OneVision model (got {model_config.type})\")\n\n    if task_id is not None:\n        events.emit_llm_task_progress(task_id=task_id, user_id=user_id, phase=\"loading_model\", message=\"Loading model\")\n\n    with _model_load_lock:\n        loaded_model = model_manager.load.load_model(model_config, user_id=user_id)\n\n    # Load the image from InvokeAI's image store\n    image = ApiDependencies.invoker.services.images.get_pil_image(image_name)\n    image = image.convert(\"RGB\")\n\n    with torch.no_grad(), loaded_model.model_on_device() as (_, model):\n        if not isinstance(model, LlavaOnevisionForConditionalGeneration):\n            raise TypeError(f\"Expected LlavaOnevisionForConditionalGeneration, got {type(model).__name__}\")\n\n        model_abs_path = _resolve_model_path(model_config.path)\n        processor = AutoProcessor.from_pretrained(model_abs_path, local_files_only=True)\n        if not isinstance(processor, LlavaOnevisionProcessor):\n            raise TypeError(f\"Expected LlavaOnevisionProcessor, got {type(processor).__name__}\")\n\n        pipeline = LlavaOnevisionPipeline(model, processor)\n        model_device = next(model.parameters()).device\n\n        progress_callback = _make_progress_callback(events, task_id, user_id)\n\n        output = pipeline.run(\n            prompt=instruction,\n            images=[image],\n            device=model_device,\n            dtype=TorchDevice.choose_torch_dtype(),\n            progress_callback=progress_callback,\n        )","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/utilities.py#L248-L284","documentation":"_run_image_to_prompt loads a LLaVA OneVision model via the model manager and, once it is resident on the device, asserts the loaded object is a transformers LlavaOnevisionForConditionalGeneration. If InvokeAI's loader returned some other module object (different model type, stub, or class from an incompatible transformers version), the isinstance check fails and this TypeError is raised. It guards the downstream LlavaOnevisionPipeline, which can only accept that exact class.","triggerScenarios":"POST /utilities/image_to_prompt with a model_key whose loaded model is not a LlavaOnevisionForConditionalGeneration — e.g. the model manager load path returned a raw module wrapper, the installed transformers version lacks/moved LlavaOnevisionForConditionalGeneration, or the model_config was mutated so a non-LLaVA checkpoint is loaded under a LlavaOnevision config.","commonSituations":"transformers version drift (LlavaOnevision classes only exist in transformers >= 4.45), custom model-manager loaders returning BaseModelClass instances instead of the raw HF module, checkpoints mislabeled as LlavaOnevision in the model record, or monkeypatched test doubles.","solutions":["Upgrade/align the installed transformers version so LlavaOnevisionForConditionalGeneration imports from the same package InvokeAI's loader instantiates","Verify the model record (model_key) actually points to a LLaVA OneVision checkpoint and its config is not corrupted","Check for duplicate transformers installs or a vendored copy shadowing the real package (pip show transformers, sys.path order)","Inspect the loader path (model_manager.load.load_model / model_on_device) to confirm what object it returns"],"exampleFix":"# before\nwith torch.no_grad(), loaded_model.model_on_device() as (_, model):\n    pipeline = LlavaOnevisionPipeline(model, processor)\n# after\nwith torch.no_grad(), loaded_model.model_on_device() as (_, model):\n    if not isinstance(model, LlavaOnevisionForConditionalGeneration):\n        raise TypeError(f\"Expected LlavaOnevisionForConditionalGeneration, got {type(model).__name__}\")\n    pipeline = LlavaOnevisionPipeline(model, processor)","handlingStrategy":"type-guard","validationCode":"import transformers\nfrom transformers import LlavaOnevisionForConditionalGeneration\nassert hasattr(transformers, \"LlavaOnevisionForConditionalGeneration\"), \"upgrade transformers >= 4.45\"","typeGuard":"def is_llava_onevision_model(model) -> bool:\n    from transformers import LlavaOnevisionForConditionalGeneration\n    return isinstance(model, LlavaOnevisionForConditionalGeneration)","tryCatchPattern":"try:\n    prompt = requests.post(f\"{base}/utilities/image_to_prompt\", json={...}).raise_for_status().json()[\"prompt\"]\nexcept requests.HTTPError as e:\n    if e.response.status_code == 422 and \"Expected LlavaOnevisionForConditionalGeneration\" in e.response.text:\n        fix_model_install()","preventionTips":["Pin the transformers version InvokeAI was tested against","Validate the checkpoint is a genuine llava-onevision download (config.json architectures field)","Watch for duplicate transformers installs in the environment"],"tags":["transformers","type-mismatch","llava","model-loading"],"backgroundTag":"model-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}