Christen Millerdurai commited on
Commit
08639bd
·
1 Parent(s): 237ddb2

reducing dependancy installations

Browse files
Files changed (3) hide show
  1. README.md +4 -2
  2. app.py +58 -2
  3. requirements.txt +3 -0
README.md CHANGED
@@ -10,16 +10,18 @@ app_file: app.py
10
  pinned: false
11
  license: cc-by-nc-4.0
12
  short_description: Forearm-Guided Camera-Space 3D Hand Pose
13
- suggested_hardware: a10g-small
14
  startup_duration_timeout: 1h
15
  ---
16
 
17
- This Space runs the EgoForce video demo with the Hugging Face Gradio SDK.
18
 
19
  At startup, `app.py`:
20
 
21
  - Clones `https://github.com/dfki-av/EgoForce` into the Space runtime.
 
22
  - Downloads the `_DATA` model assets from `chris10/EgoForce` on the Hugging Face Hub.
23
  - Launches the upstream Gradio demo at `demo/run_app.py`.
24
 
25
  Most Python dependencies are declared in `requirements.txt`, with build prerequisites in `pre-requirements.txt`. Packages that need custom pip flags or repo-local subdirectories are installed by `app.py` after the EgoForce source checkout. Debian packages needed for OpenCV, ffmpeg, headless rendering, and compiled extensions are declared in `packages.txt`.
 
 
 
10
  pinned: false
11
  license: cc-by-nc-4.0
12
  short_description: Forearm-Guided Camera-Space 3D Hand Pose
 
13
  startup_duration_timeout: 1h
14
  ---
15
 
16
+ This Space runs the EgoForce video demo with the Hugging Face Gradio SDK and is prepared for ZeroGPU hardware.
17
 
18
  At startup, `app.py`:
19
 
20
  - Clones `https://github.com/dfki-av/EgoForce` into the Space runtime.
21
+ - Patches the upstream Gradio callback with `@spaces.GPU` so video inference runs inside ZeroGPU's dynamic CUDA allocation.
22
  - Downloads the `_DATA` model assets from `chris10/EgoForce` on the Hugging Face Hub.
23
  - Launches the upstream Gradio demo at `demo/run_app.py`.
24
 
25
  Most Python dependencies are declared in `requirements.txt`, with build prerequisites in `pre-requirements.txt`. Packages that need custom pip flags or repo-local subdirectories are installed by `app.py` after the EgoForce source checkout. Debian packages needed for OpenCV, ffmpeg, headless rendering, and compiled extensions are declared in `packages.txt`.
26
+
27
+ Select `ZeroGPU` in the Space hardware settings. `ZEROGPU_DURATION_SECONDS` defaults to `600`, and `ZEROGPU_SIZE` defaults to `large`.
app.py CHANGED
@@ -15,6 +15,8 @@ EGOFORCE_REPO_URL = os.environ.get("EGOFORCE_REPO_URL", "https://github.com/dfki
15
  EGOFORCE_REF = os.environ.get("EGOFORCE_REF", "main")
16
  EGOFORCE_ROOT = Path(os.environ.get("EGOFORCE_ROOT", SPACE_ROOT / "EgoForce")).resolve()
17
  EGOFORCE_ASSETS_REPO_ID = os.environ.get("EGOFORCE_ASSETS_REPO_ID", "chris10/EgoForce")
 
 
18
 
19
 
20
  def run_command(command: list[str], cwd: Path | None = None) -> None:
@@ -26,12 +28,37 @@ def configure_runtime_environment() -> None:
26
  os.environ.setdefault("EGOFORCE_ROOT", str(EGOFORCE_ROOT))
27
  configure_cuda_environment()
28
  os.environ.setdefault("FORCE_CUDA", "1")
29
- os.environ.setdefault("TORCH_CUDA_ARCH_LIST", "7.5;8.0;8.6;8.9")
 
 
 
 
30
  os.environ.setdefault("PYOPENGL_PLATFORM", "egl")
31
  os.environ.setdefault("MPLBACKEND", "Agg")
32
  os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def candidate_site_packages() -> list[Path]:
36
  paths = [Path(path) for path in site.getsitepackages()]
37
  user_site = site.getusersitepackages()
@@ -64,6 +91,7 @@ def configure_cuda_environment() -> None:
64
  def ensure_egoforce_repo() -> Path:
65
  demo_entrypoint = EGOFORCE_ROOT / "demo" / "run_app.py"
66
  if demo_entrypoint.exists():
 
67
  return EGOFORCE_ROOT
68
 
69
  if EGOFORCE_ROOT.exists() and any(EGOFORCE_ROOT.iterdir()):
@@ -85,9 +113,36 @@ def ensure_egoforce_repo() -> Path:
85
  if not demo_entrypoint.exists():
86
  raise RuntimeError(f"EgoForce demo entrypoint not found at {demo_entrypoint}")
87
 
 
88
  return EGOFORCE_ROOT
89
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  def package_available(module_name: str) -> bool:
92
  return importlib.util.find_spec(module_name) is not None
93
 
@@ -99,6 +154,7 @@ def pip_install(requirement: str, *extra_args: str) -> None:
99
  "pip",
100
  "install",
101
  "--no-cache-dir",
 
102
  requirement,
103
  *extra_args,
104
  ]
