Sync from GitHub via hub-sync
Browse files- glm-ocr.py +70 -1
- jina-ocr-v1.py +70 -1
- lighton-ocr2-server.py +70 -1
- nanonets-ocr.py +70 -1
- ovis-ocr2-server.py +70 -1
- ovis-ocr2.py +70 -1
- rolm-ocr.py +70 -1
glm-ocr.py
CHANGED
|
@@ -174,6 +174,75 @@ def make_ocr_message(
|
|
| 174 |
]
|
| 175 |
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
def create_dataset_card(
|
| 178 |
source_dataset: str,
|
| 179 |
model: str,
|
|
@@ -199,7 +268,7 @@ def create_dataset_card(
|
|
| 199 |
|
| 200 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 201 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 202 |
-
hw =
|
| 203 |
origin = (
|
| 204 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 205 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 174 |
]
|
| 175 |
|
| 176 |
|
| 177 |
+
def jobs_flavor() -> str:
|
| 178 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 179 |
+
|
| 180 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 181 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 182 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 183 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 184 |
+
"""
|
| 185 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 186 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 187 |
+
return hardware # already a flavor name
|
| 188 |
+
try:
|
| 189 |
+
from huggingface_hub import HfApi
|
| 190 |
+
|
| 191 |
+
gpu_name, gpu_count = "", 0
|
| 192 |
+
try:
|
| 193 |
+
import torch
|
| 194 |
+
|
| 195 |
+
if torch.cuda.is_available():
|
| 196 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 197 |
+
gpu_count = torch.cuda.device_count()
|
| 198 |
+
except ImportError:
|
| 199 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 200 |
+
import subprocess
|
| 201 |
+
|
| 202 |
+
try:
|
| 203 |
+
listed = subprocess.run(
|
| 204 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 205 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 206 |
+
).stdout
|
| 207 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 208 |
+
if names:
|
| 209 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 210 |
+
except (OSError, subprocess.SubprocessError):
|
| 211 |
+
pass
|
| 212 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 213 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 214 |
+
|
| 215 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 216 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 217 |
+
candidates = []
|
| 218 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 219 |
+
accelerator = flavor.accelerator
|
| 220 |
+
if gpu_count == 0 and accelerator is None:
|
| 221 |
+
candidates.append(flavor)
|
| 222 |
+
elif (
|
| 223 |
+
gpu_count > 0
|
| 224 |
+
and accelerator is not None
|
| 225 |
+
and accelerator.model.upper() in gpu_words
|
| 226 |
+
and int(accelerator.quantity) == gpu_count
|
| 227 |
+
):
|
| 228 |
+
candidates.append(flavor)
|
| 229 |
+
if not candidates:
|
| 230 |
+
return ""
|
| 231 |
+
|
| 232 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 233 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 234 |
+
|
| 235 |
+
def distance(flavor) -> float:
|
| 236 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 237 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 238 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 239 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 240 |
+
|
| 241 |
+
return min(candidates, key=distance).name
|
| 242 |
+
except Exception:
|
| 243 |
+
return ""
|
| 244 |
+
|
| 245 |
+
|
| 246 |
def create_dataset_card(
|
| 247 |
source_dataset: str,
|
| 248 |
model: str,
|
|
|
|
| 268 |
|
| 269 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 270 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 271 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 272 |
origin = (
|
| 273 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 274 |
+ (f" (`{hw}`)" if hw else "")
|
jina-ocr-v1.py
CHANGED
|
@@ -142,6 +142,75 @@ def load_model_glue(revision: str | None):
|
|
| 142 |
return snapshot, deepseek_ocr_mtp
|
| 143 |
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
def create_dataset_card(
|
| 146 |
source_dataset: str,
|
| 147 |
num_samples: int,
|
|
@@ -157,7 +226,7 @@ def create_dataset_card(
|
|
| 157 |
image_count_per_sec: float,
|
| 158 |
) -> str:
|
| 159 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 160 |
-
hw =
|
| 161 |
origin = (
|
| 162 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 163 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 142 |
return snapshot, deepseek_ocr_mtp
|
| 143 |
|
| 144 |
|
| 145 |
+
def jobs_flavor() -> str:
|
| 146 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 147 |
+
|
| 148 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 149 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 150 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 151 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 152 |
+
"""
|
| 153 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 154 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 155 |
+
return hardware # already a flavor name
|
| 156 |
+
try:
|
| 157 |
+
from huggingface_hub import HfApi
|
| 158 |
+
|
| 159 |
+
gpu_name, gpu_count = "", 0
|
| 160 |
+
try:
|
| 161 |
+
import torch
|
| 162 |
+
|
| 163 |
+
if torch.cuda.is_available():
|
| 164 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 165 |
+
gpu_count = torch.cuda.device_count()
|
| 166 |
+
except ImportError:
|
| 167 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 168 |
+
import subprocess
|
| 169 |
+
|
| 170 |
+
try:
|
| 171 |
+
listed = subprocess.run(
|
| 172 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 173 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 174 |
+
).stdout
|
| 175 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 176 |
+
if names:
|
| 177 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 178 |
+
except (OSError, subprocess.SubprocessError):
|
| 179 |
+
pass
|
| 180 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 181 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 182 |
+
|
| 183 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 184 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 185 |
+
candidates = []
|
| 186 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 187 |
+
accelerator = flavor.accelerator
|
| 188 |
+
if gpu_count == 0 and accelerator is None:
|
| 189 |
+
candidates.append(flavor)
|
| 190 |
+
elif (
|
| 191 |
+
gpu_count > 0
|
| 192 |
+
and accelerator is not None
|
| 193 |
+
and accelerator.model.upper() in gpu_words
|
| 194 |
+
and int(accelerator.quantity) == gpu_count
|
| 195 |
+
):
|
| 196 |
+
candidates.append(flavor)
|
| 197 |
+
if not candidates:
|
| 198 |
+
return ""
|
| 199 |
+
|
| 200 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 201 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 202 |
+
|
| 203 |
+
def distance(flavor) -> float:
|
| 204 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 205 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 206 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 207 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 208 |
+
|
| 209 |
+
return min(candidates, key=distance).name
|
| 210 |
+
except Exception:
|
| 211 |
+
return ""
|
| 212 |
+
|
| 213 |
+
|
| 214 |
def create_dataset_card(
|
| 215 |
source_dataset: str,
|
| 216 |
num_samples: int,
|
|
|
|
| 226 |
image_count_per_sec: float,
|
| 227 |
) -> str:
|
| 228 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 229 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 230 |
origin = (
|
| 231 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 232 |
+ (f" (`{hw}`)" if hw else "")
|
lighton-ocr2-server.py
CHANGED
|
@@ -242,6 +242,75 @@ def ocr_one(
|
|
| 242 |
raise RuntimeError(f"request failed after {retries + 1} attempts: {last_err}")
|
| 243 |
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
def create_dataset_card(
|
| 246 |
source_dataset: str,
|
| 247 |
model: str,
|
|
@@ -261,7 +330,7 @@ def create_dataset_card(
|
|
| 261 |
|
| 262 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 263 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 264 |
-
hw =
|
| 265 |
origin = (
|
| 266 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 267 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 242 |
raise RuntimeError(f"request failed after {retries + 1} attempts: {last_err}")
|
| 243 |
|
| 244 |
|
| 245 |
+
def jobs_flavor() -> str:
|
| 246 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 247 |
+
|
| 248 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 249 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 250 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 251 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 252 |
+
"""
|
| 253 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 254 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 255 |
+
return hardware # already a flavor name
|
| 256 |
+
try:
|
| 257 |
+
from huggingface_hub import HfApi
|
| 258 |
+
|
| 259 |
+
gpu_name, gpu_count = "", 0
|
| 260 |
+
try:
|
| 261 |
+
import torch
|
| 262 |
+
|
| 263 |
+
if torch.cuda.is_available():
|
| 264 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 265 |
+
gpu_count = torch.cuda.device_count()
|
| 266 |
+
except ImportError:
|
| 267 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 268 |
+
import subprocess
|
| 269 |
+
|
| 270 |
+
try:
|
| 271 |
+
listed = subprocess.run(
|
| 272 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 273 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 274 |
+
).stdout
|
| 275 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 276 |
+
if names:
|
| 277 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 278 |
+
except (OSError, subprocess.SubprocessError):
|
| 279 |
+
pass
|
| 280 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 281 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 282 |
+
|
| 283 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 284 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 285 |
+
candidates = []
|
| 286 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 287 |
+
accelerator = flavor.accelerator
|
| 288 |
+
if gpu_count == 0 and accelerator is None:
|
| 289 |
+
candidates.append(flavor)
|
| 290 |
+
elif (
|
| 291 |
+
gpu_count > 0
|
| 292 |
+
and accelerator is not None
|
| 293 |
+
and accelerator.model.upper() in gpu_words
|
| 294 |
+
and int(accelerator.quantity) == gpu_count
|
| 295 |
+
):
|
| 296 |
+
candidates.append(flavor)
|
| 297 |
+
if not candidates:
|
| 298 |
+
return ""
|
| 299 |
+
|
| 300 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 301 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 302 |
+
|
| 303 |
+
def distance(flavor) -> float:
|
| 304 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 305 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 306 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 307 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 308 |
+
|
| 309 |
+
return min(candidates, key=distance).name
|
| 310 |
+
except Exception:
|
| 311 |
+
return ""
|
| 312 |
+
|
| 313 |
+
|
| 314 |
def create_dataset_card(
|
| 315 |
source_dataset: str,
|
| 316 |
model: str,
|
|
|
|
| 330 |
|
| 331 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 332 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 333 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 334 |
origin = (
|
| 335 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 336 |
+ (f" (`{hw}`)" if hw else "")
|
nanonets-ocr.py
CHANGED
|
@@ -115,6 +115,75 @@ def make_ocr_message(
|
|
| 115 |
]
|
| 116 |
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
def create_dataset_card(
|
| 119 |
source_dataset: str,
|
| 120 |
model: str,
|
|
@@ -132,7 +201,7 @@ def create_dataset_card(
|
|
| 132 |
|
| 133 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 134 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 135 |
-
hw =
|
| 136 |
origin = (
|
| 137 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 138 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 115 |
]
|
| 116 |
|
| 117 |
|
| 118 |
+
def jobs_flavor() -> str:
|
| 119 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 120 |
+
|
| 121 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 122 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 123 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 124 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 125 |
+
"""
|
| 126 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 127 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 128 |
+
return hardware # already a flavor name
|
| 129 |
+
try:
|
| 130 |
+
from huggingface_hub import HfApi
|
| 131 |
+
|
| 132 |
+
gpu_name, gpu_count = "", 0
|
| 133 |
+
try:
|
| 134 |
+
import torch
|
| 135 |
+
|
| 136 |
+
if torch.cuda.is_available():
|
| 137 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 138 |
+
gpu_count = torch.cuda.device_count()
|
| 139 |
+
except ImportError:
|
| 140 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 141 |
+
import subprocess
|
| 142 |
+
|
| 143 |
+
try:
|
| 144 |
+
listed = subprocess.run(
|
| 145 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 146 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 147 |
+
).stdout
|
| 148 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 149 |
+
if names:
|
| 150 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 151 |
+
except (OSError, subprocess.SubprocessError):
|
| 152 |
+
pass
|
| 153 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 154 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 155 |
+
|
| 156 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 157 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 158 |
+
candidates = []
|
| 159 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 160 |
+
accelerator = flavor.accelerator
|
| 161 |
+
if gpu_count == 0 and accelerator is None:
|
| 162 |
+
candidates.append(flavor)
|
| 163 |
+
elif (
|
| 164 |
+
gpu_count > 0
|
| 165 |
+
and accelerator is not None
|
| 166 |
+
and accelerator.model.upper() in gpu_words
|
| 167 |
+
and int(accelerator.quantity) == gpu_count
|
| 168 |
+
):
|
| 169 |
+
candidates.append(flavor)
|
| 170 |
+
if not candidates:
|
| 171 |
+
return ""
|
| 172 |
+
|
| 173 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 174 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 175 |
+
|
| 176 |
+
def distance(flavor) -> float:
|
| 177 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 178 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 179 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 180 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 181 |
+
|
| 182 |
+
return min(candidates, key=distance).name
|
| 183 |
+
except Exception:
|
| 184 |
+
return ""
|
| 185 |
+
|
| 186 |
+
|
| 187 |
def create_dataset_card(
|
| 188 |
source_dataset: str,
|
| 189 |
model: str,
|
|
|
|
| 201 |
|
| 202 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 203 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 204 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 205 |
origin = (
|
| 206 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 207 |
+ (f" (`{hw}`)" if hw else "")
|
ovis-ocr2-server.py
CHANGED
|
@@ -325,6 +325,75 @@ def ocr_one(
|
|
| 325 |
raise RuntimeError(f"request failed after {retries + 1} attempts: {last_err}")
|
| 326 |
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
def create_dataset_card(
|
| 329 |
source_dataset: str,
|
| 330 |
model: str,
|
|
@@ -343,7 +412,7 @@ def create_dataset_card(
|
|
| 343 |
|
| 344 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 345 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 346 |
-
hw =
|
| 347 |
origin = (
|
| 348 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 349 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 325 |
raise RuntimeError(f"request failed after {retries + 1} attempts: {last_err}")
|
| 326 |
|
| 327 |
|
| 328 |
+
def jobs_flavor() -> str:
|
| 329 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 330 |
+
|
| 331 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 332 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 333 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 334 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 335 |
+
"""
|
| 336 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 337 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 338 |
+
return hardware # already a flavor name
|
| 339 |
+
try:
|
| 340 |
+
from huggingface_hub import HfApi
|
| 341 |
+
|
| 342 |
+
gpu_name, gpu_count = "", 0
|
| 343 |
+
try:
|
| 344 |
+
import torch
|
| 345 |
+
|
| 346 |
+
if torch.cuda.is_available():
|
| 347 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 348 |
+
gpu_count = torch.cuda.device_count()
|
| 349 |
+
except ImportError:
|
| 350 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 351 |
+
import subprocess
|
| 352 |
+
|
| 353 |
+
try:
|
| 354 |
+
listed = subprocess.run(
|
| 355 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 356 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 357 |
+
).stdout
|
| 358 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 359 |
+
if names:
|
| 360 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 361 |
+
except (OSError, subprocess.SubprocessError):
|
| 362 |
+
pass
|
| 363 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 364 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 365 |
+
|
| 366 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 367 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 368 |
+
candidates = []
|
| 369 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 370 |
+
accelerator = flavor.accelerator
|
| 371 |
+
if gpu_count == 0 and accelerator is None:
|
| 372 |
+
candidates.append(flavor)
|
| 373 |
+
elif (
|
| 374 |
+
gpu_count > 0
|
| 375 |
+
and accelerator is not None
|
| 376 |
+
and accelerator.model.upper() in gpu_words
|
| 377 |
+
and int(accelerator.quantity) == gpu_count
|
| 378 |
+
):
|
| 379 |
+
candidates.append(flavor)
|
| 380 |
+
if not candidates:
|
| 381 |
+
return ""
|
| 382 |
+
|
| 383 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 384 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 385 |
+
|
| 386 |
+
def distance(flavor) -> float:
|
| 387 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 388 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 389 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 390 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 391 |
+
|
| 392 |
+
return min(candidates, key=distance).name
|
| 393 |
+
except Exception:
|
| 394 |
+
return ""
|
| 395 |
+
|
| 396 |
+
|
| 397 |
def create_dataset_card(
|
| 398 |
source_dataset: str,
|
| 399 |
model: str,
|
|
|
|
| 412 |
|
| 413 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 414 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 415 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 416 |
origin = (
|
| 417 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 418 |
+ (f" (`{hw}`)" if hw else "")
|
ovis-ocr2.py
CHANGED
|
@@ -194,6 +194,75 @@ def postprocess_output(text: str, keep_image_tags: bool) -> str:
|
|
| 194 |
return clean_truncated_repeats(text)
|
| 195 |
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
def create_dataset_card(
|
| 198 |
source_dataset: str,
|
| 199 |
model: str,
|
|
@@ -212,7 +281,7 @@ def create_dataset_card(
|
|
| 212 |
|
| 213 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 214 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 215 |
-
hw =
|
| 216 |
origin = (
|
| 217 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 218 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 194 |
return clean_truncated_repeats(text)
|
| 195 |
|
| 196 |
|
| 197 |
+
def jobs_flavor() -> str:
|
| 198 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 199 |
+
|
| 200 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 201 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 202 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 203 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 204 |
+
"""
|
| 205 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 206 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 207 |
+
return hardware # already a flavor name
|
| 208 |
+
try:
|
| 209 |
+
from huggingface_hub import HfApi
|
| 210 |
+
|
| 211 |
+
gpu_name, gpu_count = "", 0
|
| 212 |
+
try:
|
| 213 |
+
import torch
|
| 214 |
+
|
| 215 |
+
if torch.cuda.is_available():
|
| 216 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 217 |
+
gpu_count = torch.cuda.device_count()
|
| 218 |
+
except ImportError:
|
| 219 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 220 |
+
import subprocess
|
| 221 |
+
|
| 222 |
+
try:
|
| 223 |
+
listed = subprocess.run(
|
| 224 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 225 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 226 |
+
).stdout
|
| 227 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 228 |
+
if names:
|
| 229 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 230 |
+
except (OSError, subprocess.SubprocessError):
|
| 231 |
+
pass
|
| 232 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 233 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 234 |
+
|
| 235 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 236 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 237 |
+
candidates = []
|
| 238 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 239 |
+
accelerator = flavor.accelerator
|
| 240 |
+
if gpu_count == 0 and accelerator is None:
|
| 241 |
+
candidates.append(flavor)
|
| 242 |
+
elif (
|
| 243 |
+
gpu_count > 0
|
| 244 |
+
and accelerator is not None
|
| 245 |
+
and accelerator.model.upper() in gpu_words
|
| 246 |
+
and int(accelerator.quantity) == gpu_count
|
| 247 |
+
):
|
| 248 |
+
candidates.append(flavor)
|
| 249 |
+
if not candidates:
|
| 250 |
+
return ""
|
| 251 |
+
|
| 252 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 253 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 254 |
+
|
| 255 |
+
def distance(flavor) -> float:
|
| 256 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 257 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 258 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 259 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 260 |
+
|
| 261 |
+
return min(candidates, key=distance).name
|
| 262 |
+
except Exception:
|
| 263 |
+
return ""
|
| 264 |
+
|
| 265 |
+
|
| 266 |
def create_dataset_card(
|
| 267 |
source_dataset: str,
|
| 268 |
model: str,
|
|
|
|
| 281 |
|
| 282 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 283 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 284 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 285 |
origin = (
|
| 286 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 287 |
+ (f" (`{hw}`)" if hw else "")
|
rolm-ocr.py
CHANGED
|
@@ -117,6 +117,75 @@ def make_ocr_message(
|
|
| 117 |
]
|
| 118 |
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
def create_dataset_card(
|
| 121 |
source_dataset: str,
|
| 122 |
model: str,
|
|
@@ -135,7 +204,7 @@ def create_dataset_card(
|
|
| 135 |
|
| 136 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 137 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 138 |
-
hw =
|
| 139 |
origin = (
|
| 140 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 141 |
+ (f" (`{hw}`)" if hw else "")
|
|
|
|
| 117 |
]
|
| 118 |
|
| 119 |
|
| 120 |
+
def jobs_flavor() -> str:
|
| 121 |
+
"""Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
|
| 122 |
+
|
| 123 |
+
HF Jobs sets ACCELERATOR to "cpu" or "gpu", not the flavor name, so the flavor is looked up
|
| 124 |
+
in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
|
| 125 |
+
MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
|
| 126 |
+
cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
|
| 127 |
+
"""
|
| 128 |
+
hardware = os.environ.get("ACCELERATOR") or ""
|
| 129 |
+
if "-" in hardware or any(character.isdigit() for character in hardware):
|
| 130 |
+
return hardware # already a flavor name
|
| 131 |
+
try:
|
| 132 |
+
from huggingface_hub import HfApi
|
| 133 |
+
|
| 134 |
+
gpu_name, gpu_count = "", 0
|
| 135 |
+
try:
|
| 136 |
+
import torch
|
| 137 |
+
|
| 138 |
+
if torch.cuda.is_available():
|
| 139 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 140 |
+
gpu_count = torch.cuda.device_count()
|
| 141 |
+
except ImportError:
|
| 142 |
+
# Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
|
| 143 |
+
import subprocess
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
listed = subprocess.run(
|
| 147 |
+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
|
| 148 |
+
capture_output=True, text=True, timeout=10, check=True,
|
| 149 |
+
).stdout
|
| 150 |
+
names = [line.strip() for line in listed.splitlines() if line.strip()]
|
| 151 |
+
if names:
|
| 152 |
+
gpu_name, gpu_count = names[0], len(names)
|
| 153 |
+
except (OSError, subprocess.SubprocessError):
|
| 154 |
+
pass
|
| 155 |
+
if gpu_count == 0 and hardware == "gpu":
|
| 156 |
+
return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
|
| 157 |
+
|
| 158 |
+
# Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
|
| 159 |
+
gpu_words = gpu_name.upper().replace("-", " ").split()
|
| 160 |
+
candidates = []
|
| 161 |
+
for flavor in HfApi(token=False).list_jobs_hardware():
|
| 162 |
+
accelerator = flavor.accelerator
|
| 163 |
+
if gpu_count == 0 and accelerator is None:
|
| 164 |
+
candidates.append(flavor)
|
| 165 |
+
elif (
|
| 166 |
+
gpu_count > 0
|
| 167 |
+
and accelerator is not None
|
| 168 |
+
and accelerator.model.upper() in gpu_words
|
| 169 |
+
and int(accelerator.quantity) == gpu_count
|
| 170 |
+
):
|
| 171 |
+
candidates.append(flavor)
|
| 172 |
+
if not candidates:
|
| 173 |
+
return ""
|
| 174 |
+
|
| 175 |
+
cores = float(os.environ.get("CPU_CORES") or 0)
|
| 176 |
+
memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
|
| 177 |
+
|
| 178 |
+
def distance(flavor) -> float:
|
| 179 |
+
# Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
|
| 180 |
+
listed_cores = float(flavor.cpu.split()[0])
|
| 181 |
+
listed_memory = float(flavor.ram.split()[0])
|
| 182 |
+
return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
|
| 183 |
+
|
| 184 |
+
return min(candidates, key=distance).name
|
| 185 |
+
except Exception:
|
| 186 |
+
return ""
|
| 187 |
+
|
| 188 |
+
|
| 189 |
def create_dataset_card(
|
| 190 |
source_dataset: str,
|
| 191 |
model: str,
|
|
|
|
| 204 |
|
| 205 |
# Canonical provenance stamp (see AGENTS.md): Jobs claim gated on JOB_ID, set by HF Jobs in-container.
|
| 206 |
on_jobs = os.environ.get("JOB_ID") is not None
|
| 207 |
+
hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
|
| 208 |
origin = (
|
| 209 |
"Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
|
| 210 |
+ (f" (`{hw}`)" if hw else "")
|