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,601 | __init__ | def __init__(self) -> None:
self._opened_for_scan = False
self._fp = None
self._index = 0
self._flush_offset = 0
self._size_bytes = 0
self._crc = [0] * (LEVELDBLOG_LAST + 1)
for x in range(1, LEVELDBLOG_LAST + 1):
self._crc[x] = zlib.crc32(strtobytes(chr(x))) & 0xFFFFFFFF
assert (
wandb._assert_is_internal_process
), "DataStore can only be used in the internal process" | python | wandb/sdk/internal/datastore.py | 68 | 81 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,602 | open_for_write | def open_for_write(self, fname: str) -> None:
self._fname = fname
logger.info("open: %s", fname)
open_flags = "xb"
self._fp = open(fname, open_flags)
self._write_header() | python | wandb/sdk/internal/datastore.py | 83 | 88 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,603 | open_for_append | def open_for_append(self, fname):
# TODO: implement
self._fname = fname
logger.info("open: %s", fname)
self._fp = open(fname, "wb")
# do something with _index | python | wandb/sdk/internal/datastore.py | 90 | 95 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,604 | open_for_scan | def open_for_scan(self, fname):
self._fname = fname
logger.info("open for scan: %s", fname)
self._fp = open(fname, "r+b")
self._index = 0
self._size_bytes = os.stat(fname).st_size
self._opened_for_scan = True
self._read_header() | python | wandb/sdk/internal/datastore.py | 97 | 104 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,605 | seek | def seek(self, offset: int) -> None:
self._fp.seek(offset)
self._index = offset | python | wandb/sdk/internal/datastore.py | 106 | 108 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,606 | get_offset | def get_offset(self) -> int:
offset = self._fp.tell()
return offset | python | wandb/sdk/internal/datastore.py | 110 | 112 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,607 | in_last_block | def in_last_block(self):
"""Determine if we're in the last block to handle in-progress writes."""
return self._index > self._size_bytes - LEVELDBLOG_DATA_LEN | python | wandb/sdk/internal/datastore.py | 114 | 116 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,608 | scan_record | def scan_record(self):
assert self._opened_for_scan, "file not open for scanning"
# TODO(jhr): handle some assertions as file corruption issues
# assume we have enough room to read header, checked by caller?
header = self._fp.read(LEVELDBLOG_HEADER_LEN)
if len(header) == 0:
return None
assert (
len(header) == LEVELDBLOG_HEADER_LEN
), "record header is {} bytes instead of the expected {}".format(
len(header), LEVELDBLOG_HEADER_LEN
)
fields = struct.unpack("<IHB", header)
checksum, dlength, dtype = fields
# check len, better fit in the block
self._index += LEVELDBLOG_HEADER_LEN
data = self._fp.read(dlength)
checksum_computed = zlib.crc32(data, self._crc[dtype]) & 0xFFFFFFFF
assert (
checksum == checksum_computed
), "record checksum is invalid, data may be corrupt"
self._index += dlength
return dtype, data | python | wandb/sdk/internal/datastore.py | 118 | 140 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,609 | scan_data | def scan_data(self):
# TODO(jhr): handle some assertions as file corruption issues
# how much left in the block. if less than header len, read as pad,
offset = self._index % LEVELDBLOG_BLOCK_LEN
space_left = LEVELDBLOG_BLOCK_LEN - offset
if space_left < LEVELDBLOG_HEADER_LEN:
pad_check = strtobytes("\x00" * space_left)
pad = self._fp.read(space_left)
# verify they are zero
assert pad == pad_check, "invalid padding"
self._index += space_left
record = self.scan_record()
if record is None: # eof
return None
dtype, data = record
if dtype == LEVELDBLOG_FULL:
return data
assert (
dtype == LEVELDBLOG_FIRST
), f"expected record to be type {LEVELDBLOG_FIRST} but found {dtype}"
while True:
offset = self._index % LEVELDBLOG_BLOCK_LEN
record = self.scan_record()
if record is None: # eof
return None
dtype, new_data = record
if dtype == LEVELDBLOG_LAST:
data += new_data
break
assert (
dtype == LEVELDBLOG_MIDDLE
), "expected record to be type {} but found {}".format(
LEVELDBLOG_MIDDLE, dtype
)
data += new_data
return data | python | wandb/sdk/internal/datastore.py | 142 | 179 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,610 | _write_header | def _write_header(self):
data = struct.pack(
"<4sHB",
strtobytes(LEVELDBLOG_HEADER_IDENT),
LEVELDBLOG_HEADER_MAGIC,
LEVELDBLOG_HEADER_VERSION,
)
assert (
len(data) == LEVELDBLOG_HEADER_LEN
), "header size is {} bytes, expected {}".format(
len(data), LEVELDBLOG_HEADER_LEN
)
self._fp.write(data)
self._index += len(data) | python | wandb/sdk/internal/datastore.py | 181 | 194 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,611 | _read_header | def _read_header(self):
header = self._fp.read(LEVELDBLOG_HEADER_LEN)
assert (
len(header) == LEVELDBLOG_HEADER_LEN
), "header is {} bytes instead of the expected {}".format(
len(header), LEVELDBLOG_HEADER_LEN
)
ident, magic, version = struct.unpack("<4sHB", header)
if ident != strtobytes(LEVELDBLOG_HEADER_IDENT):
raise Exception("Invalid header")
if magic != LEVELDBLOG_HEADER_MAGIC:
raise Exception("Invalid header")
if version != LEVELDBLOG_HEADER_VERSION:
raise Exception("Invalid header")
self._index += len(header) | python | wandb/sdk/internal/datastore.py | 196 | 210 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,612 | _write_record | def _write_record(self, s, dtype=None):
"""Write record that must fit into a block."""
# double check that there is enough space
# (this is a precondition to calling this method)
assert len(s) + LEVELDBLOG_HEADER_LEN <= (
LEVELDBLOG_BLOCK_LEN - self._index % LEVELDBLOG_BLOCK_LEN
), "not enough space to write new records"
dlength = len(s)
dtype = dtype or LEVELDBLOG_FULL
# print("record: length={} type={}".format(dlength, dtype))
checksum = zlib.crc32(s, self._crc[dtype]) & 0xFFFFFFFF
# logger.info("write_record: index=%d len=%d dtype=%d",
# self._index, dlength, dtype)
self._fp.write(struct.pack("<IHB", checksum, dlength, dtype))
if dlength:
self._fp.write(s)
self._index += LEVELDBLOG_HEADER_LEN + len(s) | python | wandb/sdk/internal/datastore.py | 212 | 229 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,613 | _write_data | def _write_data(self, s):
start_offset = self._index
offset = self._index % LEVELDBLOG_BLOCK_LEN
space_left = LEVELDBLOG_BLOCK_LEN - offset
data_used = 0
data_left = len(s)
# logger.info("write_data: index=%d offset=%d len=%d",
# self._index, offset, data_left)
if space_left < LEVELDBLOG_HEADER_LEN:
pad = "\x00" * space_left
self._fp.write(strtobytes(pad))
self._index += space_left
offset = 0
space_left = LEVELDBLOG_BLOCK_LEN
# does it fit in first (possibly partial) block?
if data_left + LEVELDBLOG_HEADER_LEN <= space_left:
self._write_record(s)
else:
# write first record (we could still be in the middle of a block,
# but this write will end on a block boundary)
data_room = space_left - LEVELDBLOG_HEADER_LEN
self._write_record(s[:data_room], LEVELDBLOG_FIRST)
data_used += data_room
data_left -= data_room
assert data_left, "data_left should be non-zero"
# write middles (if any)
while data_left > LEVELDBLOG_DATA_LEN:
self._write_record(
s[data_used : data_used + LEVELDBLOG_DATA_LEN],
LEVELDBLOG_MIDDLE,
)
data_used += LEVELDBLOG_DATA_LEN
data_left -= LEVELDBLOG_DATA_LEN
# write last and flush the entire block to disk
self._write_record(s[data_used:], LEVELDBLOG_LAST)
self._fp.flush()
os.fsync(self._fp.fileno())
self._flush_offset = self._index
return start_offset, self._index, self._flush_offset | python | wandb/sdk/internal/datastore.py | 231 | 274 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,614 | ensure_flushed | def ensure_flushed(self, off: int) -> None:
self._fp.flush() | python | wandb/sdk/internal/datastore.py | 276 | 277 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,615 | write | def write(self, obj: "Record") -> Tuple[int, int, int]:
"""Write a protocol buffer.
Arguments:
obj: Protocol buffer to write.
Returns:
(start_offset, end_offset, flush_offset) if successful,
None otherwise
"""
raw_size = obj.ByteSize()
s = obj.SerializeToString()
assert len(s) == raw_size, "invalid serialization"
ret = self._write_data(s)
return ret | python | wandb/sdk/internal/datastore.py | 279 | 294 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,616 | close | def close(self) -> None:
if self._fp is not None:
logger.info("close: %s", self._fname)
self._fp.close() | python | wandb/sdk/internal/datastore.py | 296 | 299 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,617 | __init__ | def __init__(self) -> None:
self.metrics_queue: "queue.Queue[dict]" = queue.Queue()
self.telemetry_queue: "queue.Queue[TelemetryRecord]" = queue.Queue() | python | wandb/sdk/internal/system/system_monitor.py | 21 | 23 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,618 | publish_stats | def publish_stats(self, stats: dict) -> None:
self.metrics_queue.put(stats) | python | wandb/sdk/internal/system/system_monitor.py | 25 | 26 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,619 | _publish_telemetry | def _publish_telemetry(self, telemetry: "TelemetryRecord") -> None:
self.telemetry_queue.put(telemetry) | python | wandb/sdk/internal/system/system_monitor.py | 28 | 29 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,620 | publish_files | def publish_files(self, files_dict: "FilesDict") -> None:
pass | python | wandb/sdk/internal/system/system_monitor.py | 31 | 32 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,621 | __init__ | def __init__(
self,
settings: "SettingsStatic",
interface: "Interface",
) -> None:
self._shutdown_event: threading.Event = threading.Event()
self._process: Optional[threading.Thread] = None
self.settings = settings
# settings._stats_join_assets controls whether we should join stats from different assets
# before publishing them to the backend. If set to False, we will publish stats from each
# asset separately, using the backend interface. If set to True, we will aggregate stats from
# all assets before publishing them, using an internal queue interface, and then publish
# them using the interface to the backend.
# This is done to improve compatibility with older versions of the backend as it used to
# collect the names of the metrics to be displayed in the UI from the first stats message.
# compute the global publishing interval if _stats_join_assets is requested
sampling_interval: float = float(
max(
0.1,
self.settings._stats_sample_rate_seconds,
)
) # seconds
# The number of samples to aggregate (e.g. average or compute max/min etc.)
# before publishing; defaults to 15; valid range: [1:30]
samples_to_aggregate: int = min(
30, max(1, self.settings._stats_samples_to_average)
)
self.publishing_interval: float = sampling_interval * samples_to_aggregate
self.join_assets: bool = self.settings._stats_join_assets
self.backend_interface = interface
self.asset_interface: Optional[AssetInterface] = (
AssetInterface() if self.join_assets else None
)
# hardware assets
self.assets: List["Asset"] = self._get_assets()
# OpenMetrics/Prometheus-compatible endpoints
self.assets.extend(self._get_open_metrics_assets())
# static system info, both hardware and software
self.system_info: SystemInfo = SystemInfo(
settings=self.settings, interface=interface
) | python | wandb/sdk/internal/system/system_monitor.py | 41 | 88 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,622 | _get_assets | def _get_assets(self) -> List["Asset"]:
return [
asset_class(
interface=self.asset_interface or self.backend_interface,
settings=self.settings,
shutdown_event=self._shutdown_event,
)
for asset_class in asset_registry
] | python | wandb/sdk/internal/system/system_monitor.py | 90 | 98 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,623 | _get_open_metrics_assets | def _get_open_metrics_assets(self) -> List["Asset"]:
open_metrics_endpoints = self.settings._stats_open_metrics_endpoints
if not open_metrics_endpoints:
return []
assets: List[Asset] = []
for name, endpoint in open_metrics_endpoints.items():
if not OpenMetrics.is_available(url=endpoint):
continue
logger.debug(f"Monitoring OpenMetrics endpoint: {endpoint}")
open_metrics = OpenMetrics(
interface=self.asset_interface or self.backend_interface,
settings=self.settings,
shutdown_event=self._shutdown_event,
name=name,
url=endpoint,
)
assets.append(open_metrics) # type: ignore
return assets | python | wandb/sdk/internal/system/system_monitor.py | 100 | 119 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,624 | aggregate_and_publish_asset_metrics | def aggregate_and_publish_asset_metrics(self) -> None:
if self.asset_interface is None:
return None
# only extract as many items as are available in the queue at the moment
size = self.asset_interface.metrics_queue.qsize()
aggregated_metrics = {}
for _ in range(size):
item = self.asset_interface.metrics_queue.get()
aggregated_metrics.update(item)
if aggregated_metrics:
self.backend_interface.publish_stats(aggregated_metrics) | python | wandb/sdk/internal/system/system_monitor.py | 121 | 133 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,625 | publish_telemetry | def publish_telemetry(self) -> None:
if self.asset_interface is None:
return None
# get everything from the self.asset_interface.telemetry_queue,
# merge into a single dictionary and publish on the backend_interface
while not self.asset_interface.telemetry_queue.empty():
telemetry_record = self.asset_interface.telemetry_queue.get()
self.backend_interface._publish_telemetry(telemetry_record) | python | wandb/sdk/internal/system/system_monitor.py | 135 | 142 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,626 | _start | def _start(self) -> None:
logger.info("Starting system asset monitoring threads")
for asset in self.assets:
asset.start()
# compatibility mode: join stats from different assets before publishing
if not (self.join_assets and self.asset_interface is not None):
return None
# give the assets a chance to accumulate and publish their first stats
# this will provide a constant offset for the following accumulation events below
self._shutdown_event.wait(
self.publishing_interval * self.PUBLISHING_INTERVAL_DELAY_FACTOR
)
logger.debug("Starting system metrics aggregation loop")
while not self._shutdown_event.is_set():
self.publish_telemetry()
self.aggregate_and_publish_asset_metrics()
self._shutdown_event.wait(self.publishing_interval)
logger.debug("Finished system metrics aggregation loop")
# try to publish the last batch of metrics + telemetry
try:
logger.debug("Publishing last batch of metrics")
# publish telemetry
self.publish_telemetry()
self.aggregate_and_publish_asset_metrics()
except Exception as e:
logger.error(f"Error publishing last batch of metrics: {e}") | python | wandb/sdk/internal/system/system_monitor.py | 144 | 175 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,627 | start | def start(self) -> None:
self._shutdown_event.clear()
if self._process is not None:
return None
logger.info("Starting system monitor")
self._process = threading.Thread(
target=self._start, daemon=True, name="SystemMonitor"
)
self._process.start() | python | wandb/sdk/internal/system/system_monitor.py | 177 | 185 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,628 | finish | def finish(self) -> None:
if self._process is None:
return None
logger.info("Stopping system monitor")
self._shutdown_event.set()
for asset in self.assets:
asset.finish()
try:
self._process.join()
except Exception as e:
logger.error(f"Error joining system monitor process: {e}")
self._process = None | python | wandb/sdk/internal/system/system_monitor.py | 187 | 198 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,629 | probe | def probe(self, publish: bool = True) -> None:
logger.info("Collecting system info")
# collect static info about the hardware from registered assets
hardware_info: dict = {
k: v for d in [asset.probe() for asset in self.assets] for k, v in d.items()
}
# collect static info about the software environment
software_info: dict = self.system_info.probe()
# merge the two dictionaries
system_info = {**software_info, **hardware_info}
logger.debug(system_info)
logger.info("Finished collecting system info")
if publish:
logger.info("Publishing system info")
self.system_info.publish(system_info)
logger.info("Finished publishing system info") | python | wandb/sdk/internal/system/system_monitor.py | 200 | 216 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,630 | __init__ | def __init__(self, settings: SettingsStatic, interface: Interface) -> None:
logger.debug("System info init")
self.settings = settings
self.metadata_file_name = os.path.join(self.settings.files_dir, METADATA_FNAME)
self.backend_interface = interface
self.git = GitRepo(
root=self.settings.git_root,
remote=self.settings.git_remote, # type: ignore
remote_url=self.settings.git_remote_url,
commit=self.settings.git_commit,
)
# Location under "code" directory in files where program was saved.
self.saved_program: Optional[os.PathLike] = None
# Locations under files directory where diff patches were saved.
self.saved_patches: List[str] = []
logger.debug("System info init done") | python | wandb/sdk/internal/system/system_info.py | 30 | 46 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,631 | _save_pip | def _save_pip(self) -> None:
"""Save the current working set of pip packages to {REQUIREMENTS_FNAME}."""
logger.debug(
"Saving list of pip packages installed into the current environment"
)
try:
import pkg_resources
installed_packages = [d for d in iter(pkg_resources.working_set)]
installed_packages_list = sorted(
f"{i.key}=={i.version}" for i in installed_packages
)
with open(
os.path.join(self.settings.files_dir, REQUIREMENTS_FNAME), "w"
) as f:
f.write("\n".join(installed_packages_list))
except Exception as e:
logger.exception(f"Error saving pip packages: {e}")
logger.debug("Saving pip packages done") | python | wandb/sdk/internal/system/system_info.py | 49 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,632 | _save_conda | def _save_conda(self) -> None:
current_shell_is_conda = os.path.exists(os.path.join(sys.prefix, "conda-meta"))
if not current_shell_is_conda:
return None
logger.debug(
"Saving list of conda packages installed into the current environment"
)
try:
with open(
os.path.join(self.settings.files_dir, CONDA_ENVIRONMENTS_FNAME), "w"
) as f:
subprocess.call(
["conda", "env", "export"], stdout=f, stderr=subprocess.DEVNULL
)
except Exception as e:
logger.exception(f"Error saving conda packages: {e}")
logger.debug("Saving conda packages done") | python | wandb/sdk/internal/system/system_info.py | 69 | 86 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,633 | _save_code | def _save_code(self) -> None:
logger.debug("Saving code")
if self.settings.program_relpath is None:
logger.warning("unable to save code -- program entry not found")
return None
root: str = self.git.root or os.getcwd()
program_relative: str = self.settings.program_relpath
filesystem.mkdir_exists_ok(
os.path.join(
self.settings.files_dir, "code", os.path.dirname(program_relative)
)
)
program_absolute = os.path.join(root, program_relative)
if not os.path.exists(program_absolute):
logger.warning("unable to save code -- can't find %s" % program_absolute)
return None
saved_program = os.path.join(self.settings.files_dir, "code", program_relative)
self.saved_program = program_relative # type: ignore
if not os.path.exists(saved_program):
copyfile(program_absolute, saved_program)
logger.debug("Saving code done") | python | wandb/sdk/internal/system/system_info.py | 88 | 110 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,634 | _save_patches | def _save_patches(self) -> None:
"""Save the current state of this repository to one or more patches.
Makes one patch against HEAD and another one against the most recent
commit that occurs in an upstream branch. This way we can be robust
to history editing as long as the user never does "push -f" to break
history on an upstream branch.
Writes the first patch to <files_dir>/<DIFF_FNAME> and the second to
<files_dir>/upstream_diff_<commit_id>.patch.
"""
if not self.git.enabled:
return None
logger.debug("Saving git patches")
try:
root = self.git.root
diff_args = ["git", "diff"]
if self.git.has_submodule_diff:
diff_args.append("--submodule=diff")
if self.git.dirty:
patch_path = os.path.join(self.settings.files_dir, DIFF_FNAME)
with open(patch_path, "wb") as patch:
# we diff against HEAD to ensure we get changes in the index
subprocess.check_call(
diff_args + ["HEAD"], stdout=patch, cwd=root, timeout=5
)
self.saved_patches.append(
os.path.relpath(patch_path, start=self.settings.files_dir)
)
upstream_commit = self.git.get_upstream_fork_point() # type: ignore
if upstream_commit and upstream_commit != self.git.repo.head.commit:
sha = upstream_commit.hexsha
upstream_patch_path = os.path.join(
self.settings.files_dir, f"upstream_diff_{sha}.patch"
)
with open(upstream_patch_path, "wb") as upstream_patch:
subprocess.check_call(
diff_args + [sha], stdout=upstream_patch, cwd=root, timeout=5
)
self.saved_patches.append(
os.path.relpath(
upstream_patch_path, start=self.settings.files_dir
)
)
# TODO: A customer saw `ValueError: Reference at 'refs/remotes/origin/foo'
# does not exist` so we now catch ValueError. Catching this error feels
# too generic.
except (
ValueError,
subprocess.CalledProcessError,
subprocess.TimeoutExpired,
) as e:
logger.error("Error generating diff: %s" % e)
logger.debug("Saving git patches done") | python | wandb/sdk/internal/system/system_info.py | 112 | 169 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,635 | _probe_git | def _probe_git(self, data: Dict[str, Any]) -> Dict[str, Any]:
if self.settings.disable_git:
return data
# in case of manually passing the git repo info, `enabled` would be False,
# but we still want to save the git repo info
if not self.git.enabled and self.git.auto:
return data
logger.debug("Probing git")
data["git"] = {
"remote": self.git.remote_url,
"commit": self.git.last_commit,
}
data["email"] = self.git.email
data["root"] = self.git.root or data.get("root") or os.getcwd()
logger.debug("Probing git done")
return data | python | wandb/sdk/internal/system/system_info.py | 171 | 190 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,636 | probe | def probe(self) -> Dict[str, Any]:
"""Probe the system for information about the current environment."""
# todo: refactor this quality code 🤮🤮🤮🤮🤮
logger.debug("Probing system")
data: Dict[str, Any] = dict()
data["os"] = self.settings._os
data["python"] = self.settings._python
data["heartbeatAt"] = datetime.datetime.utcnow().isoformat()
data["startedAt"] = datetime.datetime.utcfromtimestamp(
self.settings._start_time
).isoformat()
data["docker"] = self.settings.docker
data["cuda"] = self.settings._cuda
data["args"] = self.settings._args
data["state"] = "running"
if self.settings.program is not None:
data["program"] = self.settings.program
if not self.settings.disable_code:
if self.settings.program_relpath is not None:
data["codePath"] = self.settings.program_relpath
elif self.settings._jupyter:
if self.settings.notebook_name:
data["program"] = self.settings.notebook_name
elif self.settings._jupyter_path:
if self.settings._jupyter_path.startswith("fileId="):
unescaped = unquote(self.settings._jupyter_path)
data["colab"] = (
"https://colab.research.google.com/notebook#" + unescaped
)
data["program"] = self.settings._jupyter_name
else:
data["program"] = self.settings._jupyter_path
data["root"] = self.settings._jupyter_root
# get the git repo info
data = self._probe_git(data)
if self.settings.anonymous != "true":
data["host"] = self.settings.host
data["username"] = self.settings.username
data["executable"] = sys.executable
else:
data.pop("email", None)
data.pop("root", None)
logger.debug("Probing system done")
return data | python | wandb/sdk/internal/system/system_info.py | 192 | 242 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,637 | publish | def publish(self, system_info: dict) -> None:
# save pip, conda, code patches to disk
if self.settings._save_requirements:
self._save_pip()
self._save_conda()
if self.settings.save_code:
self._save_code()
self._save_patches()
# save system_info to disk
with open(self.metadata_file_name, "w") as f:
s = json.dumps(system_info, indent=4)
f.write(s)
f.write("\n")
base_name = os.path.basename(self.metadata_file_name)
files = dict(files=[(base_name, "now")])
if self.saved_program:
saved_program = os.path.join("code", self.saved_program)
files["files"].append((glob.escape(saved_program), "now"))
for patch in self.saved_patches:
files["files"].append((glob.escape(patch), "now"))
# publish files to the backend
self.backend_interface.publish_files(files) # type: ignore | python | wandb/sdk/internal/system/system_info.py | 244 | 268 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,638 | sample | def sample(self) -> None:
"""Sample the metric."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 34 | 36 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,639 | clear | def clear(self) -> None:
"""Clear the samples."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 38 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,640 | aggregate | def aggregate(self) -> dict:
"""Aggregate the samples."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 42 | 44 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,641 | setup | def setup(self) -> None:
"""Extra setup required for the metric beyond __init__."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 51 | 53 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,642 | teardown | def teardown(self) -> None:
"""Extra teardown required for the metric."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 55 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,643 | __init__ | def __init__(self, *args: Any, **kwargs: Any) -> None:
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 71 | 72 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,644 | is_available | def is_available(cls) -> bool:
"""Check if the resource is available."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 75 | 77 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,645 | start | def start(self) -> None:
"""Start monitoring the resource."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 79 | 81 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,646 | finish | def finish(self) -> None:
"""Finish monitoring the resource."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 83 | 85 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,647 | probe | def probe(self) -> dict:
"""Get static information about the resource."""
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 87 | 89 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,648 | publish_stats | def publish_stats(self, stats: dict) -> None:
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 93 | 94 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,649 | _publish_telemetry | def _publish_telemetry(self, telemetry: "TelemetryRecord") -> None:
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 96 | 97 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,650 | publish_files | def publish_files(self, files_dict: "FilesDict") -> None:
... # pragma: no cover | python | wandb/sdk/internal/system/assets/interfaces.py | 99 | 100 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,651 | __init__ | def __init__(
self,
asset_name: str,
metrics: List[Metric],
interface: Interface,
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.metrics = metrics
self.asset_name = asset_name
self._interface = interface
self._process: Optional[threading.Thread] = None
self._shutdown_event: threading.Event = shutdown_event
self.sampling_interval: float = float(
max(
0.1,
settings._stats_sample_rate_seconds,
)
) # seconds
# The number of samples to aggregate (e.g. average or compute max/min etc.)
# before publishing; defaults to 15; valid range: [1:30]
self.samples_to_aggregate: int = min(
30, max(1, settings._stats_samples_to_average)
) | python | wandb/sdk/internal/system/assets/interfaces.py | 106 | 130 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,652 | monitor | def monitor(self) -> None:
"""Poll the Asset metrics."""
while not self._shutdown_event.is_set():
for _ in range(self.samples_to_aggregate):
for metric in self.metrics:
try:
metric.sample()
except psutil.NoSuchProcess:
logger.info(f"Process {metric.name} has exited.")
self._shutdown_event.set()
break
except Exception as e:
logger.error(f"Failed to sample metric: {e}")
self._shutdown_event.wait(self.sampling_interval)
if self._shutdown_event.is_set():
break
self.publish() | python | wandb/sdk/internal/system/assets/interfaces.py | 132 | 148 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,653 | aggregate | def aggregate(self) -> dict:
"""Return a dict of metrics."""
aggregated_metrics = {}
for metric in self.metrics:
try:
serialized_metric = metric.aggregate()
aggregated_metrics.update(serialized_metric)
# aggregated_metrics = wandb.util.merge_dicts(
# aggregated_metrics, metric.serialize()
# )
except Exception as e:
logger.error(f"Failed to serialize metric: {e}")
return aggregated_metrics | python | wandb/sdk/internal/system/assets/interfaces.py | 150 | 162 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,654 | publish | def publish(self) -> None:
"""Publish the Asset metrics."""
try:
aggregated_metrics = self.aggregate()
if aggregated_metrics:
self._interface.publish_stats(aggregated_metrics)
for metric in self.metrics:
metric.clear()
except Exception as e:
logger.error(f"Failed to publish metrics: {e}") | python | wandb/sdk/internal/system/assets/interfaces.py | 164 | 173 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,655 | start | def start(self) -> None:
if (self._process is not None) or self._shutdown_event.is_set():
return None
thread_name = f"{self.asset_name[:15]}" # thread names are limited to 15 chars
try:
for metric in self.metrics:
if isinstance(metric, SetupTeardown):
metric.setup()
self._process = threading.Thread(
target=self.monitor,
daemon=True,
name=thread_name,
)
self._process.start()
logger.info(f"Started {thread_name} monitoring")
except Exception as e:
logger.warning(f"Failed to start {thread_name} monitoring: {e}")
self._process = None | python | wandb/sdk/internal/system/assets/interfaces.py | 175 | 193 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,656 | finish | def finish(self) -> None:
if self._process is None:
return None
thread_name = f"{self.asset_name[:15]}"
try:
self._process.join()
logger.info(f"Joined {thread_name} monitor")
for metric in self.metrics:
if isinstance(metric, SetupTeardown):
metric.teardown()
except Exception as e:
logger.warning(f"Failed to finish {thread_name} monitoring: {e}")
finally:
self._process = None | python | wandb/sdk/internal/system/assets/interfaces.py | 195 | 209 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,657 | __init__ | def __init__(self) -> None:
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/disk.py | 27 | 28 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,658 | sample | def sample(self) -> None:
self.samples.append(psutil.disk_usage("/").percent) | python | wandb/sdk/internal/system/assets/disk.py | 30 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,659 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/disk.py | 33 | 34 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,660 | 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/disk.py | 36 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,661 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [DiskUsage()]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/disk.py | 45 | 59 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,662 | 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/disk.py | 62 | 64 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,663 | probe | def probe(self) -> dict:
# total disk space:
total = psutil.disk_usage("/").total / 1024 / 1024 / 1024
# total disk space used:
used = psutil.disk_usage("/").used / 1024 / 1024 / 1024
return {self.name: {"total": total, "used": used}} | python | wandb/sdk/internal/system/assets/disk.py | 66 | 71 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,664 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/disk.py | 73 | 74 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,665 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/disk.py | 76 | 77 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,666 | __init__ | def __init__(self, pid: int, gc_ipu_info: Optional[Any] = None) -> None:
self.samples: "Deque[dict]" = deque()
if gc_ipu_info is None:
if not gcipuinfo:
raise ImportError(
"Monitoring IPU stats requires gcipuinfo to be installed"
)
self._gc_ipu_info = gcipuinfo.gcipuinfo()
else:
self._gc_ipu_info = gc_ipu_info
self._gc_ipu_info.setUpdateMode(True)
self._pid = pid
self._devices_called: Set[str] = set() | python | wandb/sdk/internal/system/assets/ipu.py | 40 | 55 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,667 | parse_metric | def parse_metric(key: str, value: str) -> Optional[Tuple[str, Union[int, float]]]:
metric_suffixes = {
"temp": "C",
"clock": "MHz",
"power": "W",
"utilisation": "%",
"utilisation (session)": "%",
"speed": "GT/s",
}
for metric, suffix in metric_suffixes.items():
if key.endswith(metric) and value.endswith(suffix):
value = value[: -len(suffix)]
key = f"{key} ({suffix})"
try:
float_value = float(value)
num_value = int(float_value) if float_value.is_integer() else float_value
except ValueError:
return None
return key, num_value | python | wandb/sdk/internal/system/assets/ipu.py | 58 | 79 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,668 | sample | def sample(self) -> None:
try:
stats = {}
devices = self._gc_ipu_info.getDevices()
for device in devices:
device_metrics: Dict[str, str] = dict(device)
pid = device_metrics.get("user process id")
if pid is None or int(pid) != self._pid:
continue
device_id = device_metrics.get("id")
initial_call = device_id not in self._devices_called
if device_id is not None:
self._devices_called.add(device_id)
for key, value in device_metrics.items():
log_metric = initial_call or key in self.variable_metric_keys
if not log_metric:
continue
parsed = self.parse_metric(key, value)
if parsed is None:
continue
parsed_key, parsed_value = parsed
stats[self.name.format(device_id, parsed_key)] = parsed_value
self.samples.append(stats)
except Exception as e:
wandb.termwarn(f"IPU stats error {e}", repeat=False) | python | wandb/sdk/internal/system/assets/ipu.py | 81 | 111 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,669 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/ipu.py | 113 | 114 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,670 | 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 if key in s]
aggregate = aggregate_mean(samples)
stats[key] = aggregate
return stats | python | wandb/sdk/internal/system/assets/ipu.py | 116 | 124 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,671 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
IPUStats(settings._stats_pid),
]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/ipu.py | 129 | 145 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,672 | is_available | def is_available(cls) -> bool:
return gcipuinfo is not None | python | wandb/sdk/internal/system/assets/ipu.py | 148 | 149 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,673 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/ipu.py | 151 | 152 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,674 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/ipu.py | 154 | 155 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,675 | probe | def probe(self) -> dict:
device_data = self.metrics[0]._gc_ipu_info.getDevices() # type: ignore
device_count = len(device_data)
devices = []
for i, device in enumerate(device_data):
device_metrics: Dict[str, str] = dict(device)
devices.append(
{
"id": device_metrics.get("id") or i,
"board ipu index": device_metrics.get("board ipu index"),
"board type": device_metrics.get("board type") or "unknown",
}
)
return {
self.name: {
"device_count": device_count,
"devices": devices,
"vendor": "Graphcore",
}
} | python | wandb/sdk/internal/system/assets/ipu.py | 157 | 177 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,676 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.process: Optional[psutil.Process] = None
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/memory.py | 30 | 33 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,677 | sample | def sample(self) -> None:
if self.process is None:
self.process = psutil.Process(self.pid)
self.samples.append(self.process.memory_info().rss / 1024 / 1024) | python | wandb/sdk/internal/system/assets/memory.py | 35 | 39 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,678 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/memory.py | 41 | 42 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,679 | 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/memory.py | 44 | 48 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,680 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.process: Optional[psutil.Process] = None
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/memory.py | 58 | 61 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,681 | sample | def sample(self) -> None:
if self.process is None:
self.process = psutil.Process(self.pid)
self.samples.append(self.process.memory_percent()) | python | wandb/sdk/internal/system/assets/memory.py | 63 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,682 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/memory.py | 69 | 70 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,683 | 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/memory.py | 72 | 76 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,684 | __init__ | def __init__(self) -> None:
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/memory.py | 86 | 87 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,685 | sample | def sample(self) -> None:
self.samples.append(psutil.virtual_memory().percent) | python | wandb/sdk/internal/system/assets/memory.py | 89 | 90 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,686 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/memory.py | 92 | 93 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,687 | 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/memory.py | 95 | 99 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,688 | __init__ | def __init__(self) -> None:
self.samples = deque([]) | python | wandb/sdk/internal/system/assets/memory.py | 109 | 110 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,689 | sample | def sample(self) -> None:
self.samples.append(psutil.virtual_memory().available / 1024 / 1024) | python | wandb/sdk/internal/system/assets/memory.py | 112 | 113 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,690 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/memory.py | 115 | 116 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,691 | 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/memory.py | 118 | 122 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,692 | __init__ | def __init__(
self,
interface: "Interface",
settings: "SettingsStatic",
shutdown_event: threading.Event,
) -> None:
self.name = self.__class__.__name__.lower()
self.metrics: List[Metric] = [
MemoryAvailable(),
MemoryPercent(),
ProcessMemoryRSS(settings._stats_pid),
ProcessMemoryPercent(settings._stats_pid),
]
self.metrics_monitor = MetricsMonitor(
self.name,
self.metrics,
interface,
settings,
shutdown_event,
) | python | wandb/sdk/internal/system/assets/memory.py | 127 | 146 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,693 | start | def start(self) -> None:
self.metrics_monitor.start() | python | wandb/sdk/internal/system/assets/memory.py | 148 | 149 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,694 | finish | def finish(self) -> None:
self.metrics_monitor.finish() | python | wandb/sdk/internal/system/assets/memory.py | 151 | 152 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,695 | 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/memory.py | 155 | 157 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,696 | probe | def probe(self) -> dict:
"""Return a dict of the hardware information."""
# total available memory in gigabytes
return {
"memory": {
"total": psutil.virtual_memory().total / 1024 / 1024 / 1024,
}
} | python | wandb/sdk/internal/system/assets/memory.py | 159 | 166 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,697 | __init__ | def __init__(self, pid: int) -> None:
self.pid = pid
self.samples: "Deque[float]" = deque([])
self.process: Optional[psutil.Process] = None | python | wandb/sdk/internal/system/assets/cpu.py | 28 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,698 | sample | def sample(self) -> None:
# todo: this is what we'd eventually want to do
# self.samples.append(
# (
# datetime.datetime.utcnow(),
# psutil.Process(self.pid).cpu_percent(),
# )
# )
if self.process is None:
self.process = psutil.Process(self.pid)
self.samples.append(self.process.cpu_percent() / psutil.cpu_count()) | python | wandb/sdk/internal/system/assets/cpu.py | 33 | 44 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,699 | clear | def clear(self) -> None:
self.samples.clear() | python | wandb/sdk/internal/system/assets/cpu.py | 46 | 47 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
4,700 | aggregate | def aggregate(self) -> dict:
# todo: create a statistics class with helper methods to compute
# mean, median, min, max, etc.
if not self.samples:
return {}
aggregate = aggregate_mean(self.samples)
return {self.name: aggregate} | python | wandb/sdk/internal/system/assets/cpu.py | 49 | 55 | {
"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.