Spaces:
Paused
Paused
count the cores the cgroup allows, not the host's
Browse files
app.py
CHANGED
|
@@ -51,6 +51,23 @@ os.environ["CMF_GPU"] = "0"
|
|
| 51 |
_model: str | None = None
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def binary() -> str:
|
| 55 |
if not BIN.exists():
|
| 56 |
BIN.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -151,7 +168,7 @@ def animate(prompt, width, height, frames, steps, progress=gr.Progress()):
|
|
| 151 |
|
| 152 |
wav = out.with_suffix(".wav")
|
| 153 |
gif = avi_to_gif(out, WORK / f"{tag}.gif")
|
| 154 |
-
log += f"\n{time.time() - t0:.0f} s on {
|
| 155 |
yield str(gif) if gif else None, str(wav) if wav.exists() else None, str(out), log
|
| 156 |
|
| 157 |
|
|
|
|
| 51 |
_model: str | None = None
|
| 52 |
|
| 53 |
|
| 54 |
+
def cores() -> str:
|
| 55 |
+
"""How many cores this container may actually use.
|
| 56 |
+
|
| 57 |
+
`os.cpu_count()` reports the HOST's, which on a Space is wildly wrong:
|
| 58 |
+
a cpu-basic container saw 16 while its quota was 2. The truth is the
|
| 59 |
+
cgroup v2 quota — "<quota> <period>" in microseconds, or "max" when
|
| 60 |
+
uncapped.
|
| 61 |
+
"""
|
| 62 |
+
try:
|
| 63 |
+
q, p = Path("/sys/fs/cgroup/cpu.max").read_text().split()
|
| 64 |
+
if q != "max":
|
| 65 |
+
return f"{int(q) / int(p):g} vCPU"
|
| 66 |
+
except Exception: # noqa: BLE001 — cgroup v1, macOS, anything else
|
| 67 |
+
pass
|
| 68 |
+
return f"{os.cpu_count()} vCPU"
|
| 69 |
+
|
| 70 |
+
|
| 71 |
def binary() -> str:
|
| 72 |
if not BIN.exists():
|
| 73 |
BIN.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 168 |
|
| 169 |
wav = out.with_suffix(".wav")
|
| 170 |
gif = avi_to_gif(out, WORK / f"{tag}.gif")
|
| 171 |
+
log += f"\n{time.time() - t0:.0f} s on {cores()}.\n"
|
| 172 |
yield str(gif) if gif else None, str(wav) if wav.exists() else None, str(out), log
|
| 173 |
|
| 174 |
|