@@ -108,7 +164,7 @@ def pip_install(requirement: str, *extra_args: str) -> None:
108
  def ensure_runtime_python_packages(repo_root: Path) -> None:
109
  datapipes_path = repo_root / "thirdparty" / "datapipes"
110
  install_plan = [
111
- ("mmcv", "mmcv==2.1.0", ("--no-build-isolation",)),
112
  ("anycalib", "git+https://github.com/javrtg/AnyCalib.git", ("--no-build-isolation",)),
113
  ("chumpy", "git+https://github.com/mattloper/chumpy.git", ("--no-build-isolation",)),
114
  ("pytorch3d", "git+https://github.com/facebookresearch/pytorch3d.git", ("--no-build-isolation",)),
 
15
  EGOFORCE_REF = os.environ.get("EGOFORCE_REF", "main")
16
  EGOFORCE_ROOT = Path(os.environ.get("EGOFORCE_ROOT", SPACE_ROOT / "EgoForce")).resolve()
17
  EGOFORCE_ASSETS_REPO_ID = os.environ.get("EGOFORCE_ASSETS_REPO_ID", "chris10/EgoForce")
18
+ ZEROGPU_DURATION_SECONDS = os.environ.get("ZEROGPU_DURATION_SECONDS", "600")
19
+ ZEROGPU_SIZE = os.environ.get("ZEROGPU_SIZE", "large")
20
 
21
 
22
  def run_command(command: list[str], cwd: Path | None = None) -> None:
 
28
  os.environ.setdefault("EGOFORCE_ROOT", str(EGOFORCE_ROOT))
29
  configure_cuda_environment()
30
  os.environ.setdefault("FORCE_CUDA", "1")
31
+ configure_torch_cuda_arch_list()
32
+ os.environ.setdefault("MAX_JOBS", "1")
33
+ os.environ.setdefault("CMAKE_BUILD_PARALLEL_LEVEL", "1")
34
+ os.environ.setdefault("NINJAFLAGS", "-j1")
35
+ os.environ.setdefault("MAKEFLAGS", "-j1")
36
  os.environ.setdefault("PYOPENGL_PLATFORM", "egl")
37
  os.environ.setdefault("MPLBACKEND", "Agg")
38
  os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
39
 
40
 
41
+ def configure_torch_cuda_arch_list() -> None:
42
+ if os.environ.get("TORCH_CUDA_ARCH_LIST"):
43
+ return
44
+
45
+ accelerator = os.environ.get("ACCELERATOR", "").lower()
46
+ if "zero" in accelerator or "h200" in accelerator:
47
+ arch_list = "9.0"
48
+ elif "t4" in accelerator:
49
+ arch_list = "7.5"
50
+ elif "a100" in accelerator:
51
+ arch_list = "8.0"
52
+ elif "a10g" in accelerator:
53
+ arch_list = "8.6"
54
+ elif "l4" in accelerator or "l40" in accelerator:
55
+ arch_list = "8.9"
56
+ else:
57
+ arch_list = "9.0"
58
+
59
+ os.environ["TORCH_CUDA_ARCH_LIST"] = arch_list
60
+
61
+
62
  def candidate_site_packages() -> list[Path]:
63
  paths = [Path(path) for path in site.getsitepackages()]
64
  user_site = site.getusersitepackages()
 
91
  def ensure_egoforce_repo() -> Path:
92
  demo_entrypoint = EGOFORCE_ROOT / "demo" / "run_app.py"
93
  if demo_entrypoint.exists():
94
+ patch_upstream_gradio_for_zerogpu(demo_entrypoint)
95
  return EGOFORCE_ROOT
96
 
97
  if EGOFORCE_ROOT.exists() and any(EGOFORCE_ROOT.iterdir()):
 
113
  if not demo_entrypoint.exists():
114
  raise RuntimeError(f"EgoForce demo entrypoint not found at {demo_entrypoint}")
115
 
116
+ patch_upstream_gradio_for_zerogpu(demo_entrypoint)
117
  return EGOFORCE_ROOT
118
 
119
 
120
+ def patch_upstream_gradio_for_zerogpu(demo_entrypoint: Path) -> None:
121
+ source = demo_entrypoint.read_text(encoding="utf-8")
122
+
123
+ if "import spaces\n" not in source:
124
+ if "import torch\n" not in source:
125
+ raise RuntimeError(f"Could not insert ZeroGPU import in {demo_entrypoint}")
126
+ source = source.replace("import torch\n", "import spaces\nimport torch\n", 1)
127
+
128
+ if "@spaces.GPU(" not in source:
129
+ if "def process_video(\n" not in source:
130
+ raise RuntimeError(f"Could not locate process_video in {demo_entrypoint}")
131
+ source = source.replace(
132
+ "def process_video(\n",
133
+ (
134
+ "@spaces.GPU("
135
+ f"duration={int(ZEROGPU_DURATION_SECONDS)}, "
136
+ f"size={ZEROGPU_SIZE!r}"
137
+ ")\n"
138
+ "def process_video(\n"
139
+ ),
140
+ 1,
141
+ )
142
+
143
+ demo_entrypoint.write_text(source, encoding="utf-8")
144
+
145
+
146
  def package_available(module_name: str) -> bool:
147
  return importlib.util.find_spec(module_name) is not None
148
 
 
154
  "pip",
155
  "install",
156
  "--no-cache-dir",
157
+ "--disable-pip-version-check",
158
  requirement,
159
  *extra_args,
160
  ]
 
