Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Fix torch dependency in cua-agent

Dillon DuPont090edb8f3356
diff --git a/libs/python/agent/agent/loops/moondream3.py b/libs/python/agent/agent/loops/moondream3.py
index 140c9cb404..5f6a85fd0c 100644
--- a/libs/python/agent/agent/loops/moondream3.py
+++ b/libs/python/agent/agent/loops/moondream3.py
@@ -20,8 +20,6 @@ import io
from typing import Dict, List, Any, Optional, Tuple, Any
from PIL import Image, ImageDraw, ImageFont
-import torch
-from transformers import AutoModelForCausalLM
import litellm
from ..decorators import register_agent
@@ -41,12 +39,19 @@ def get_moondream_model() -> Any:
"""Get a singleton instance of the Moondream3 preview model."""
global _MOONDREAM_SINGLETON
if _MOONDREAM_SINGLETON is None:
- _MOONDREAM_SINGLETON = AutoModelForCausalLM.from_pretrained(
- "moondream/moondream3-preview",
- trust_remote_code=True,
- torch_dtype=torch.bfloat16,
- device_map="cuda",
- )
+ try:
+ import torch
+ from transformers import AutoModelForCausalLM
+ _MOONDREAM_SINGLETON = AutoModelForCausalLM.from_pretrained(
+ "moondream/moondream3-preview",
+ trust_remote_code=True,
+ torch_dtype=torch.bfloat16,
+ device_map="cuda",
+ )
+ except ImportError as e:
+ raise RuntimeError(
+ "moondream3 requires torch and transformers. Install with: pip install cua-agent[moondream3]"
+ ) from e
return _MOONDREAM_SINGLETON
diff --git a/libs/python/agent/pyproject.toml b/libs/python/agent/pyproject.toml
index e9064f491b..de735b7f94 100644
--- a/libs/python/agent/pyproject.toml
+++ b/libs/python/agent/pyproject.toml
@@ -60,6 +60,11 @@ internvl-hf = [
"einops",
"timm"
]
+moondream3 = [
+ "accelerate",
+ "torch",
+ "transformers>=4.55.0"
+]
ui = [
"gradio>=5.23.3",
"python-dotenv>=1.0.1",