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
5,101
dict_from_proto_list
def dict_from_proto_list(obj_list: "RepeatedCompositeFieldContainer") -> Dict[str, Any]: return {item.key: json.loads(item.value_json) for item in obj_list}
python
wandb/sdk/lib/proto_util.py
19
20
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,102
_result_from_record
def _result_from_record(record: "pb.Record") -> "pb.Result": result = pb.Result(uuid=record.uuid, control=record.control) return result
python
wandb/sdk/lib/proto_util.py
23
25
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,103
_assign_record_num
def _assign_record_num(record: "pb.Record", record_num: int) -> None: record.num = record_num
python
wandb/sdk/lib/proto_util.py
28
29
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,104
_assign_end_offset
def _assign_end_offset(record: "pb.Record", end_offset: int) -> None: record.control.end_offset = end_offset
python
wandb/sdk/lib/proto_util.py
32
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,105
proto_encode_to_dict
def proto_encode_to_dict( pb_obj: Union["tpb.TelemetryRecord", "pb.MetricRecord"] ) -> Dict[int, Any]: data: Dict[int, Any] = dict() fields = pb_obj.ListFields() for desc, value in fields: if desc.name.startswith("_"): continue if desc.type == desc.TYPE_STRING: data[desc.number] = value elif desc.type == desc.TYPE_INT32: data[desc.number] = value elif desc.type == desc.TYPE_ENUM: data[desc.number] = value elif desc.type == desc.TYPE_MESSAGE: nested = value.ListFields() bool_msg = all(d.type == d.TYPE_BOOL for d, _ in nested) if bool_msg: items = [d.number for d, v in nested if v] if items: data[desc.number] = items else: # TODO: for now this code only handles sub-messages with strings md = {} for d, v in nested: if not v or d.type != d.TYPE_STRING: continue md[d.number] = v data[desc.number] = md return data
python
wandb/sdk/lib/proto_util.py
36
65
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,106
settings_dict_from_pbmap
def settings_dict_from_pbmap( pbmap: "MessageMap[str, spb.SettingsValue]", ) -> Dict[str, Any]: d: Dict[str, Any] = dict() for k in pbmap: v_obj = pbmap[k] v_type = v_obj.WhichOneof("value_type") v: Union[int, str, float, None, tuple, dict, datetime] = None if v_type == "int_value": v = v_obj.int_value elif v_type == "string_value": v = v_obj.string_value elif v_type == "float_value": v = v_obj.float_value elif v_type == "bool_value": v = v_obj.bool_value elif v_type == "null_value": v = None elif v_type == "tuple_value": v = tuple(v_obj.tuple_value.string_values) elif v_type == "map_value": v = dict(v_obj.map_value.map_values) elif v_type == "nested_map_value": v = { k: dict(vv.map_values) for k, vv in dict(v_obj.nested_map_value.nested_map_values).items() } elif v_type == "timestamp_value": v = datetime.strptime(v_obj.timestamp_value, "%Y%m%d_%H%M%S") d[k] = v return d
python
wandb/sdk/lib/proto_util.py
68
99
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,107
message_to_dict
def message_to_dict( message: "Message", ) -> Dict[str, Any]: """Convert a protobuf message into a dictionary.""" from google.protobuf.json_format import MessageToDict return MessageToDict(message, preserving_proto_field_name=True)
python
wandb/sdk/lib/proto_util.py
102
108
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,108
toggle_button
def toggle_button(what="run"): return f"<button onClick=\"this.nextSibling.style.display='block';this.style.display='none';\">Display W&B {what}</button>"
python
wandb/sdk/lib/ipython.py
19
20
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,109
_get_python_type
def _get_python_type(): try: from IPython import get_ipython # type: ignore # Calling get_ipython can cause an ImportError if get_ipython() is None: return "python" except ImportError: return "python" if "terminal" in get_ipython().__module__ or "spyder" in sys.modules: return "ipython" else: return "jupyter"
python
wandb/sdk/lib/ipython.py
23
35
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,110
in_jupyter
def in_jupyter() -> bool: return _get_python_type() == "jupyter"
python
wandb/sdk/lib/ipython.py
38
39
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,111
display_html
def display_html(html: str): # type: ignore """Display HTML in notebooks, is a noop outside of a jupyter context.""" if wandb.run and wandb.run._settings.silent: return try: from IPython.core.display import HTML, display # type: ignore except ImportError: wandb.termwarn("Unable to render HTML, can't import display from ipython.core") return False return display(HTML(html))
python
wandb/sdk/lib/ipython.py
42
51
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,112
display_widget
def display_widget(widget): """Display ipywidgets in notebooks, is a noop outside of a jupyter context.""" if wandb.run and wandb.run._settings.silent: return try: from IPython.core.display import display except ImportError: wandb.termwarn( "Unable to render Widget, can't import display from ipython.core" ) return False return display(widget)
python
wandb/sdk/lib/ipython.py
54
65
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,113
__init__
def __init__(self, widgets, min, max): self.widgets = widgets self._progress = widgets.FloatProgress(min=min, max=max) self._label = widgets.Label() self._widget = self.widgets.VBox([self._label, self._progress]) self._displayed = False self._disabled = False
python
wandb/sdk/lib/ipython.py
71
77
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,114
update
def update(self, value: float, label: str) -> None: if self._disabled: return try: self._progress.value = value self._label.value = label if not self._displayed: self._displayed = True display_widget(self._widget) except Exception as e: self._disabled = True logger.exception(e) wandb.termwarn( "Unable to render progress bar, see the user log for details" )
python
wandb/sdk/lib/ipython.py
79
93
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,115
close
def close(self) -> None: if self._disabled or not self._displayed: return self._widget.close()
python
wandb/sdk/lib/ipython.py
95
98
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,116
jupyter_progress_bar
def jupyter_progress_bar(min: float = 0, max: float = 1.0) -> Optional[ProgressWidget]: """Return an ipywidget progress bar or None if we can't import it.""" widgets = wandb.util.get_module("ipywidgets") try: if widgets is None: # TODO: this currently works in iPython but it's deprecated since 4.0 with warnings.catch_warnings(): warnings.simplefilter("ignore") from IPython.html import widgets # type: ignore assert hasattr(widgets, "VBox") assert hasattr(widgets, "Label") assert hasattr(widgets, "FloatProgress") return ProgressWidget(widgets, min=min, max=max) except (ImportError, AssertionError): return None
python
wandb/sdk/lib/ipython.py
101
116
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,117
get_args
def get_args(obj: Any) -> Optional[Any]: return obj.__args__ if hasattr(obj, "__args__") else None
python
wandb/sdk/lib/_settings_toposort_generate.py
14
15
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,118
get_origin
def get_origin(obj: Any) -> Optional[Any]: return obj.__origin__ if hasattr(obj, "__origin__") else None
python
wandb/sdk/lib/_settings_toposort_generate.py
17
18
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,119
get_type_hints
def get_type_hints(obj: Any) -> Dict[str, Any]: return dict(obj.__annotations__) if hasattr(obj, "__annotations__") else dict()
python
wandb/sdk/lib/_settings_toposort_generate.py
20
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,120
__init__
def __init__(self) -> None: self.adj_list: Dict[str, Set[str]] = {}
python
wandb/sdk/lib/_settings_toposort_generate.py
51
52
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,121
add_node
def add_node(self, node: str) -> None: if node not in self.adj_list: self.adj_list[node] = set()
python
wandb/sdk/lib/_settings_toposort_generate.py
54
56
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,122
add_edge
def add_edge(self, node1: str, node2: str) -> None: self.adj_list[node1].add(node2)
python
wandb/sdk/lib/_settings_toposort_generate.py
58
59
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,123
get_neighbors
def get_neighbors(self, node: str) -> Set[str]: return self.adj_list[node]
python
wandb/sdk/lib/_settings_toposort_generate.py
61
62
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,124
topological_sort_dfs
def topological_sort_dfs(self) -> List[str]: sorted_copy = {k: sorted(v) for k, v in self.adj_list.items()} sorted_nodes: List[str] = [] visited_nodes: Set[str] = set() current_nodes: Set[str] = set() def visit(n: str) -> None: if n in visited_nodes: return None if n in current_nodes: raise UsageError("Cyclic dependency detected in wandb.Settings") current_nodes.add(n) for neighbor in sorted_copy[n]: visit(neighbor) current_nodes.remove(n) visited_nodes.add(n) sorted_nodes.append(n) return None for node in self.adj_list: if node not in visited_nodes: visit(node) return sorted_nodes
python
wandb/sdk/lib/_settings_toposort_generate.py
65
92
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,125
visit
def visit(n: str) -> None: if n in visited_nodes: return None if n in current_nodes: raise UsageError("Cyclic dependency detected in wandb.Settings") current_nodes.add(n) for neighbor in sorted_copy[n]: visit(neighbor) current_nodes.remove(n) visited_nodes.add(n) sorted_nodes.append(n) return None
python
wandb/sdk/lib/_settings_toposort_generate.py
72
86
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,126
_get_modification_order
def _get_modification_order( settings: Settings, ) -> Tuple[Tuple[str, ...], Tuple[str, ...]]: """Return the order in which settings should be modified, based on dependencies.""" dependency_graph = Graph() props = tuple(get_type_hints(Settings).keys()) # discover prop dependencies from validator methods and runtime hooks prefix = "_validate_" symbols = set(dir(settings)) validator_methods = tuple(sorted(m for m in symbols if m.startswith(prefix))) # extract dependencies from validator methods for m in validator_methods: setting = m.split(prefix)[1] dependency_graph.add_node(setting) # if the method is not static, inspect its code to find the attributes it depends on if ( not isinstance(Settings.__dict__[m], staticmethod) and not isinstance(Settings.__dict__[m], classmethod) and Settings.__dict__[m].__code__.co_argcount > 0 ): unbound_closure_vars = inspect.getclosurevars(Settings.__dict__[m]).unbound dependencies = (v for v in unbound_closure_vars if v in props) for d in dependencies: dependency_graph.add_node(d) dependency_graph.add_edge(setting, d) # extract dependencies from props' runtime hooks default_props = settings._default_props() for prop, spec in default_props.items(): if "hook" not in spec: continue dependency_graph.add_node(prop) hook = spec["hook"] if callable(hook): hook = [hook] for h in hook: unbound_closure_vars = inspect.getclosurevars(h).unbound dependencies = (v for v in unbound_closure_vars if v in props) for d in dependencies: dependency_graph.add_node(d) dependency_graph.add_edge(prop, d) modification_order = dependency_graph.topological_sort_dfs() return props, tuple(modification_order)
python
wandb/sdk/lib/_settings_toposort_generate.py
95
145
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,127
generate
def generate(settings: Settings) -> None: _settings_literal_list, _settings_topologically_sorted = _get_modification_order( settings ) settings_literal_list = ", ".join(f'"{s}"' for s in _settings_literal_list) settings_topologically_sorted = ", ".join( f'"{s}"' for s in _settings_topologically_sorted ) print( template.replace("$settings_literal_list", settings_literal_list,).replace( "$settings_topologically_sorted", settings_topologically_sorted, ) )
python
wandb/sdk/lib/_settings_toposort_generate.py
148
162
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,128
_generate_address
def _generate_address(length: int = 12) -> str: address = "".join( secrets.choice(string.ascii_lowercase + string.digits) for i in range(length) ) return address
python
wandb/sdk/lib/mailbox.py
16
20
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,129
__init__
def __init__(self) -> None: self._event = threading.Event() self._lock = threading.Lock() self._handles = [] self._failed_handles = 0
python
wandb/sdk/lib/mailbox.py
41
45
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,130
notify
def notify(self) -> None: with self._lock: self._event.set()
python
wandb/sdk/lib/mailbox.py
47
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,131
_add_handle
def _add_handle(self, handle: "MailboxHandle") -> None: handle._slot._set_wait_all(self) self._handles.append(handle) # set wait_all event if an event has already been set before added to wait_all if handle._slot._event.is_set(): self._event.set()
python
wandb/sdk/lib/mailbox.py
51
57
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,132
active_handles
def active_handles(self) -> List["MailboxHandle"]: return [h for h in self._handles if not h._is_failed]
python
wandb/sdk/lib/mailbox.py
60
61
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,133
active_handles_count
def active_handles_count(self) -> int: return len(self.active_handles)
python
wandb/sdk/lib/mailbox.py
64
65
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,134
failed_handles_count
def failed_handles_count(self) -> int: return self._failed_handles
python
wandb/sdk/lib/mailbox.py
68
69
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,135
_mark_handle_failed
def _mark_handle_failed(self, handle: "MailboxHandle") -> None: handle._mark_failed() self._failed_handles += 1
python
wandb/sdk/lib/mailbox.py
71
73
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,136
clear_handles
def clear_handles(self) -> None: for handle in self._handles: handle._slot._clear_wait_all() self._handles = []
python
wandb/sdk/lib/mailbox.py
75
78
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,137
_wait
def _wait(self, timeout: float) -> bool: return self._event.wait(timeout=timeout)
python
wandb/sdk/lib/mailbox.py
80
81
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,138
_get_and_clear
def _get_and_clear(self, timeout: float) -> List["MailboxHandle"]: found: List["MailboxHandle"] = [] if self._wait(timeout=timeout): with self._lock: remove_handles = [] # Look through handles for triggered events for handle in self._handles: if handle._slot._event.is_set(): found.append(handle) remove_handles.append(handle) for handle in remove_handles: self._handles.remove(handle) self._event.clear() return found
python
wandb/sdk/lib/mailbox.py
83
99
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,139
__init__
def __init__(self, address: str) -> None: self._result = None self._event = threading.Event() self._lock = threading.Lock() self._address = address self._wait_all = None self._abandoned = False
python
wandb/sdk/lib/mailbox.py
110
116
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,140
_set_wait_all
def _set_wait_all(self, wait_all: _MailboxWaitAll) -> None: assert not self._wait_all, "Only one caller can wait_all for a slot at a time" self._wait_all = wait_all
python
wandb/sdk/lib/mailbox.py
118
120
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,141
_clear_wait_all
def _clear_wait_all(self) -> None: self._wait_all = None
python
wandb/sdk/lib/mailbox.py
122
123
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,142
_wait
def _wait(self, timeout: float) -> bool: return self._event.wait(timeout=timeout)
python
wandb/sdk/lib/mailbox.py
125
126
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,143
_get_and_clear
def _get_and_clear(self, timeout: float) -> Tuple[Optional[pb.Result], bool]: found = None if self._wait(timeout=timeout): with self._lock: found = self._result self._event.clear() abandoned = self._abandoned return found, abandoned
python
wandb/sdk/lib/mailbox.py
128
135
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,144
_deliver
def _deliver(self, result: pb.Result) -> None: with self._lock: self._result = result self._event.set() if self._wait_all: self._wait_all.notify()
python
wandb/sdk/lib/mailbox.py
137
143
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,145
_notify_abandon
def _notify_abandon(self) -> None: self._abandoned = True with self._lock: self._event.set() if self._wait_all: self._wait_all.notify()
python
wandb/sdk/lib/mailbox.py
145
151
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,146
__init__
def __init__(self) -> None: self._handle = None self._result = None
python
wandb/sdk/lib/mailbox.py
158
160
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,147
set_probe_result
def set_probe_result(self, result: pb.Result) -> None: self._result = result
python
wandb/sdk/lib/mailbox.py
162
163
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,148
get_probe_result
def get_probe_result(self) -> Optional[pb.Result]: return self._result
python
wandb/sdk/lib/mailbox.py
165
166
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,149
get_mailbox_handle
def get_mailbox_handle(self) -> Optional["MailboxHandle"]: return self._handle
python
wandb/sdk/lib/mailbox.py
168
169
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,150
set_mailbox_handle
def set_mailbox_handle(self, handle: "MailboxHandle") -> None: self._handle = handle
python
wandb/sdk/lib/mailbox.py
171
172
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,151
__init__
def __init__(self, _handle: "MailboxHandle") -> None: self._handle = _handle self._percent_done = 0.0 self._probe_handles = [] self._stopped = False
python
wandb/sdk/lib/mailbox.py
181
185
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,152
percent_done
def percent_done(self) -> float: return self._percent_done
python
wandb/sdk/lib/mailbox.py
188
189
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,153
set_percent_done
def set_percent_done(self, percent_done: float) -> None: self._percent_done = percent_done
python
wandb/sdk/lib/mailbox.py
191
192
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,154
add_probe_handle
def add_probe_handle(self, probe_handle: MailboxProbe) -> None: self._probe_handles.append(probe_handle)
python
wandb/sdk/lib/mailbox.py
194
195
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,155
get_probe_handles
def get_probe_handles(self) -> List[MailboxProbe]: return self._probe_handles
python
wandb/sdk/lib/mailbox.py
197
198
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,156
wait_stop
def wait_stop(self) -> None: self._stopped = True
python
wandb/sdk/lib/mailbox.py
200
201
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,157
_is_stopped
def _is_stopped(self) -> bool: return self._stopped
python
wandb/sdk/lib/mailbox.py
204
205
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,158
__init__
def __init__(self) -> None: self._progress_handles = []
python
wandb/sdk/lib/mailbox.py
211
212
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,159
add_progress_handle
def add_progress_handle(self, progress_handle: MailboxProgress) -> None: self._progress_handles.append(progress_handle)
python
wandb/sdk/lib/mailbox.py
214
215
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,160
get_progress_handles
def get_progress_handles(self) -> List[MailboxProgress]: # only return progress handles for not failed handles return [ph for ph in self._progress_handles if not ph._handle._is_failed]
python
wandb/sdk/lib/mailbox.py
217
219
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,161
__init__
def __init__(self, mailbox: "Mailbox", slot: _MailboxSlot) -> None: self._mailbox = mailbox self._slot = slot self._on_probe = None self._on_progress = None self._interface = None self._keepalive = False self._failed = False
python
wandb/sdk/lib/mailbox.py
231
238
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,162
add_probe
def add_probe(self, on_probe: Callable[[MailboxProbe], None]) -> None: self._on_probe = on_probe
python
wandb/sdk/lib/mailbox.py
240
241
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,163
add_progress
def add_progress(self, on_progress: Callable[[MailboxProgress], None]) -> None: self._on_progress = on_progress
python
wandb/sdk/lib/mailbox.py
243
244
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,164
_time
def _time(self) -> float: return time.monotonic()
python
wandb/sdk/lib/mailbox.py
246
247
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,165
wait
def wait( # noqa: C901 self, *, timeout: float, on_probe: Optional[Callable[[MailboxProbe], None]] = None, on_progress: Optional[Callable[[MailboxProgress], None]] = None, release: bool = True, cancel: bool = False, ) -> Optional[pb.Result]: probe_handle: Optional[MailboxProbe] = None progress_handle: Optional[MailboxProgress] = None found: Optional[pb.Result] = None start_time = self._time() percent_done = 0.0 progress_sent = False wait_timeout = 1.0 if timeout >= 0: wait_timeout = min(timeout, wait_timeout) on_progress = on_progress or self._on_progress if on_progress: progress_handle = MailboxProgress(_handle=self) on_probe = on_probe or self._on_probe if on_probe: probe_handle = MailboxProbe() if progress_handle: progress_handle.add_probe_handle(probe_handle) while True: if self._keepalive and self._interface: if self._interface._transport_keepalive_failed(): raise MailboxError("transport failed") found, abandoned = self._slot._get_and_clear(timeout=wait_timeout) if found: # Always update progress to 100% when done if on_progress and progress_handle and progress_sent: progress_handle.set_percent_done(100) on_progress(progress_handle) break if abandoned: break now = self._time() if timeout >= 0: if now >= start_time + timeout: # todo: communicate that we timed out break if on_probe and probe_handle: on_probe(probe_handle) if on_progress and progress_handle: if timeout > 0: percent_done = min((now - start_time) / timeout, 1.0) progress_handle.set_percent_done(percent_done) on_progress(progress_handle) if progress_handle._is_stopped: break progress_sent = True if not found and cancel: self._cancel() if release: self._release() return found
python
wandb/sdk/lib/mailbox.py
249
311
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,166
_cancel
def _cancel(self) -> None: mailbox_slot = self.address if self._interface: self._interface.publish_cancel(mailbox_slot)
python
wandb/sdk/lib/mailbox.py
313
316
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,167
_release
def _release(self) -> None: self._mailbox._release_slot(self.address)
python
wandb/sdk/lib/mailbox.py
318
319
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,168
abandon
def abandon(self) -> None: self._slot._notify_abandon() self._release()
python
wandb/sdk/lib/mailbox.py
321
323
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,169
_is_failed
def _is_failed(self) -> bool: return self._failed
python
wandb/sdk/lib/mailbox.py
326
327
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,170
_mark_failed
def _mark_failed(self) -> None: self._failed = True
python
wandb/sdk/lib/mailbox.py
329
330
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,171
address
def address(self) -> str: return self._slot._address
python
wandb/sdk/lib/mailbox.py
333
334
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,172
__init__
def __init__(self) -> None: self._slots = {} self._keepalive = False
python
wandb/sdk/lib/mailbox.py
341
343
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,173
enable_keepalive
def enable_keepalive(self) -> None: self._keepalive = True
python
wandb/sdk/lib/mailbox.py
345
346
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,174
wait
def wait( self, handle: MailboxHandle, *, timeout: float, on_progress: Optional[Callable[[MailboxProgress], None]] = None, cancel: bool = False, ) -> Optional[pb.Result]: return handle.wait(timeout=timeout, on_progress=on_progress, cancel=cancel)
python
wandb/sdk/lib/mailbox.py
348
356
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,175
_time
def _time(self) -> float: return time.monotonic()
python
wandb/sdk/lib/mailbox.py
358
359
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,176
wait_all
def wait_all( self, handles: List[MailboxHandle], *, timeout: float, on_progress_all: Optional[Callable[[MailboxProgressAll], None]] = None, ) -> bool: progress_all_handle: Optional[MailboxProgressAll] = None if on_progress_all: progress_all_handle = MailboxProgressAll() wait_all = _MailboxWaitAll() for handle in handles: wait_all._add_handle(handle) if progress_all_handle and handle._on_progress: progress_handle = MailboxProgress(_handle=handle) if handle._on_probe: probe_handle = MailboxProbe() progress_handle.add_probe_handle(probe_handle) progress_all_handle.add_progress_handle(progress_handle) start_time = self._time() while wait_all.active_handles_count > 0: # Make sure underlying interfaces are still up if self._keepalive: for handle in wait_all.active_handles: if not handle._interface: continue if handle._interface._transport_keepalive_failed(): wait_all._mark_handle_failed(handle) # if there are no valid handles left, either break or raise exception if not wait_all.active_handles_count: if wait_all.failed_handles_count: wait_all.clear_handles() raise MailboxError("transport failed") break # wait for next event wait_all._get_and_clear(timeout=1) # TODO: we can do more careful timekeeping and not run probes and progress # indications until a full second elapses in the case where we found a wait_all # event. Extra probes should be ok for now. if progress_all_handle and on_progress_all: # Run all probe handles for progress_handle in progress_all_handle.get_progress_handles(): for probe_handle in progress_handle.get_probe_handles(): if ( progress_handle._handle and progress_handle._handle._on_probe ): progress_handle._handle._on_probe(probe_handle) on_progress_all(progress_all_handle) now = self._time() if timeout >= 0 and now >= start_time + timeout: break return wait_all.active_handles_count == 0
python
wandb/sdk/lib/mailbox.py
361
424
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,177
deliver
def deliver(self, result: pb.Result) -> None: mailbox = result.control.mailbox_slot slot = self._slots.get(mailbox) if not slot: return slot._deliver(result)
python
wandb/sdk/lib/mailbox.py
426
431
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,178
_allocate_slot
def _allocate_slot(self) -> _MailboxSlot: address = _generate_address() slot = _MailboxSlot(address=address) self._slots[address] = slot return slot
python
wandb/sdk/lib/mailbox.py
433
437
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,179
_release_slot
def _release_slot(self, address: str) -> None: self._slots.pop(address, None)
python
wandb/sdk/lib/mailbox.py
439
440
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,180
get_handle
def get_handle(self) -> MailboxHandle: slot = self._allocate_slot() handle = MailboxHandle(mailbox=self, slot=slot) return handle
python
wandb/sdk/lib/mailbox.py
442
445
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,181
_deliver_record
def _deliver_record( self, record: pb.Record, interface: "InterfaceShared" ) -> MailboxHandle: handle = self.get_handle() handle._interface = interface handle._keepalive = self._keepalive record.control.mailbox_slot = handle.address try: interface._publish(record) except Exception: interface._transport_mark_failed() raise interface._transport_mark_success() return handle
python
wandb/sdk/lib/mailbox.py
447
460
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,182
md5_string
def md5_string(string: str) -> B64MD5: return _b64_from_hasher(hashlib.md5(string.encode()))
python
wandb/sdk/lib/hashutil.py
11
12
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,183
_b64_from_hasher
def _b64_from_hasher(hasher: "hashlib._Hash") -> B64MD5: return B64MD5(base64.b64encode(hasher.digest()).decode("ascii"))
python
wandb/sdk/lib/hashutil.py
15
16
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,184
b64_to_hex_id
def b64_to_hex_id(string: B64MD5) -> HexMD5: return HexMD5(base64.standard_b64decode(string).hex())
python
wandb/sdk/lib/hashutil.py
19
20
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,185
hex_to_b64_id
def hex_to_b64_id(encoded_string: Union[str, bytes]) -> B64MD5: if isinstance(encoded_string, bytes): encoded_string = encoded_string.decode("utf-8") as_str = bytes.fromhex(encoded_string) return B64MD5(base64.standard_b64encode(as_str).decode("utf-8"))
python
wandb/sdk/lib/hashutil.py
23
27
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,186
md5_file_b64
def md5_file_b64(*paths: Union[str, PathLike]) -> B64MD5: return _b64_from_hasher(_md5_file_hasher(*paths))
python
wandb/sdk/lib/hashutil.py
30
31
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,187
md5_file_hex
def md5_file_hex(*paths: Union[str, PathLike]) -> HexMD5: return HexMD5(_md5_file_hasher(*paths).hexdigest())
python
wandb/sdk/lib/hashutil.py
34
35
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,188
_md5_file_hasher
def _md5_file_hasher(*paths: Union[str, PathLike]) -> "hashlib._Hash": md5_hash = hashlib.md5() for path in sorted(str(p) for p in paths): with open(path, "rb") as f: for chunk in iter(lambda: f.read(64 * 1024), b""): md5_hash.update(chunk) return md5_hash
python
wandb/sdk/lib/hashutil.py
38
44
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,189
set_global
def set_global( run=None, config=None, log=None, summary=None, save=None, use_artifact=None, log_artifact=None, define_metric=None, alert=None, plot_table=None, mark_preempting=None, ): if run: wandb.run = run if config is not None: wandb.config = config if log: wandb.log = log if summary is not None: wandb.summary = summary if save: wandb.save = save if use_artifact: wandb.use_artifact = use_artifact if log_artifact: wandb.log_artifact = log_artifact if define_metric: wandb.define_metric = define_metric if plot_table: wandb.plot_table = plot_table if alert: wandb.alert = alert if mark_preempting: wandb.mark_preempting = mark_preempting
python
wandb/sdk/lib/module.py
7
41
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,190
unset_globals
def unset_globals(): wandb.run = None wandb.config = preinit.PreInitObject("wandb.config") wandb.summary = preinit.PreInitObject("wandb.summary") wandb.log = preinit.PreInitCallable("wandb.log", wandb.wandb_sdk.wandb_run.Run.log) wandb.save = preinit.PreInitCallable( "wandb.save", wandb.wandb_sdk.wandb_run.Run.save ) wandb.use_artifact = preinit.PreInitCallable( "wandb.use_artifact", wandb.wandb_sdk.wandb_run.Run.use_artifact ) wandb.log_artifact = preinit.PreInitCallable( "wandb.log_artifact", wandb.wandb_sdk.wandb_run.Run.log_artifact ) wandb.define_metric = preinit.PreInitCallable( "wandb.define_metric", wandb.wandb_sdk.wandb_run.Run.define_metric )
python
wandb/sdk/lib/module.py
44
60
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,191
get_types
def get_types(): classes = map(data_types.__dict__.get, data_types.__all__) types = [] for cls in classes: if hasattr(cls, "_log_type") and cls._log_type is not None: types.append(cls._log_type) # add table-file type because this is a special case # that does not have a matching _log_type for artifacts # and files types.append("table-file") return types
python
wandb/sdk/lib/handler_util.py
4
14
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,192
metric_is_wandb_dict
def metric_is_wandb_dict(metric): return "_type" in list(metric.keys()) and metric["_type"] in WANDB_TYPES
python
wandb/sdk/lib/handler_util.py
20
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,193
__init__
def __init__( self, url: str, auth: Optional[Union[Tuple[str, str], Callable]] = None, use_json: bool = False, timeout: Optional[Union[int, float]] = None, **kwargs: Any, ) -> None: """Setup a session for sending GraphQL queries and mutations. Args: url (str): The GraphQL URL auth (tuple or callable): Auth tuple or callable for Basic/Digest/Custom HTTP Auth use_json (bool): Send request body as JSON instead of form-urlencoded timeout (int, float): Specifies a default timeout for requests (Default: None) """ super().__init__(url, **kwargs) self.session = requests.Session() self.session.auth = auth self.default_timeout = timeout self.use_json = use_json
python
wandb/sdk/lib/gql_request.py
17
37
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,194
execute
def execute( self, document: ast.Node, variable_values: Optional[Dict] = None, timeout: Optional[Union[int, float]] = None, ) -> ExecutionResult: query_str = print_ast(document) payload = {"query": query_str, "variables": variable_values or {}} data_key = "json" if self.use_json else "data" post_args = { "headers": self.headers, "cookies": self.cookies, "timeout": timeout or self.default_timeout, data_key: payload, } request = self.session.post(self.url, **post_args) request.raise_for_status() result = request.json() data, errors = result.get("data"), result.get("errors") if data is None and errors is None: raise RuntimeError(f"Received non-compatible response: {result}") return ExecutionResult(data=data, errors=errors)
python
wandb/sdk/lib/gql_request.py
39
62
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,195
dict_from_proto_list
def dict_from_proto_list(obj_list): d = dict() for item in obj_list: d[item.key] = dict(desc=None, value=json.loads(item.value_json)) return d
python
wandb/sdk/lib/config_util.py
21
25
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,196
update_from_proto
def update_from_proto(config_dict, config_proto): for item in config_proto.update: key_list = item.nested_key or (item.key,) assert key_list, "key or nested key must be set" target = config_dict # recurse down the dictionary structure: for prop in key_list[:-1]: if not target.get(prop): target[prop] = {} target = target[prop] # use the last element of the key to write the leaf: target[key_list[-1]] = json.loads(item.value_json) for item in config_proto.remove: key_list = item.nested_key or (item.key,) assert key_list, "key or nested key must be set" target = config_dict # recurse down the dictionary structure: for prop in key_list[:-1]: target = target[prop] # use the last element of the key to write the leaf: del target[key_list[-1]] # TODO(jhr): should we delete empty parents?
python
wandb/sdk/lib/config_util.py
28
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,197
dict_add_value_dict
def dict_add_value_dict(config_dict): d = dict() for k, v in config_dict.items(): d[k] = dict(desc=None, value=v) return d
python
wandb/sdk/lib/config_util.py
52
56
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,198
dict_strip_value_dict
def dict_strip_value_dict(config_dict): d = dict() for k, v in config_dict.items(): d[k] = v["value"] return d
python
wandb/sdk/lib/config_util.py
59
63
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,199
dict_no_value_from_proto_list
def dict_no_value_from_proto_list(obj_list): d = dict() for item in obj_list: possible_dict = json.loads(item.value_json) if not isinstance(possible_dict, dict) or "value" not in possible_dict: # (tss) TODO: This is protecting against legacy 'wandb_version' field. # Should investigate why the config payload even has 'wandb_version'. logger.warning(f"key {item.key!r} has no 'value' attribute") continue d[item.key] = possible_dict["value"] return d
python
wandb/sdk/lib/config_util.py
66
77
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,200
save_config_file_from_dict
def save_config_file_from_dict(config_filename, config_dict): s = b"wandb_version: 1" if config_dict: # adding an empty dictionary here causes a parse error s += b"\n\n" + yaml.dump( config_dict, Dumper=yaml.SafeDumper, default_flow_style=False, allow_unicode=True, encoding="utf-8", sort_keys=False, ) data = s.decode("utf-8") filesystem.mkdir_exists_ok(os.path.dirname(config_filename)) with open(config_filename, "w") as conf_file: conf_file.write(data)
python
wandb/sdk/lib/config_util.py
81
95
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }