Spaces:
Running
Running
Restore docker_patch.py from Make-It-Animatable
Browse files- docker_patch.py +37 -0
docker_patch.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build-only patches to the pinned existing upstream; never modifies /data."""
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import shutil
|
| 4 |
+
root = Path("/opt/space/upstream")
|
| 5 |
+
|
| 6 |
+
def replace(path,old,new,count=1):
|
| 7 |
+
source=path.read_text()
|
| 8 |
+
if source.count(old) != count:
|
| 9 |
+
raise RuntimeError(f"Upstream patch mismatch: {path} expected {count} occurrences of {old!r}")
|
| 10 |
+
path.write_text(source.replace(old,new))
|
| 11 |
+
|
| 12 |
+
app=root/"app.py"
|
| 13 |
+
replace(app,"import spaces # isort:skip","")
|
| 14 |
+
replace(app,"@spaces.GPU\n","",2)
|
| 15 |
+
replace(app,'device = torch.device("cuda" if torch.cuda.is_available() else "cpu")',
|
| 16 |
+
'assert torch.cuda.is_available(), "Dedicated CUDA GPU required"\n device = torch.device("cuda")')
|
| 17 |
+
replace(app," cmd += \" > /dev/null 2>&1\"",
|
| 18 |
+
' cmd += ""')
|
| 19 |
+
replace(app," os.system(cmd)",
|
| 20 |
+
' import shlex, subprocess\n subprocess.run(shlex.split(cmd), check=True, timeout=300)')
|
| 21 |
+
replace(app,' fbx2glb_cmd += " > /dev/null 2>&1"',
|
| 22 |
+
' fbx2glb_cmd += ""')
|
| 23 |
+
replace(app," os.system(fbx2glb_cmd)",
|
| 24 |
+
' import shlex, subprocess\n subprocess.run(shlex.split(fbx2glb_cmd), check=True, timeout=300)')
|
| 25 |
+
additional=root/"util/dataset_mixamo_additional.py"
|
| 26 |
+
old='KINEMATIC_TREE = get_kinematic_tree(TEMPLATE_PATH, BONES_IDX_DICT)\nassert len(KINEMATIC_TREE) == len(MIXAMO_JOINTS)'
|
| 27 |
+
new='if os.path.isfile(TEMPLATE_PATH):\n KINEMATIC_TREE = get_kinematic_tree(TEMPLATE_PATH, BONES_IDX_DICT)\n assert len(KINEMATIC_TREE) == len(MIXAMO_JOINTS)\nelse:\n KINEMATIC_TREE = dataset_mixamo.KINEMATIC_TREE'
|
| 28 |
+
replace(additional,old,new)
|
| 29 |
+
for name in ("data","output"):
|
| 30 |
+
path=root/name
|
| 31 |
+
backup=root/(name+".bundled")
|
| 32 |
+
if path.exists():
|
| 33 |
+
# Docker COPY inputs may be a separate mount; rename can fail EXDEV.
|
| 34 |
+
# Copy then remove in the image so runtime can make the /data symlink.
|
| 35 |
+
shutil.copytree(path,backup,symlinks=True)
|
| 36 |
+
shutil.rmtree(path)
|
| 37 |
+
print("BUILD_PATCH_PASS: dedicated CUDA, checked exports, standard skeleton")
|