davanstrien HF Staff commited on
Commit
f8c866a
·
verified ·
1 Parent(s): 2e753d7

Sync from davanstrien/uv-scripts via hub-sync

Browse files
falcon-ocr-1.5.py CHANGED
@@ -152,78 +152,6 @@ def prepare_image(image: Union[Image.Image, Dict[str, Any], str]) -> Image.Image
152
  return pil_img.convert("RGB")
153
 
154
 
155
- def jobs_flavor() -> str:
156
- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
157
-
158
- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
159
- "cpu" or "gpu", not the flavor name), the flavor is looked up
160
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
161
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
162
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
163
- """
164
- if os.environ.get("HF_JOB_FLAVOR"):
165
- return os.environ["HF_JOB_FLAVOR"]
166
- hardware = os.environ.get("ACCELERATOR") or ""
167
- if "-" in hardware or any(character.isdigit() for character in hardware):
168
- return hardware # already a flavor name
169
- try:
170
- from huggingface_hub import HfApi
171
-
172
- gpu_name, gpu_count = "", 0
173
- try:
174
- import torch
175
-
176
- if torch.cuda.is_available():
177
- gpu_name = torch.cuda.get_device_name(0)
178
- gpu_count = torch.cuda.device_count()
179
- except ImportError:
180
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
181
- import subprocess
182
-
183
- try:
184
- listed = subprocess.run(
185
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
186
- capture_output=True, text=True, timeout=10, check=True,
187
- ).stdout
188
- names = [line.strip() for line in listed.splitlines() if line.strip()]
189
- if names:
190
- gpu_name, gpu_count = names[0], len(names)
191
- except (OSError, subprocess.SubprocessError):
192
- pass
193
- if gpu_count == 0 and hardware == "gpu":
194
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
195
-
196
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
197
- gpu_words = gpu_name.upper().replace("-", " ").split()
198
- candidates = []
199
- for flavor in HfApi(token=False).list_jobs_hardware():
200
- accelerator = flavor.accelerator
201
- if gpu_count == 0 and accelerator is None:
202
- candidates.append(flavor)
203
- elif (
204
- gpu_count > 0
205
- and accelerator is not None
206
- and accelerator.model.upper() in gpu_words
207
- and int(accelerator.quantity) == gpu_count
208
- ):
209
- candidates.append(flavor)
210
- if not candidates:
211
- return ""
212
-
213
- cores = float(os.environ.get("CPU_CORES") or 0)
214
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
215
-
216
- def distance(flavor) -> float:
217
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
218
- listed_cores = float(flavor.cpu.split()[0])
219
- listed_memory = float(flavor.ram.split()[0])
220
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
221
-
222
- return min(candidates, key=distance).name
223
- except Exception:
224
- return ""
225
-
226
-
227
  def create_dataset_card(
228
  source_dataset: str,
229
  task_mode: str,
@@ -238,7 +166,7 @@ def create_dataset_card(
238
  commit_note = f" (resolved to `{model_commit}`)"
239
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
240
  on_jobs = os.environ.get("HF_JOB_ID") is not None
241
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
242
  origin = (
243
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
244
  + (f" (`{hw}`)" if hw else "")
 
152
  return pil_img.convert("RGB")
153
 
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  def create_dataset_card(
156
  source_dataset: str,
157
  task_mode: str,
 
166
  commit_note = f" (resolved to `{model_commit}`)"
167
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
168
  on_jobs = os.environ.get("HF_JOB_ID") is not None
169
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
170
  origin = (
171
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
172
  + (f" (`{hw}`)" if hw else "")
falcon-ocr.py CHANGED
@@ -157,78 +157,6 @@ def prepare_image(image: Union[Image.Image, Dict[str, Any], str]) -> Image.Image
157
  return pil_img.convert("RGB")
158
 
159
 
160
- def jobs_flavor() -> str:
161
- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
162
-
163
- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
164
- "cpu" or "gpu", not the flavor name), the flavor is looked up
165
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
166
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
167
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
168
- """
169
- if os.environ.get("HF_JOB_FLAVOR"):
170
- return os.environ["HF_JOB_FLAVOR"]
171
- hardware = os.environ.get("ACCELERATOR") or ""
172
- if "-" in hardware or any(character.isdigit() for character in hardware):
173
- return hardware # already a flavor name
174
- try:
175
- from huggingface_hub import HfApi
176
-
177
- gpu_name, gpu_count = "", 0
178
- try:
179
- import torch
180
-
181
- if torch.cuda.is_available():
182
- gpu_name = torch.cuda.get_device_name(0)
183
- gpu_count = torch.cuda.device_count()
184
- except ImportError:
185
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
186
- import subprocess
187
-
188
- try:
189
- listed = subprocess.run(
190
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
191
- capture_output=True, text=True, timeout=10, check=True,
192
- ).stdout
193
- names = [line.strip() for line in listed.splitlines() if line.strip()]
194
- if names:
195
- gpu_name, gpu_count = names[0], len(names)
196
- except (OSError, subprocess.SubprocessError):
197
- pass
198
- if gpu_count == 0 and hardware == "gpu":
199
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
200
-
201
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
202
- gpu_words = gpu_name.upper().replace("-", " ").split()
203
- candidates = []
204
- for flavor in HfApi(token=False).list_jobs_hardware():
205
- accelerator = flavor.accelerator
206
- if gpu_count == 0 and accelerator is None:
207
- candidates.append(flavor)
208
- elif (
209
- gpu_count > 0
210
- and accelerator is not None
211
- and accelerator.model.upper() in gpu_words
212
- and int(accelerator.quantity) == gpu_count
213
- ):
214
- candidates.append(flavor)
215
- if not candidates:
216
- return ""
217
-
218
- cores = float(os.environ.get("CPU_CORES") or 0)
219
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
220
-
221
- def distance(flavor) -> float:
222
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
223
- listed_cores = float(flavor.cpu.split()[0])
224
- listed_memory = float(flavor.ram.split()[0])
225
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
226
-
227
- return min(candidates, key=distance).name
228
- except Exception:
229
- return ""
230
-
231
-
232
  def create_dataset_card(
233
  source_dataset: str,
234
  task_mode: str,
@@ -243,7 +171,7 @@ def create_dataset_card(
243
  commit_note = f" (resolved to `{model_commit}`)"
244
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
245
  on_jobs = os.environ.get("HF_JOB_ID") is not None
246
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
247
  origin = (
248
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
249
  + (f" (`{hw}`)" if hw else "")
 
157
  return pil_img.convert("RGB")
158
 
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def create_dataset_card(
161
  source_dataset: str,
162
  task_mode: str,
 
171
  commit_note = f" (resolved to `{model_commit}`)"
172
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
173
  on_jobs = os.environ.get("HF_JOB_ID") is not None
174
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
175
  origin = (
176
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
177
  + (f" (`{hw}`)" if hw else "")
glm-ocr.py CHANGED
@@ -176,78 +176,6 @@ def make_ocr_message(
176
  ]
177
 
178
 
179
- def jobs_flavor() -> str:
180
- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
181
-
182
- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
183
- "cpu" or "gpu", not the flavor name), the flavor is looked up
184
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
185
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
186
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
187
- """
188
- if os.environ.get("HF_JOB_FLAVOR"):
189
- return os.environ["HF_JOB_FLAVOR"]
190
- hardware = os.environ.get("ACCELERATOR") or ""
191
- if "-" in hardware or any(character.isdigit() for character in hardware):
192
- return hardware # already a flavor name
193
- try:
194
- from huggingface_hub import HfApi
195
-
196
- gpu_name, gpu_count = "", 0
197
- try:
198
- import torch
199
-
200
- if torch.cuda.is_available():
201
- gpu_name = torch.cuda.get_device_name(0)
202
- gpu_count = torch.cuda.device_count()
203
- except ImportError:
204
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
205
- import subprocess
206
-
207
- try:
208
- listed = subprocess.run(
209
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
210
- capture_output=True, text=True, timeout=10, check=True,
211
- ).stdout
212
- names = [line.strip() for line in listed.splitlines() if line.strip()]
213
- if names:
214
- gpu_name, gpu_count = names[0], len(names)
215
- except (OSError, subprocess.SubprocessError):
216
- pass
217
- if gpu_count == 0 and hardware == "gpu":
218
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
219
-
220
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
221
- gpu_words = gpu_name.upper().replace("-", " ").split()
222
- candidates = []
223
- for flavor in HfApi(token=False).list_jobs_hardware():
224
- accelerator = flavor.accelerator
225
- if gpu_count == 0 and accelerator is None:
226
- candidates.append(flavor)
227
- elif (
228
- gpu_count > 0
229
- and accelerator is not None
230
- and accelerator.model.upper() in gpu_words
231
- and int(accelerator.quantity) == gpu_count
232
- ):
233
- candidates.append(flavor)
234
- if not candidates:
235
- return ""
236
-
237
- cores = float(os.environ.get("CPU_CORES") or 0)
238
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
239
-
240
- def distance(flavor) -> float:
241
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
242
- listed_cores = float(flavor.cpu.split()[0])
243
- listed_memory = float(flavor.ram.split()[0])
244
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
245
-
246
- return min(candidates, key=distance).name
247
- except Exception:
248
- return ""
249
-
250
-
251
  def create_dataset_card(
252
  source_dataset: str,
253
  model: str,
@@ -273,7 +201,7 @@ def create_dataset_card(
273
 
274
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
275
  on_jobs = os.environ.get("HF_JOB_ID") is not None
276
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
277
  origin = (
278
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
279
  + (f" (`{hw}`)" if hw else "")
 
176
  ]
177
 
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  def create_dataset_card(
180
  source_dataset: str,
181
  model: str,
 
201
 
202
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
203
  on_jobs = os.environ.get("HF_JOB_ID") is not None
204
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
205
  origin = (
206
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
207
  + (f" (`{hw}`)" if hw else "")
jina-ocr-v1.py CHANGED
@@ -142,78 +142,6 @@ def load_model_glue(revision: str | None):
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
149
- "cpu" or "gpu", not the flavor name), the flavor is looked up
150
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
151
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
152
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
153
- """
154
- if os.environ.get("HF_JOB_FLAVOR"):
155
- return os.environ["HF_JOB_FLAVOR"]
156
- hardware = os.environ.get("ACCELERATOR") or ""
157
- if "-" in hardware or any(character.isdigit() for character in hardware):
158
- return hardware # already a flavor name
159
- try:
160
- from huggingface_hub import HfApi
161
-
162
- gpu_name, gpu_count = "", 0
163
- try:
164
- import torch
165
-
166
- if torch.cuda.is_available():
167
- gpu_name = torch.cuda.get_device_name(0)
168
- gpu_count = torch.cuda.device_count()
169
- except ImportError:
170
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
171
- import subprocess
172
-
173
- try:
174
- listed = subprocess.run(
175
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
176
- capture_output=True, text=True, timeout=10, check=True,
177
- ).stdout
178
- names = [line.strip() for line in listed.splitlines() if line.strip()]
179
- if names:
180
- gpu_name, gpu_count = names[0], len(names)
181
- except (OSError, subprocess.SubprocessError):
182
- pass
183
- if gpu_count == 0 and hardware == "gpu":
184
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
185
-
186
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
187
- gpu_words = gpu_name.upper().replace("-", " ").split()
188
- candidates = []
189
- for flavor in HfApi(token=False).list_jobs_hardware():
190
- accelerator = flavor.accelerator
191
- if gpu_count == 0 and accelerator is None:
192
- candidates.append(flavor)
193
- elif (
194
- gpu_count > 0
195
- and accelerator is not None
196
- and accelerator.model.upper() in gpu_words
197
- and int(accelerator.quantity) == gpu_count
198
- ):
199
- candidates.append(flavor)
200
- if not candidates:
201
- return ""
202
-
203
- cores = float(os.environ.get("CPU_CORES") or 0)
204
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
205
-
206
- def distance(flavor) -> float:
207
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
208
- listed_cores = float(flavor.cpu.split()[0])
209
- listed_memory = float(flavor.ram.split()[0])
210
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
211
-
212
- return min(candidates, key=distance).name
213
- except Exception:
214
- return ""
215
-
216
-
217
  def create_dataset_card(
218
  source_dataset: str,
219
  num_samples: int,
@@ -229,7 +157,7 @@ def create_dataset_card(
229
  image_count_per_sec: float,
230
  ) -> str:
231
  on_jobs = os.environ.get("HF_JOB_ID") is not None
232
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
233
  origin = (
234
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
235
  + (f" (`{hw}`)" if hw else "")
 
142
  return snapshot, deepseek_ocr_mtp
143
 
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  def create_dataset_card(
146
  source_dataset: str,
147
  num_samples: int,
 
157
  image_count_per_sec: float,
158
  ) -> str:
159
  on_jobs = os.environ.get("HF_JOB_ID") is not None
160
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
161
  origin = (
162
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
163
  + (f" (`{hw}`)" if hw else "")
lighton-ocr2-server.py CHANGED
@@ -242,78 +242,6 @@ def ocr_one(
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
249
- "cpu" or "gpu", not the flavor name), the flavor is looked up
250
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
251
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
252
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
253
- """
254
- if os.environ.get("HF_JOB_FLAVOR"):
255
- return os.environ["HF_JOB_FLAVOR"]
256
- hardware = os.environ.get("ACCELERATOR") or ""
257
- if "-" in hardware or any(character.isdigit() for character in hardware):
258
- return hardware # already a flavor name
259
- try:
260
- from huggingface_hub import HfApi
261
-
262
- gpu_name, gpu_count = "", 0
263
- try:
264
- import torch
265
-
266
- if torch.cuda.is_available():
267
- gpu_name = torch.cuda.get_device_name(0)
268
- gpu_count = torch.cuda.device_count()
269
- except ImportError:
270
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
271
- import subprocess
272
-
273
- try:
274
- listed = subprocess.run(
275
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
276
- capture_output=True, text=True, timeout=10, check=True,
277
- ).stdout
278
- names = [line.strip() for line in listed.splitlines() if line.strip()]
279
- if names:
280
- gpu_name, gpu_count = names[0], len(names)
281
- except (OSError, subprocess.SubprocessError):
282
- pass
283
- if gpu_count == 0 and hardware == "gpu":
284
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
285
-
286
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
287
- gpu_words = gpu_name.upper().replace("-", " ").split()
288
- candidates = []
289
- for flavor in HfApi(token=False).list_jobs_hardware():
290
- accelerator = flavor.accelerator
291
- if gpu_count == 0 and accelerator is None:
292
- candidates.append(flavor)
293
- elif (
294
- gpu_count > 0
295
- and accelerator is not None
296
- and accelerator.model.upper() in gpu_words
297
- and int(accelerator.quantity) == gpu_count
298
- ):
299
- candidates.append(flavor)
300
- if not candidates:
301
- return ""
302
-
303
- cores = float(os.environ.get("CPU_CORES") or 0)
304
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
305
-
306
- def distance(flavor) -> float:
307
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
308
- listed_cores = float(flavor.cpu.split()[0])
309
- listed_memory = float(flavor.ram.split()[0])
310
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
311
-
312
- return min(candidates, key=distance).name
313
- except Exception:
314
- return ""
315
-
316
-
317
  def create_dataset_card(
318
  source_dataset: str,
319
  model: str,
@@ -333,7 +261,7 @@ def create_dataset_card(
333
 
334
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
335
  on_jobs = os.environ.get("HF_JOB_ID") is not None
336
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
337
  origin = (
338
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
339
  + (f" (`{hw}`)" if hw else "")
 
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
 
262
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
263
  on_jobs = os.environ.get("HF_JOB_ID") is not None
264
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
265
  origin = (
266
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
267
  + (f" (`{hw}`)" if hw else "")
lighton-ocr3.py CHANGED
@@ -195,78 +195,6 @@ def postprocess_output(text: str, mode: str, fix_dollars: bool):
195
  return markdown, json.dumps([b.to_dict() for b in blocks], ensure_ascii=False)
196
 
197
 
198
- def jobs_flavor() -> str:
199
- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
200
-
201
- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
202
- "cpu" or "gpu", not the flavor name), the flavor is looked up
203
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
204
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
205
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
206
- """
207
- if os.environ.get("HF_JOB_FLAVOR"):
208
- return os.environ["HF_JOB_FLAVOR"]
209
- hardware = os.environ.get("ACCELERATOR") or ""
210
- if "-" in hardware or any(character.isdigit() for character in hardware):
211
- return hardware # already a flavor name
212
- try:
213
- from huggingface_hub import HfApi
214
-
215
- gpu_name, gpu_count = "", 0
216
- try:
217
- import torch
218
-
219
- if torch.cuda.is_available():
220
- gpu_name = torch.cuda.get_device_name(0)
221
- gpu_count = torch.cuda.device_count()
222
- except ImportError:
223
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
224
- import subprocess
225
-
226
- try:
227
- listed = subprocess.run(
228
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
229
- capture_output=True, text=True, timeout=10, check=True,
230
- ).stdout
231
- names = [line.strip() for line in listed.splitlines() if line.strip()]
232
- if names:
233
- gpu_name, gpu_count = names[0], len(names)
234
- except (OSError, subprocess.SubprocessError):
235
- pass
236
- if gpu_count == 0 and hardware == "gpu":
237
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
238
-
239
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
240
- gpu_words = gpu_name.upper().replace("-", " ").split()
241
- candidates = []
242
- for flavor in HfApi(token=False).list_jobs_hardware():
243
- accelerator = flavor.accelerator
244
- if gpu_count == 0 and accelerator is None:
245
- candidates.append(flavor)
246
- elif (
247
- gpu_count > 0
248
- and accelerator is not None
249
- and accelerator.model.upper() in gpu_words
250
- and int(accelerator.quantity) == gpu_count
251
- ):
252
- candidates.append(flavor)
253
- if not candidates:
254
- return ""
255
-
256
- cores = float(os.environ.get("CPU_CORES") or 0)
257
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
258
-
259
- def distance(flavor) -> float:
260
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
261
- listed_cores = float(flavor.cpu.split()[0])
262
- listed_memory = float(flavor.ram.split()[0])
263
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
264
-
265
- return min(candidates, key=distance).name
266
- except Exception:
267
- return ""
268
-
269
-
270
  def create_dataset_card(
271
  source_dataset: str,
272
  model: str,
@@ -290,7 +218,7 @@ def create_dataset_card(
290
 
291
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
292
  on_jobs = os.environ.get("HF_JOB_ID") is not None
293
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" when it cannot be told
294
  origin = (
295
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
296
  + (f" (`{hw}`)" if hw else "")
 
195
  return markdown, json.dumps([b.to_dict() for b in blocks], ensure_ascii=False)
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  def create_dataset_card(
199
  source_dataset: str,
200
  model: str,
 
218
 
219
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
220
  on_jobs = os.environ.get("HF_JOB_ID") is not None
221
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
222
  origin = (
223
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
224
  + (f" (`{hw}`)" if hw else "")
minicpm-ocr.py CHANGED
@@ -382,82 +382,10 @@ def run_files(args):
382
  # --- Dataset mode ----------------------------------------------------------------------------
383
 
384
 
385
- def jobs_flavor() -> str:
386
- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
387
-
388
- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
389
- "cpu" or "gpu", not the flavor name), the flavor is looked up
390
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
391
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
392
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
393
- """
394
- if os.environ.get("HF_JOB_FLAVOR"):
395
- return os.environ["HF_JOB_FLAVOR"]
396
- hardware = os.environ.get("ACCELERATOR") or ""
397
- if "-" in hardware or any(character.isdigit() for character in hardware):
398
- return hardware # already a flavor name
399
- try:
400
- from huggingface_hub import HfApi
401
-
402
- gpu_name, gpu_count = "", 0
403
- try:
404
- import torch
405
-
406
- if torch.cuda.is_available():
407
- gpu_name = torch.cuda.get_device_name(0)
408
- gpu_count = torch.cuda.device_count()
409
- except ImportError:
410
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
411
- import subprocess
412
-
413
- try:
414
- listed = subprocess.run(
415
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
416
- capture_output=True, text=True, timeout=10, check=True,
417
- ).stdout
418
- names = [line.strip() for line in listed.splitlines() if line.strip()]
419
- if names:
420
- gpu_name, gpu_count = names[0], len(names)
421
- except (OSError, subprocess.SubprocessError):
422
- pass
423
- if gpu_count == 0 and hardware == "gpu":
424
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
425
-
426
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
427
- gpu_words = gpu_name.upper().replace("-", " ").split()
428
- candidates = []
429
- for flavor in HfApi(token=False).list_jobs_hardware():
430
- accelerator = flavor.accelerator
431
- if gpu_count == 0 and accelerator is None:
432
- candidates.append(flavor)
433
- elif (
434
- gpu_count > 0
435
- and accelerator is not None
436
- and accelerator.model.upper() in gpu_words
437
- and int(accelerator.quantity) == gpu_count
438
- ):
439
- candidates.append(flavor)
440
- if not candidates:
441
- return ""
442
-
443
- cores = float(os.environ.get("CPU_CORES") or 0)
444
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
445
-
446
- def distance(flavor) -> float:
447
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
448
- listed_cores = float(flavor.cpu.split()[0])
449
- listed_memory = float(flavor.ram.split()[0])
450
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
451
-
452
- return min(candidates, key=distance).name
453
- except Exception:
454
- return ""
455
-
456
-
457
  def create_dataset_card(args, num_samples: int, counts: dict, processing_time: str) -> str:
458
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
459
  on_jobs = os.environ.get("HF_JOB_ID") is not None
460
- hw = jobs_flavor()
461
  origin = (
462
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
463
  + (f" (`{hw}`)" if hw else "")
 
382
  # --- Dataset mode ----------------------------------------------------------------------------
383
 
384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  def create_dataset_card(args, num_samples: int, counts: dict, processing_time: str) -> str:
386
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
387
  on_jobs = os.environ.get("HF_JOB_ID") is not None
388
+ hw = os.environ.get("HF_JOB_FLAVOR", "")
389
  origin = (
390
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
391
  + (f" (`{hw}`)" if hw else "")
nanonets-ocr.py CHANGED
@@ -115,78 +115,6 @@ def make_ocr_message(
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
122
- "cpu" or "gpu", not the flavor name), the flavor is looked up
123
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
124
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
125
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
126
- """
127
- if os.environ.get("HF_JOB_FLAVOR"):
128
- return os.environ["HF_JOB_FLAVOR"]
129
- hardware = os.environ.get("ACCELERATOR") or ""
130
- if "-" in hardware or any(character.isdigit() for character in hardware):
131
- return hardware # already a flavor name
132
- try:
133
- from huggingface_hub import HfApi
134
-
135
- gpu_name, gpu_count = "", 0
136
- try:
137
- import torch
138
-
139
- if torch.cuda.is_available():
140
- gpu_name = torch.cuda.get_device_name(0)
141
- gpu_count = torch.cuda.device_count()
142
- except ImportError:
143
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
144
- import subprocess
145
-
146
- try:
147
- listed = subprocess.run(
148
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
149
- capture_output=True, text=True, timeout=10, check=True,
150
- ).stdout
151
- names = [line.strip() for line in listed.splitlines() if line.strip()]
152
- if names:
153
- gpu_name, gpu_count = names[0], len(names)
154
- except (OSError, subprocess.SubprocessError):
155
- pass
156
- if gpu_count == 0 and hardware == "gpu":
157
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
158
-
159
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
160
- gpu_words = gpu_name.upper().replace("-", " ").split()
161
- candidates = []
162
- for flavor in HfApi(token=False).list_jobs_hardware():
163
- accelerator = flavor.accelerator
164
- if gpu_count == 0 and accelerator is None:
165
- candidates.append(flavor)
166
- elif (
167
- gpu_count > 0
168
- and accelerator is not None
169
- and accelerator.model.upper() in gpu_words
170
- and int(accelerator.quantity) == gpu_count
171
- ):
172
- candidates.append(flavor)
173
- if not candidates:
174
- return ""
175
-
176
- cores = float(os.environ.get("CPU_CORES") or 0)
177
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
178
-
179
- def distance(flavor) -> float:
180
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
181
- listed_cores = float(flavor.cpu.split()[0])
182
- listed_memory = float(flavor.ram.split()[0])
183
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
184
-
185
- return min(candidates, key=distance).name
186
- except Exception:
187
- return ""
188
-
189
-
190
  def create_dataset_card(
191
  source_dataset: str,
192
  model: str,
@@ -204,7 +132,7 @@ def create_dataset_card(
204
 
205
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
206
  on_jobs = os.environ.get("HF_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 "")
 
115
  ]
116
 
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  def create_dataset_card(
119
  source_dataset: str,
120
  model: str,
 
132
 
133
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
134
  on_jobs = os.environ.get("HF_JOB_ID") is not None
135
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
136
  origin = (
137
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
138
  + (f" (`{hw}`)" if hw else "")
ocria-nano.py CHANGED
@@ -194,81 +194,6 @@ def run_ocr(parser, dataset, image_column: str, num_workers: int) -> list[str]:
194
  return results
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,
226
- text=True,
227
- timeout=10,
228
- check=True,
229
- ).stdout
230
- names = [line.strip() for line in listed.splitlines() if line.strip()]
231
- if names:
232
- gpu_name, gpu_count = names[0], len(names)
233
- except (OSError, subprocess.SubprocessError):
234
- pass
235
- if gpu_count == 0 and hardware == "gpu":
236
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
237
-
238
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
239
- gpu_words = gpu_name.upper().replace("-", " ").split()
240
- candidates = []
241
- for flavor in HfApi(token=False).list_jobs_hardware():
242
- accelerator = flavor.accelerator
243
- if gpu_count == 0 and accelerator is None:
244
- candidates.append(flavor)
245
- elif (
246
- gpu_count > 0
247
- and accelerator is not None
248
- and accelerator.model.upper() in gpu_words
249
- and int(accelerator.quantity) == gpu_count
250
- ):
251
- candidates.append(flavor)
252
- if not candidates:
253
- return ""
254
-
255
- cores = float(os.environ.get("CPU_CORES") or 0)
256
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
257
-
258
- def distance(flavor) -> float:
259
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
260
- listed_cores = float(flavor.cpu.split()[0])
261
- listed_memory = float(flavor.ram.split()[0])
262
- return (
263
- abs(listed_cores - cores) / listed_cores
264
- + abs(listed_memory - memory_gb) / listed_memory
265
- )
266
-
267
- return min(candidates, key=distance).name
268
- except Exception:
269
- return ""
270
-
271
-
272
  def create_dataset_card(
273
  source_dataset: str,
274
  num_samples: int,
@@ -281,7 +206,7 @@ def create_dataset_card(
281
  ) -> str:
282
  """Create a dataset card documenting the OCRia-nano-1 run."""
283
  on_jobs = os.environ.get("HF_JOB_ID") is not None # set by HF Jobs in-container
284
- hw = jobs_flavor() # flavor name, e.g. "cpu-upgrade"; "" when it cannot be told
285
  origin = (
286
  (
287
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
 
194
  return results
195
 
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  def create_dataset_card(
198
  source_dataset: str,
199
  num_samples: int,
 
206
  ) -> str:
207
  """Create a dataset card documenting the OCRia-nano-1 run."""
208
  on_jobs = os.environ.get("HF_JOB_ID") is not None # set by HF Jobs in-container
209
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
210
  origin = (
211
  (
212
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
ovis-ocr2-server.py CHANGED
@@ -325,78 +325,6 @@ def ocr_one(
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
332
- "cpu" or "gpu", not the flavor name), the flavor is looked up
333
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
334
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
335
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
336
- """
337
- if os.environ.get("HF_JOB_FLAVOR"):
338
- return os.environ["HF_JOB_FLAVOR"]
339
- hardware = os.environ.get("ACCELERATOR") or ""
340
- if "-" in hardware or any(character.isdigit() for character in hardware):
341
- return hardware # already a flavor name
342
- try:
343
- from huggingface_hub import HfApi
344
-
345
- gpu_name, gpu_count = "", 0
346
- try:
347
- import torch
348
-
349
- if torch.cuda.is_available():
350
- gpu_name = torch.cuda.get_device_name(0)
351
- gpu_count = torch.cuda.device_count()
352
- except ImportError:
353
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
354
- import subprocess
355
-
356
- try:
357
- listed = subprocess.run(
358
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
359
- capture_output=True, text=True, timeout=10, check=True,
360
- ).stdout
361
- names = [line.strip() for line in listed.splitlines() if line.strip()]
362
- if names:
363
- gpu_name, gpu_count = names[0], len(names)
364
- except (OSError, subprocess.SubprocessError):
365
- pass
366
- if gpu_count == 0 and hardware == "gpu":
367
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
368
-
369
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
370
- gpu_words = gpu_name.upper().replace("-", " ").split()
371
- candidates = []
372
- for flavor in HfApi(token=False).list_jobs_hardware():
373
- accelerator = flavor.accelerator
374
- if gpu_count == 0 and accelerator is None:
375
- candidates.append(flavor)
376
- elif (
377
- gpu_count > 0
378
- and accelerator is not None
379
- and accelerator.model.upper() in gpu_words
380
- and int(accelerator.quantity) == gpu_count
381
- ):
382
- candidates.append(flavor)
383
- if not candidates:
384
- return ""
385
-
386
- cores = float(os.environ.get("CPU_CORES") or 0)
387
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
388
-
389
- def distance(flavor) -> float:
390
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
391
- listed_cores = float(flavor.cpu.split()[0])
392
- listed_memory = float(flavor.ram.split()[0])
393
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
394
-
395
- return min(candidates, key=distance).name
396
- except Exception:
397
- return ""
398
-
399
-
400
  def create_dataset_card(
401
  source_dataset: str,
402
  model: str,
@@ -415,7 +343,7 @@ def create_dataset_card(
415
 
416
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
417
  on_jobs = os.environ.get("HF_JOB_ID") is not None
418
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
419
  origin = (
420
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
421
  + (f" (`{hw}`)" if hw else "")
 
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
 
344
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
345
  on_jobs = os.environ.get("HF_JOB_ID") is not None
346
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
347
  origin = (
348
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
349
  + (f" (`{hw}`)" if hw else "")
ovis-ocr2.py CHANGED
@@ -194,78 +194,6 @@ def postprocess_output(text: str, keep_image_tags: bool) -> str:
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
201
- "cpu" or "gpu", not the flavor name), the flavor is looked up
202
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
203
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
204
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
205
- """
206
- if os.environ.get("HF_JOB_FLAVOR"):
207
- return os.environ["HF_JOB_FLAVOR"]
208
- hardware = os.environ.get("ACCELERATOR") or ""
209
- if "-" in hardware or any(character.isdigit() for character in hardware):
210
- return hardware # already a flavor name
211
- try:
212
- from huggingface_hub import HfApi
213
-
214
- gpu_name, gpu_count = "", 0
215
- try:
216
- import torch
217
-
218
- if torch.cuda.is_available():
219
- gpu_name = torch.cuda.get_device_name(0)
220
- gpu_count = torch.cuda.device_count()
221
- except ImportError:
222
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
223
- import subprocess
224
-
225
- try:
226
- listed = subprocess.run(
227
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
228
- capture_output=True, text=True, timeout=10, check=True,
229
- ).stdout
230
- names = [line.strip() for line in listed.splitlines() if line.strip()]
231
- if names:
232
- gpu_name, gpu_count = names[0], len(names)
233
- except (OSError, subprocess.SubprocessError):
234
- pass
235
- if gpu_count == 0 and hardware == "gpu":
236
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
237
-
238
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
239
- gpu_words = gpu_name.upper().replace("-", " ").split()
240
- candidates = []
241
- for flavor in HfApi(token=False).list_jobs_hardware():
242
- accelerator = flavor.accelerator
243
- if gpu_count == 0 and accelerator is None:
244
- candidates.append(flavor)
245
- elif (
246
- gpu_count > 0
247
- and accelerator is not None
248
- and accelerator.model.upper() in gpu_words
249
- and int(accelerator.quantity) == gpu_count
250
- ):
251
- candidates.append(flavor)
252
- if not candidates:
253
- return ""
254
-
255
- cores = float(os.environ.get("CPU_CORES") or 0)
256
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
257
-
258
- def distance(flavor) -> float:
259
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
260
- listed_cores = float(flavor.cpu.split()[0])
261
- listed_memory = float(flavor.ram.split()[0])
262
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
263
-
264
- return min(candidates, key=distance).name
265
- except Exception:
266
- return ""
267
-
268
-
269
  def create_dataset_card(
270
  source_dataset: str,
271
  model: str,
@@ -284,7 +212,7 @@ def create_dataset_card(
284
 
285
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
286
  on_jobs = os.environ.get("HF_JOB_ID") is not None
287
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
288
  origin = (
289
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
290
  + (f" (`{hw}`)" if hw else "")
 
194
  return clean_truncated_repeats(text)
195
 
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  def create_dataset_card(
198
  source_dataset: str,
199
  model: str,
 
212
 
213
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
214
  on_jobs = os.environ.get("HF_JOB_ID") is not None
215
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
216
  origin = (
217
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
218
  + (f" (`{hw}`)" if hw else "")
rolm-ocr.py CHANGED
@@ -117,78 +117,6 @@ def make_ocr_message(
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 HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
124
- "cpu" or "gpu", not the flavor name), the flavor is looked up
125
- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
126
- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
127
- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
128
- """
129
- if os.environ.get("HF_JOB_FLAVOR"):
130
- return os.environ["HF_JOB_FLAVOR"]
131
- hardware = os.environ.get("ACCELERATOR") or ""
132
- if "-" in hardware or any(character.isdigit() for character in hardware):
133
- return hardware # already a flavor name
134
- try:
135
- from huggingface_hub import HfApi
136
-
137
- gpu_name, gpu_count = "", 0
138
- try:
139
- import torch
140
-
141
- if torch.cuda.is_available():
142
- gpu_name = torch.cuda.get_device_name(0)
143
- gpu_count = torch.cuda.device_count()
144
- except ImportError:
145
- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
146
- import subprocess
147
-
148
- try:
149
- listed = subprocess.run(
150
- ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
151
- capture_output=True, text=True, timeout=10, check=True,
152
- ).stdout
153
- names = [line.strip() for line in listed.splitlines() if line.strip()]
154
- if names:
155
- gpu_name, gpu_count = names[0], len(names)
156
- except (OSError, subprocess.SubprocessError):
157
- pass
158
- if gpu_count == 0 and hardware == "gpu":
159
- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
160
-
161
- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
162
- gpu_words = gpu_name.upper().replace("-", " ").split()
163
- candidates = []
164
- for flavor in HfApi(token=False).list_jobs_hardware():
165
- accelerator = flavor.accelerator
166
- if gpu_count == 0 and accelerator is None:
167
- candidates.append(flavor)
168
- elif (
169
- gpu_count > 0
170
- and accelerator is not None
171
- and accelerator.model.upper() in gpu_words
172
- and int(accelerator.quantity) == gpu_count
173
- ):
174
- candidates.append(flavor)
175
- if not candidates:
176
- return ""
177
-
178
- cores = float(os.environ.get("CPU_CORES") or 0)
179
- memory_gb = float((os.environ.get("MEMORY") or "0").upper().rstrip("GIB ") or 0)
180
-
181
- def distance(flavor) -> float:
182
- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
183
- listed_cores = float(flavor.cpu.split()[0])
184
- listed_memory = float(flavor.ram.split()[0])
185
- return abs(listed_cores - cores) / listed_cores + abs(listed_memory - memory_gb) / listed_memory
186
-
187
- return min(candidates, key=distance).name
188
- except Exception:
189
- return ""
190
-
191
-
192
  def create_dataset_card(
193
  source_dataset: str,
194
  model: str,
@@ -207,7 +135,7 @@ def create_dataset_card(
207
 
208
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
209
  on_jobs = os.environ.get("HF_JOB_ID") is not None
210
- hw = jobs_flavor() # flavor name, e.g. "a10g-small"; "" on CPU
211
  origin = (
212
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
213
  + (f" (`{hw}`)" if hw else "")
 
117
  ]
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  def create_dataset_card(
121
  source_dataset: str,
122
  model: str,
 
135
 
136
  # Canonical provenance stamp (see AGENTS.md): Jobs claim gated on HF_JOB_ID, set by HF Jobs in-container.
137
  on_jobs = os.environ.get("HF_JOB_ID") is not None
138
+ hw = os.environ.get("HF_JOB_FLAVOR", "") # set by HF Jobs, e.g. "a10g-small"; "" outside Jobs
139
  origin = (
140
  "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
141
  + (f" (`{hw}`)" if hw else "")