id int64 1 6.07M | name stringlengths 1 295 | code stringlengths 12 426k | language stringclasses 1
value | source_file stringlengths 5 202 | start_line int64 1 158k | end_line int64 1 158k | repo dict |
|---|---|---|---|---|---|---|---|
4,701 | __init__ | def __init__(self, interval: Optional[float] = None) -> None:
self.samples: "Deque[List[float]]" = deque([])
self.interval = interval | python | wandb/sdk/internal/system/assets/cpu.py | 63 | 65 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,702 | sample | def sample(self) -> None:
self.samples.append(psutil.cpu_percent(interval=self.interval, percpu=True)) | python | wandb/sdk/internal/system/assets/cpu.py | 67 | 68 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,703 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/cpu.py | 70 | 71 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,704 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
num_cpu = len(self.samples[0])
cpu_metrics = {}
for i in range(num_cpu):
aggregate_i = aggregate_mean([sample[i] for sample in self.samples])
cpu_metrics[self.name.format(i=i)] = aggregate_i
return cpu_metrics | python | wandb/sdk/internal/system/assets/cpu.py | 73 | 82 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,705 | __init__ | def __init__(self, pid: int) -> None:
self.samples: "Deque[int]" = deque([])
self.pid = pid
self.process: Optional[psutil.Process] = None | python | wandb/sdk/internal/system/assets/cpu.py | 90 | 93 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,706 | sample | def sample(self) -> None:
if self.process is None:
self.process = psutil.Process(self.pid)
self.samples.append(self.process.num_threads()) | python | wandb/sdk/internal/system/assets/cpu.py | 95 | 99 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,707 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/cpu.py | 101 | 102 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,708 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
return {self.name: aggregate_last(self.samples)} | python | wandb/sdk/internal/system/assets/cpu.py | 104 | 107 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,709 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name: str = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
ProcessCpuPercent(settings._stats_pid),
CpuPercent(),
ProcessCpuThreads(settings._stats_pid),
]
self.metrics_monitor: "MetricsMonitor" = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/cpu.py | 112 | 130 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,710 | is_available | def is_available(cls) -> bool:
return psutil is not None | python | wandb/sdk/internal/system/assets/cpu.py | 133 | 134 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,711 | probe | def probe(self) -> dict:
asset_info = {
"cpu_count": psutil.cpu_count(logical=False),
"cpu_count_logical": psutil.cpu_count(logical=True),
}
try:
asset_info["cpu_freq"] = {
"current": psutil.cpu_freq().current,
"min": psutil.cpu_freq().min,
"max": psutil.cpu_freq().max,
}
asset_info["cpu_freq_per_core"] = [
{
"current": freq.current,
"min": freq.min,
"max": freq.max,
}
for freq in psutil.cpu_freq(percpu=True)
]
except Exception:
pass
return asset_info | python | wandb/sdk/internal/system/assets/cpu.py | 136 | 157 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,712 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/cpu.py | 159 | 160 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,713 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/cpu.py | 162 | 163 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,714 | check_neuron_monitor_config | def check_neuron_monitor_config(self) -> None:
# mkdir if not exists
pathlib.Path(self.neuron_monitor_config_path).parent.mkdir(
parents=True, exist_ok=True
)
# write default config
with open(self.neuron_monitor_config_path, "w") as f:
json.dump(NEURON_MONITOR_DEFAULT_CONFIG, f, indent=4) | python | wandb/sdk/internal/system/assets/trainium.py | 99 | 106 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,715 | neuron_monitor | def neuron_monitor(self) -> None:
self.check_neuron_monitor_config()
try:
command = [
NEURON_MONITOR_PATH,
"-c",
self.neuron_monitor_config_path,
]
with subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=None,
) as process:
while not self.shutdown_event.is_set():
if process.stdout is None:
self.shutdown_event.wait(0.1)
continue
raw_data = process.stdout.readline()
if raw_data:
self.raw_samples.append(raw_data)
process.kill()
process.wait()
except Exception as e:
logger.error("neuron-monitor failed: %s" % e) | python | wandb/sdk/internal/system/assets/trainium.py | 108 | 133 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,716 | __init__ | def __init__(
self,
pid: int,
neuron_monitor_config_path: Optional[str],
) -> None:
self.pid = pid
# neuron-monitor requires a config file (json)
# we provide an option to supply a custom config file path
# in case the default temp file path is not writable
self.neuron_monitor_config_path = (
neuron_monitor_config_path or tempfile.NamedTemporaryFile(delete=False).name
)
self.raw_samples: "Deque[bytes]" = deque(maxlen=10)
self.samples: "Deque[_Stats]" = deque()
self.shutdown_event = threading.Event()
self.neuron_monitor_thread: Optional[threading.Thread] = None | python | wandb/sdk/internal/system/assets/trainium.py | 135 | 151 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,717 | setup | def setup(self) -> None:
"""Start the neuron-monitor thread for collecting raw data."""
if self.neuron_monitor_thread is not None:
return
logger.debug("Starting neuron-monitor thread")
self.shutdown_event.clear()
self.neuron_monitor_thread = threading.Thread(
name="NeuronCoreMntr",
target=self.neuron_monitor,
daemon=True,
)
self.neuron_monitor_thread.start() | python | wandb/sdk/internal/system/assets/trainium.py | 153 | 165 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,718 | teardown | def teardown(self) -> None:
"""Stop the neuron-monitor thread."""
logger.debug("Stopping neuron-monitor thread")
try:
self.shutdown_event.set()
assert self.neuron_monitor_thread is not None
self.neuron_monitor_thread.join()
except Exception as e:
logger.error("neuron-monitor thread failed to stop: %s" % e)
finally:
self.neuron_monitor_thread = None | python | wandb/sdk/internal/system/assets/trainium.py | 167 | 177 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,719 | _is_matching_entry | def _is_matching_entry(self, entry: dict) -> bool:
"""For now, only check if the pid in the entry matches the pid of the process.
todo: add matching by neuron_runtime_tag
"""
return int(entry["pid"]) == int(self.pid) | python | wandb/sdk/internal/system/assets/trainium.py | 179 | 184 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,720 | sample | def sample(self) -> None:
try:
raw_stats = json.loads(self.raw_samples[-1])
neuron_runtime_data = [
entry["report"]
for entry in raw_stats["neuron_runtime_data"]
if self._is_matching_entry(entry)
][
0
] # there should be only one entry with the pid
neuroncores_in_use = neuron_runtime_data["neuroncore_counters"][
"neuroncores_in_use"
]
# per-core utilization stats:
neuroncore_utilization = [
v["neuroncore_utilization"] for k, v in neuroncores_in_use.items()
]
# memory usage
neuron_runtime_used_bytes = neuron_runtime_data["memory_used"][
"neuron_runtime_used_bytes"
]
# memory usage totals
host_total_memory_usage = neuron_runtime_used_bytes["host"]
neuron_device_total_memory_usage = neuron_runtime_used_bytes[
"neuron_device"
]
# memory usage breakdown
usage_breakdown = neuron_runtime_used_bytes["usage_breakdown"]
host_memory_usage = _HostMemoryUsage(**usage_breakdown["host"])
neuroncore_memory_usage = [
_NeuronCoreMemoryUsage(**v)
for v in usage_breakdown["neuroncore_memory_usage"].values()
]
stats: _Stats = _Stats(
neuroncore_utilization=neuroncore_utilization,
host_total_memory_usage=host_total_memory_usage,
neuron_device_total_memory_usage=neuron_device_total_memory_usage,
host_memory_usage=host_memory_usage,
neuroncore_memory_usage=neuroncore_memory_usage,
)
self.samples.append(stats)
except Exception as e: # noqa
pass | python | wandb/sdk/internal/system/assets/trainium.py | 186 | 231 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,721 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/trainium.py | 233 | 234 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,722 | flatten_stats | def flatten_stats(sample: _Stats) -> dict:
"""Flatten _Stats object into a flat dict of numbers."""
flattened = {}
def helper(key: str, value: Any) -> None:
if isinstance(value, (int, float)):
ret = {f"{key}": value}
flattened.update(ret)
return
elif isinstance(value, dict):
for kk, vv in value.items():
helper(f"{key}.{kk}", vv)
return
elif isinstance(value, list):
for i, val in enumerate(value):
helper(f"{i}.{key}", val)
for kkk, vvv in dataclasses.asdict(sample).items():
helper(kkk, vvv)
return flattened | python | wandb/sdk/internal/system/assets/trainium.py | 237 | 257 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,723 | helper | def helper(key: str, value: Any) -> None:
if isinstance(value, (int, float)):
ret = {f"{key}": value}
flattened.update(ret)
return
elif isinstance(value, dict):
for kk, vv in value.items():
helper(f"{key}.{kk}", vv)
return
elif isinstance(value, list):
for i, val in enumerate(value):
helper(f"{i}.{key}", val) | python | wandb/sdk/internal/system/assets/trainium.py | 241 | 252 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,724 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
stats = {}
# Stats could be: numbers or dataclass objects or lists of such.
# In the latter case that means per-core stats.
# The dataclass objects are flat containers of numbers.
# flatten samples and merge the corresponding values into lists
merged_samples: Dict[str, List[Union[int, float]]] = collections.defaultdict(
list
)
for flattened_sample in (self.flatten_stats(sample) for sample in self.samples):
for k, v in flattened_sample.items():
merged_samples[k].append(v)
# aggregate the lists
for k, v in merged_samples.items():
stats[self.name.format(key=k)] = aggregate_mean(v)
return stats | python | wandb/sdk/internal/system/assets/trainium.py | 259 | 281 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,725 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
NeuronCoreStats(
settings._stats_pid,
settings._stats_neuron_monitor_config_path,
),
]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
)
telemetry_record = telemetry.TelemetryRecord()
telemetry_record.env.trainium = True
interface._publish_telemetry(telemetry_record) | python | wandb/sdk/internal/system/assets/trainium.py | 286 | 308 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,726 | is_available | def is_available(cls) -> bool:
# todo: check if neuron-ls is available and if yes, what it reports. see:
# https://awsdocs-neuron.readthedocs-hosted.com/en/latest/tools/neuron-sys-tools/neuron-ls.html
if not pathlib.Path(NEURON_LS_COMMAND[0]).exists():
return False
# need to be extra careful as neuron tools could be pre-installed
# on some systems that do not have the hardware
try:
# redirect stderr to null to avoid printing errors to the console
# todo: alternative: check /dev/neuron0 ? sysfs support coming soon in neuron tools
output = subprocess.check_output(
NEURON_LS_COMMAND,
universal_newlines=True,
stderr=subprocess.DEVNULL,
).strip()
if len(json.loads(output)) > 0:
return True
except (OSError, ValueError, TypeError, subprocess.CalledProcessError):
pass
return False | python | wandb/sdk/internal/system/assets/trainium.py | 311 | 331 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,727 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/trainium.py | 333 | 334 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,728 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/trainium.py | 336 | 337 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,729 | probe | def probe(self) -> dict:
try:
self.metrics[0].check_neuron_monitor_config() # type: ignore
neuron_hardware_info: dict = {}
command = [
NEURON_MONITOR_PATH,
"-c",
self.metrics[0].neuron_monitor_config_path, # type: ignore
]
with subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=None,
) as process:
while True:
if process.stdout is None:
time.sleep(0.1)
continue
raw_data = process.stdout.readline()
if raw_data:
parsed_data = json.loads(raw_data)
neuron_hardware_info = parsed_data.get(
"neuron_hardware_info", {}
)
neuron_hardware_info.pop("error", None)
break
try:
process.kill()
process.wait()
except: # noqa
pass
return {self.name: neuron_hardware_info}
except Exception as e:
logger.error("neuron-monitor failed: %s" % e)
return {} | python | wandb/sdk/internal/system/assets/trainium.py | 339 | 376 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,730 | aggregate_mean | def aggregate_mean(samples: Sequence[Number], precision: int = 2) -> float:
return round(sum(samples) / len(samples), precision) | python | wandb/sdk/internal/system/assets/aggregators.py | 12 | 13 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,731 | aggregate_last | def aggregate_last(samples: Sequence[Number], precision: int = 2) -> Union[float, int]:
if isinstance(samples[-1], int):
return samples[-1]
return round(samples[-1], precision) | python | wandb/sdk/internal/system/assets/aggregators.py | 16 | 19 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,732 | aggregate_max | def aggregate_max(samples: Sequence[Number], precision: int = 2) -> Union[float, int]:
if isinstance(samples[-1], int):
return max(samples)
return round(max(samples), precision) | python | wandb/sdk/internal/system/assets/aggregators.py | 22 | 25 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,733 | aggregate_min | def aggregate_min(samples: Sequence[Number], precision: int = 2) -> Union[float, int]:
if isinstance(samples[-1], int):
return min(samples)
return round(min(samples), precision) | python | wandb/sdk/internal/system/assets/aggregators.py | 28 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,734 | aggregate_sum | def aggregate_sum(samples: Sequence[Number], precision: int = 2) -> Union[float, int]:
if isinstance(samples[-1], int):
return sum(samples)
return round(sum(samples), precision) | python | wandb/sdk/internal/system/assets/aggregators.py | 34 | 37 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,735 | __init__ | def __init__(self) -> None:
self._registry: List[Type[Asset]] = [] | python | wandb/sdk/internal/system/assets/asset_registry.py | 7 | 8 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,736 | register | def register(self, asset: Type[Asset]) -> Type[Asset]:
self._registry.append(asset)
return asset | python | wandb/sdk/internal/system/assets/asset_registry.py | 10 | 12 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,737 | __iter__ | def __iter__(self) -> Iterator[Type[Asset]]:
for asset in self._registry:
if asset.is_available():
yield asset | python | wandb/sdk/internal/system/assets/asset_registry.py | 14 | 17 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,738 | __init__ | def __init__(
self,
service_addr: str,
duration_ms: int = 100,
) -> None:
self.samples = deque([])
self.duration_ms = duration_ms
self.service_addr = service_addr
try:
from tensorflow.python.profiler import profiler_client # type: ignore
self._profiler_client = profiler_client
except ImportError:
logger.warning(
"Unable to import `tensorflow.python.profiler.profiler_client`. "
"TPU metrics will not be reported."
)
self._profiler_client = None | python | wandb/sdk/internal/system/assets/tpu.py | 25 | 44 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,739 | sample | def sample(self) -> None:
result = self._profiler_client.monitor(
self.service_addr, duration_ms=self.duration_ms, level=2
)
self.samples.append(
float(result.split("Utilization ")[1].split(": ")[1].split("%")[0])
) | python | wandb/sdk/internal/system/assets/tpu.py | 46 | 53 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,740 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/tpu.py | 55 | 56 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,741 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
aggregate = aggregate_mean(self.samples)
return {self.name: aggregate} | python | wandb/sdk/internal/system/assets/tpu.py | 58 | 62 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,742 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.service_addr = self.get_service_addr()
self.metrics: List[Metric] = [TPUUtilization(self.service_addr)]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/tpu.py | 67 | 83 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,743 | get_service_addr | def get_service_addr(
service_addr: Optional[str] = None,
tpu_name: Optional[str] = None,
compute_zone: Optional[str] = None,
core_project: Optional[str] = None,
) -> str:
if service_addr is not None:
if tpu_name is not None:
logger.warn(
"Both service_addr and tpu_name arguments provided. "
"Ignoring tpu_name and using service_addr."
)
else:
tpu_name = tpu_name or os.environ.get("TPU_NAME")
if tpu_name is None:
raise Exception("Required environment variable TPU_NAME.")
compute_zone = compute_zone or os.environ.get("CLOUDSDK_COMPUTE_ZONE")
core_project = core_project or os.environ.get("CLOUDSDK_CORE_PROJECT")
try:
from tensorflow.python.distribute.cluster_resolver import ( # type: ignore
tpu_cluster_resolver,
)
service_addr = tpu_cluster_resolver.TPUClusterResolver(
[tpu_name], zone=compute_zone, project=core_project
).get_master()
except (ValueError, TypeError):
raise ValueError(
"Failed to find TPU. Try specifying TPU zone "
"(via CLOUDSDK_COMPUTE_ZONE environment variable)"
" and GCP project (via CLOUDSDK_CORE_PROJECT "
"environment variable)."
)
service_addr = service_addr.replace("grpc://", "").replace(":8470", ":8466")
return service_addr | python | wandb/sdk/internal/system/assets/tpu.py | 86 | 120 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,744 | start | def start(self) -> None:
if self.metrics:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/tpu.py | 122 | 124 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,745 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/tpu.py | 126 | 127 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,746 | is_available | def is_available(cls) -> bool:
if os.environ.get("TPU_NAME", False) is False:
return False
try:
from tensorflow.python.distribute.cluster_resolver import ( # noqa: F401
tpu_cluster_resolver,
)
from tensorflow.python.profiler import profiler_client # noqa: F401
cls.get_service_addr()
except (
ImportError,
TypeError,
AttributeError,
ValueError,
): # Saw type error when iterating paths on colab...
# TODO: Saw error in sentry where module 'tensorflow.python.pywrap_tensorflow'
# has no attribute 'TFE_DEVICE_PLACEMENT_EXPLICIT'
return False
return True | python | wandb/sdk/internal/system/assets/tpu.py | 130 | 151 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,747 | probe | def probe(self) -> dict:
return {self.name: {"service_address": self.service_addr}} | python | wandb/sdk/internal/system/assets/tpu.py | 153 | 154 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,748 | __init__ | def __init__(self) -> None:
self.samples = deque([])
self.sent_init = psutil.net_io_counters().bytes_sent | python | wandb/sdk/internal/system/assets/network.py | 26 | 28 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,749 | sample | def sample(self) -> None:
self.samples.append(psutil.net_io_counters().bytes_sent - self.sent_init) | python | wandb/sdk/internal/system/assets/network.py | 30 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,750 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/network.py | 33 | 34 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,751 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
aggregate = aggregate_mean(self.samples)
# todo: this is an adapter for the legacy metrics system
# return {"network": {self.name: aggregate}}
return {self.name: aggregate} | python | wandb/sdk/internal/system/assets/network.py | 36 | 42 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,752 | __init__ | def __init__(self) -> None:
self.samples = deque([])
self.recv_init = psutil.net_io_counters().bytes_recv | python | wandb/sdk/internal/system/assets/network.py | 51 | 53 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,753 | sample | def sample(self) -> None:
self.samples.append(psutil.net_io_counters().bytes_recv - self.recv_init) | python | wandb/sdk/internal/system/assets/network.py | 55 | 56 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,754 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/network.py | 58 | 59 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,755 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
aggregate = aggregate_mean(self.samples)
# todo: this is an adapter for the legacy metrics system
# return {"network": {self.name: aggregate}}
return {self.name: aggregate} | python | wandb/sdk/internal/system/assets/network.py | 61 | 68 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,756 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
NetworkSent(),
NetworkRecv(),
]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/network.py | 73 | 90 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,757 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/network.py | 92 | 93 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,758 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/network.py | 95 | 96 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,759 | is_available | def is_available(cls) -> bool:
"""Return a new instance of the CPU metrics."""
return psutil is not None | python | wandb/sdk/internal/system/assets/network.py | 99 | 101 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,760 | probe | def probe(self) -> dict:
"""Return a dict of the hardware information."""
# net_if_addrs = psutil.net_if_addrs()
# return {
# self.name: {
# "interfaces": {
# k: {
# "addresses": [
# {
# "address": v.address,
# "netmask": v.netmask,
# "broadcast": v.broadcast,
# "ptp": v.ptp,
# }
# for v in v
# ]
# }
# for k, v in net_if_addrs.items()
# }
# }
# }
return {} | python | wandb/sdk/internal/system/assets/network.py | 103 | 125 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,761 | _setup_requests_session | def _setup_requests_session() -> requests.Session:
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
max_retries=_REQUEST_RETRY_STRATEGY,
pool_connections=_REQUEST_POOL_CONNECTIONS,
pool_maxsize=_REQUEST_POOL_MAXSIZE,
)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session | python | wandb/sdk/internal/system/assets/open_metrics.py | 56 | 65 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,762 | _nested_dict_to_tuple | def _nested_dict_to_tuple(
nested_dict: Mapping[str, Mapping[str, str]]
) -> Tuple[Tuple[str, Tuple[str, str]], ...]:
return tuple((k, *v.items()) for k, v in nested_dict.items()) # type: ignore | python | wandb/sdk/internal/system/assets/open_metrics.py | 68 | 71 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,763 | _tuple_to_nested_dict | def _tuple_to_nested_dict(
nested_tuple: Tuple[Tuple[str, Tuple[str, str]], ...]
) -> Dict[str, Dict[str, str]]:
return {k: dict(v) for k, *v in nested_tuple} | python | wandb/sdk/internal/system/assets/open_metrics.py | 74 | 77 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,764 | _should_capture_metric | def _should_capture_metric(
endpoint_name: str,
metric_name: str,
metric_labels: Tuple[str, ...],
filters: Tuple[Tuple[str, Tuple[str, str]], ...],
) -> bool:
# we use tuples to make the function arguments hashable => usable with lru_cache
should_capture = False
if not filters:
return should_capture
# self.filters keys are regexes, check the name against them
# and for the first match, check the labels against the label filters.
# assume that if at least one label filter doesn't match, the metric
# should not be captured.
# it's up to the user to make sure that the filters are not conflicting etc.
metric_labels_dict = {t[0]: t[1] for t in metric_labels}
filters_dict = _tuple_to_nested_dict(filters)
for metric_name_regex, label_filters in filters_dict.items():
if not re.match(metric_name_regex, f"{endpoint_name}.{metric_name}"):
continue
should_capture = True
for label, label_filter in label_filters.items():
if not re.match(label_filter, metric_labels_dict.get(label, "")):
should_capture = False
break
break
return should_capture | python | wandb/sdk/internal/system/assets/open_metrics.py | 81 | 112 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,765 | __init__ | def __init__(
self, name: str, url: str, filters: Mapping[str, Mapping[str, str]]
) -> None:
self.name = name
self.url = url
self.filters = filters
self.filters_tuple = _nested_dict_to_tuple(filters)
self._session: Optional["requests.Session"] = None
self.samples: "Deque[dict]" = deque([])
# {"<metric name>": {"<labels hash>": <index>}}
self.label_map: "Dict[str, Dict[str, int]]" = defaultdict(dict)
# {"<labels hash>": <labels>}
self.label_hashes: "Dict[str, dict]" = {} | python | wandb/sdk/internal/system/assets/open_metrics.py | 118 | 130 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,766 | setup | def setup(self) -> None:
if self._session is not None:
return
self._session = _setup_requests_session() | python | wandb/sdk/internal/system/assets/open_metrics.py | 132 | 136 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,767 | teardown | def teardown(self) -> None:
if self._session is None:
return
self._session.close()
self._session = None | python | wandb/sdk/internal/system/assets/open_metrics.py | 138 | 143 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,768 | parse_open_metrics_endpoint | def parse_open_metrics_endpoint(self) -> Dict[str, Union[str, int, float]]:
assert prometheus_client_parser is not None
assert self._session is not None
response = self._session.get(self.url, timeout=_REQUEST_TIMEOUT)
response.raise_for_status()
text = response.text
measurement = {}
for family in prometheus_client_parser.text_string_to_metric_families(text):
if family.type not in ("counter", "gauge"):
# todo: add support for other metric types?
# todo: log warning about that?
continue
for sample in family.samples:
name, labels, value = sample.name, sample.labels, sample.value
if not _should_capture_metric(
self.name,
name,
tuple(labels.items()),
self.filters_tuple,
):
continue
# md5 hash of the labels
label_hash = md5(str(labels).encode("utf-8")).hexdigest()
if label_hash not in self.label_map[name]:
# store the index of the label hash in the label map
self.label_map[name][label_hash] = len(self.label_map[name])
# store the labels themselves
self.label_hashes[label_hash] = labels
index = self.label_map[name][label_hash]
measurement[f"{name}.{index}"] = value
return measurement | python | wandb/sdk/internal/system/assets/open_metrics.py | 145 | 180 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,769 | sample | def sample(self) -> None:
s = self.parse_open_metrics_endpoint()
self.samples.append(s) | python | wandb/sdk/internal/system/assets/open_metrics.py | 182 | 184 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,770 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/open_metrics.py | 186 | 187 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,771 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
prefix = f"{_PREFIX}.{self.name}."
stats = {}
for key in self.samples[0].keys():
samples = [s[key] for s in self.samples if key in s]
if samples and all(isinstance(s, (int, float)) for s in samples):
stats[f"{prefix}{key}"] = aggregate_mean(samples)
else:
stats[f"{prefix}{key}"] = aggregate_last(samples)
return stats | python | wandb/sdk/internal/system/assets/open_metrics.py | 189 | 202 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,772 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
name: str,
url: str,
) -> None:
self.name = name
self.url = url
self.interface = interface
self.settings = settings
self.shutdown_event = shutdown_event
self.metrics: List[Metric] = [
OpenMetricsMetric(name, url, settings._stats_open_metrics_filters)
]
self.metrics_monitor: "MetricsMonitor" = MetricsMonitor(
asset_name=self.name,
metrics=self.metrics,
interface=interface,
settings=settings,
shutdown_event=shutdown_event,
)
telemetry_record = telemetry.TelemetryRecord()
telemetry_record.feature.open_metrics = True
interface._publish_telemetry(telemetry_record) | python | wandb/sdk/internal/system/assets/open_metrics.py | 209 | 237 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,773 | is_available | def is_available(cls, url: str) -> bool:
_is_available: bool = False
ret = prometheus_client_parser is not None
if not ret:
wandb.termwarn(
"Monitoring OpenMetrics endpoints requires the `prometheus_client` package. "
"To install it, run `pip install prometheus_client`.",
repeat=False,
)
return _is_available
# check if the endpoint is available and is a valid OpenMetrics endpoint
_session: Optional[requests.Session] = None
try:
assert prometheus_client_parser is not None
_session = _setup_requests_session()
response = _session.get(url, timeout=_REQUEST_TIMEOUT)
response.raise_for_status()
# check if the response is a valid OpenMetrics response
# text_string_to_metric_families returns a generator
if list(
prometheus_client_parser.text_string_to_metric_families(response.text)
):
_is_available = True
except Exception as e:
logger.debug(
f"OpenMetrics endpoint {url} is not available: {e}", exc_info=True
)
if _session is not None:
try:
_session.close()
except Exception:
pass
return _is_available | python | wandb/sdk/internal/system/assets/open_metrics.py | 240 | 275 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,774 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/open_metrics.py | 277 | 278 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,775 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/open_metrics.py | 280 | 281 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,776 | probe | def probe(self) -> dict:
# todo: also return self.label_hashes
return {self.name: self.url} | python | wandb/sdk/internal/system/assets/open_metrics.py | 283 | 285 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,777 | __init__ | def __init__(self) -> None:
self.samples = deque()
self.binary_path = (
pathlib.Path(sys.modules["wandb"].__path__[0]) / "bin" / "apple_gpu_stats"
).resolve() | python | wandb/sdk/internal/system/assets/gpu_apple.py | 50 | 54 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,778 | sample | def sample(self) -> None:
try:
command = [str(self.binary_path), "--json"]
output = (
subprocess.check_output(command, universal_newlines=True)
.strip()
.split("\n")
)[0]
raw_stats = json.loads(output)
stats: _Stats = {
"gpu": raw_stats["utilization"],
"memoryAllocated": raw_stats["mem_used"],
"temp": raw_stats["temperature"],
"powerWatts": raw_stats["power"],
"powerPercent": (raw_stats["power"] / self.MAX_POWER_WATTS) * 100,
# TODO: this stat could be useful eventually, it was consistently
# 0 in my experimentation and requires a frontend change
# so leaving it out for now.
# "cpuWaitMs": raw_stats["cpu_wait_ms"],
}
self.samples.append(stats)
except (OSError, ValueError, TypeError, subprocess.CalledProcessError) as e:
logger.exception(f"GPU stats error: {e}") | python | wandb/sdk/internal/system/assets/gpu_apple.py | 56 | 81 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,779 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/gpu_apple.py | 83 | 84 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,780 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
stats = {}
for key in self.samples[0].keys():
samples = [s[key] for s in self.samples] # type: ignore
aggregate = aggregate_mean(samples)
stats[self.name.format(key)] = aggregate
return stats | python | wandb/sdk/internal/system/assets/gpu_apple.py | 86 | 94 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,781 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
GPUAppleStats(),
]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
)
telemetry_record = telemetry.TelemetryRecord()
telemetry_record.env.m1_gpu = True
interface._publish_telemetry(telemetry_record) | python | wandb/sdk/internal/system/assets/gpu_apple.py | 99 | 118 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,782 | is_available | def is_available(cls) -> bool:
return platform.system() == "Darwin" and platform.processor() == "arm" | python | wandb/sdk/internal/system/assets/gpu_apple.py | 121 | 122 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,783 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/gpu_apple.py | 124 | 125 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,784 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/gpu_apple.py | 127 | 128 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,785 | probe | def probe(self) -> dict:
# todo: make this actually meaningful
return {self.name: {"type": "arm", "vendor": "Apple"}} | python | wandb/sdk/internal/system/assets/gpu_apple.py | 130 | 132 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,786 | gpu_in_use_by_this_process | def gpu_in_use_by_this_process(gpu_handle: "GPUHandle", pid: int) -> bool:
if psutil is None:
return False
try:
base_process = psutil.Process(pid=pid)
except psutil.NoSuchProcess:
# do not report any gpu metrics if the base process cant be found
return False
our_processes = base_process.children(recursive=True)
our_processes.append(base_process)
our_pids = {process.pid for process in our_processes}
compute_pids = {
process.pid
for process in pynvml.nvmlDeviceGetComputeRunningProcesses(gpu_handle) # type: ignore
}
graphics_pids = {
process.pid
for process in pynvml.nvmlDeviceGetGraphicsRunningProcesses(gpu_handle) # type: ignore
}
pids_using_device = compute_pids | graphics_pids
return len(pids_using_device & our_pids) > 0 | python | wandb/sdk/internal/system/assets/gpu.py | 28 | 54 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,787 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/gpu.py | 65 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,788 | sample | def sample(self) -> None:
memory_utilization_rate = []
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
memory_utilization_rate.append(
pynvml.nvmlDeviceGetUtilizationRates(handle).memory # type: ignore
)
self.samples.append(memory_utilization_rate) | python | wandb/sdk/internal/system/assets/gpu.py | 69 | 77 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,789 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/gpu.py | 79 | 80 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,790 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
stats = {}
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
samples = [sample[i] for sample in self.samples]
aggregate = aggregate_mean(samples)
stats[self.name.format(i)] = aggregate
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
if gpu_in_use_by_this_process(handle, self.pid):
stats[self.name.format(f"process.{i}")] = aggregate
return stats | python | wandb/sdk/internal/system/assets/gpu.py | 82 | 96 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,791 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/gpu.py | 107 | 109 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,792 | sample | def sample(self) -> None:
memory_allocated = []
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle) # type: ignore
memory_allocated.append(memory_info.used / memory_info.total * 100)
self.samples.append(memory_allocated) | python | wandb/sdk/internal/system/assets/gpu.py | 111 | 118 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,793 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/gpu.py | 120 | 121 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,794 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
stats = {}
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
samples = [sample[i] for sample in self.samples]
aggregate = aggregate_mean(samples)
stats[self.name.format(i)] = aggregate
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
if gpu_in_use_by_this_process(handle, self.pid):
stats[self.name.format(f"process.{i}")] = aggregate
return stats | python | wandb/sdk/internal/system/assets/gpu.py | 123 | 137 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,795 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/gpu.py | 148 | 150 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,796 | sample | def sample(self) -> None:
gpu_utilization_rate = []
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
gpu_utilization_rate.append(
pynvml.nvmlDeviceGetUtilizationRates(handle).gpu # type: ignore
)
self.samples.append(gpu_utilization_rate) | python | wandb/sdk/internal/system/assets/gpu.py | 152 | 160 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,797 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/gpu.py | 162 | 163 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,798 | aggregate | def aggregate(self) -> dict:
if not self.samples:
return {}
stats = {}
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
samples = [sample[i] for sample in self.samples]
aggregate = aggregate_mean(samples)
stats[self.name.format(i)] = aggregate
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
if gpu_in_use_by_this_process(handle, self.pid):
stats[self.name.format(f"process.{i}")] = aggregate
return stats | python | wandb/sdk/internal/system/assets/gpu.py | 165 | 179 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,799 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/gpu.py | 190 | 192 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,800 | sample | def sample(self) -> None:
temperature = []
device_count = pynvml.nvmlDeviceGetCount() # type: ignore
for i in range(device_count):
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # type: ignore
temperature.append(
pynvml.nvmlDeviceGetTemperature( # type: ignore
handle,
pynvml.NVML_TEMPERATURE_GPU,
)
)
self.samples.append(temperature) | python | wandb/sdk/internal/system/assets/gpu.py | 194 | 205 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.