@@ -748,81 +748,9 @@ def evaluate(model_path: str, eval_sets: dict, tasks: list, batch_size: int, exp
748748 return metrics_by_split
749749
750750
751- def jobs_flavor () -> str :
752- """Return the HF Jobs hardware flavor this run is on, or "" when it cannot be told.
753-
754- HF Jobs sets HF_JOB_FLAVOR to the flavor name. Without it (ACCELERATOR holds only
755- "cpu" or "gpu", not the flavor name), the flavor is looked up
756- in the public Jobs hardware list: first by GPU model and count, then by the CPU_CORES and
757- MEMORY values that Jobs sets in the container (to tell a10g-small from a10g-large, or
758- cpu-basic from cpu-upgrade). Any failure (no network, older huggingface_hub) returns "".
759- """
760- if os .environ .get ("HF_JOB_FLAVOR" ):
761- return os .environ ["HF_JOB_FLAVOR" ]
762- hardware = os .environ .get ("ACCELERATOR" ) or ""
763- if "-" in hardware or any (character .isdigit () for character in hardware ):
764- return hardware # already a flavor name
765- try :
766- from huggingface_hub import HfApi
767-
768- gpu_name , gpu_count = "" , 0
769- try :
770- import torch
771-
772- if torch .cuda .is_available ():
773- gpu_name = torch .cuda .get_device_name (0 )
774- gpu_count = torch .cuda .device_count ()
775- except ImportError :
776- # Torch-free drivers (e.g. the -server recipes): ask nvidia-smi instead.
777- import subprocess
778-
779- try :
780- listed = subprocess .run (
781- ["nvidia-smi" , "--query-gpu=name" , "--format=csv,noheader" ],
782- capture_output = True , text = True , timeout = 10 , check = True ,
783- ).stdout
784- names = [line .strip () for line in listed .splitlines () if line .strip ()]
785- if names :
786- gpu_name , gpu_count = names [0 ], len (names )
787- except (OSError , subprocess .SubprocessError ):
788- pass
789- if gpu_count == 0 and hardware == "gpu" :
790- return "" # a GPU run whose GPU cannot be identified: do not guess a CPU flavor
791-
792- # Whole-word match, so "L4" does not match "NVIDIA L40S" ("NVIDIA A100-SXM4-80GB" -> A100).
793- gpu_words = gpu_name .upper ().replace ("-" , " " ).split ()
794- candidates = []
795- for flavor in HfApi (token = False ).list_jobs_hardware ():
796- accelerator = flavor .accelerator
797- if gpu_count == 0 and accelerator is None :
798- candidates .append (flavor )
799- elif (
800- gpu_count > 0
801- and accelerator is not None
802- and accelerator .model .upper () in gpu_words
803- and int (accelerator .quantity ) == gpu_count
804- ):
805- candidates .append (flavor )
806- if not candidates :
807- return ""
808-
809- cores = float (os .environ .get ("CPU_CORES" ) or 0 )
810- memory_gb = float ((os .environ .get ("MEMORY" ) or "0" ).upper ().rstrip ("GIB " ) or 0 )
811-
812- def distance (flavor ) -> float :
813- # Relative gap to the listed vCPUs and RAM; Jobs reports slightly different numbers.
814- listed_cores = float (flavor .cpu .split ()[0 ])
815- listed_memory = float (flavor .ram .split ()[0 ])
816- return abs (listed_cores - cores ) / listed_cores + abs (listed_memory - memory_gb ) / listed_memory
817-
818- return min (candidates , key = distance ).name
819- except Exception :
820- return ""
821-
822-
823751def build_reproduce_command (args ) -> str :
824752 """Rebuild the exact invocation, so the card's command produces the card's model."""
825- flavor = jobs_flavor ( ) or "t4-small"
753+ flavor = os . environ . get ( "HF_JOB_FLAVOR" , "" ) or "t4-small"
826754 # The timeout is the [tool.hf-jobs] default, spelled out because older CLIs ignore the header.
827755 parts = [f"hf jobs uv run --flavor { flavor } --timeout 1h --secrets HF_TOKEN \\ " ]
828756 if args .train_file :
@@ -914,7 +842,7 @@ def results_table(tasks: list, zero_shot, fine_tuned) -> str:
914842def build_card (args , tasks , zero_shot , fine_tuned , train_size , train_seconds , carved_out , oom_steps ) -> str :
915843 """Model card following the uv-scripts conventions (org credit, Jobs claim gated on HF_JOB_ID)."""
916844 on_jobs = os .environ .get ("HF_JOB_ID" ) is not None
917- hardware = jobs_flavor ( )
845+ hardware = os . environ . get ( "HF_JOB_FLAVOR" , "" )
918846 if on_jobs :
919847 provenance = "Produced on [Hugging Face Jobs](https://huggingface.co/docs/huggingface_hub/guides/jobs)"
920848 if hardware :
0 commit comments