164
  def ensure_runtime_python_packages(repo_root: Path) -> None:
165
  datapipes_path = repo_root / "thirdparty" / "datapipes"
166
  install_plan = [
167
+ ("mmcv", "mmcv==2.1.0", ("--no-build-isolation", "--no-deps")),
168
  ("anycalib", "git+https://github.com/javrtg/AnyCalib.git", ("--no-build-isolation",)),
169
  ("chumpy", "git+https://github.com/mattloper/chumpy.git", ("--no-build-isolation",)),
170
  ("pytorch3d", "git+https://github.com/facebookresearch/pytorch3d.git", ("--no-build-isolation",)),
requirements.txt CHANGED
@@ -22,6 +22,8 @@ pycocotools==2.0.10
22
  trimesh==4.11.3
23
  sortedcontainers==2.4.0
24
  openmim==0.3.9
 
 
25
  lmdb==2.0.0
26
  ultralytics==8.4.23
27
  lap==0.5.13
@@ -32,3 +34,4 @@ yacs==0.1.8
32
  projectaria_client_sdk==1.1.0
33
  huggingface_hub
34
  hf_xet
 
 
22
  trimesh==4.11.3
23
  sortedcontainers==2.4.0
24
  openmim==0.3.9
25
+ mmengine==0.10.7
26
+ yapf==0.43.0
27
  lmdb==2.0.0
28
  ultralytics==8.4.23
29
  lap==0.5.13
 
34
  projectaria_client_sdk==1.1.0
35
  huggingface_hub
36
  hf_xet
37
+ spaces