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
1,101
__init__
def __init__( self, id=None, name=None, class_name=None, size=None, parameters=None, output_shape=None, is_output=None, num_parameters=None, node=None, ): self._attributes = {"name": None} self.in_edges = {} # indexed by source node id self.out_edges = {} # indexed by dest node id # optional object (e.g. PyTorch Parameter or Module) that this Node represents self.obj = None if node is not None: self._attributes.update(node._attributes) del self._attributes["id"] self.obj = node.obj if id is not None: self.id = id if name is not None: self.name = name if class_name is not None: self.class_name = class_name if size is not None: self.size = size if parameters is not None: self.parameters = parameters if output_shape is not None: self.output_shape = output_shape if is_output is not None: self.is_output = is_output if num_parameters is not None: self.num_parameters = num_parameters
python
wandb/data_types.py
1,553
1,591
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,102
to_json
def to_json(self, run=None): return self._attributes
python
wandb/data_types.py
1,593
1,594
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,103
__repr__
def __repr__(self): return repr(self._attributes)
python
wandb/data_types.py
1,596
1,597
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,104
id
def id(self): """Must be unique in the graph.""" return self._attributes.get("id")
python
wandb/data_types.py
1,600
1,602
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,105
id
def id(self, val): self._attributes["id"] = val return val
python
wandb/data_types.py
1,605
1,607
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,106
name
def name(self): """Usually the type of layer or sublayer.""" return self._attributes.get("name")
python
wandb/data_types.py
1,610
1,612
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,107
name
def name(self, val): self._attributes["name"] = val return val
python
wandb/data_types.py
1,615
1,617
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,108
class_name
def class_name(self): """Usually the type of layer or sublayer.""" return self._attributes.get("class_name")
python
wandb/data_types.py
1,620
1,622
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,109
class_name
def class_name(self, val): self._attributes["class_name"] = val return val
python
wandb/data_types.py
1,625
1,627
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,110
functions
def functions(self): return self._attributes.get("functions", [])
python
wandb/data_types.py
1,630
1,631
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,111
functions
def functions(self, val): self._attributes["functions"] = val return val
python
wandb/data_types.py
1,634
1,636
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,112
parameters
def parameters(self): return self._attributes.get("parameters", [])
python
wandb/data_types.py
1,639
1,640
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,113
parameters
def parameters(self, val): self._attributes["parameters"] = val return val
python
wandb/data_types.py
1,643
1,645
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,114
size
def size(self): return self._attributes.get("size")
python
wandb/data_types.py
1,648
1,649
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,115
size
def size(self, val): """Tensor size.""" self._attributes["size"] = tuple(val) return val
python
wandb/data_types.py
1,652
1,655
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,116
output_shape
def output_shape(self): return self._attributes.get("output_shape")
python
wandb/data_types.py
1,658
1,659
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,117
output_shape
def output_shape(self, val): """Tensor output_shape.""" self._attributes["output_shape"] = val return val
python
wandb/data_types.py
1,662
1,665
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,118
is_output
def is_output(self): return self._attributes.get("is_output")
python
wandb/data_types.py
1,668
1,669
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,119
is_output
def is_output(self, val): """Tensor is_output.""" self._attributes["is_output"] = val return val
python
wandb/data_types.py
1,672
1,675
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,120
num_parameters
def num_parameters(self): return self._attributes.get("num_parameters")
python
wandb/data_types.py
1,678
1,679
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,121
num_parameters
def num_parameters(self, val): """Tensor num_parameters.""" self._attributes["num_parameters"] = val return val
python
wandb/data_types.py
1,682
1,685
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,122
child_parameters
def child_parameters(self): return self._attributes.get("child_parameters")
python
wandb/data_types.py
1,688
1,689
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,123
child_parameters
def child_parameters(self, val): """Tensor child_parameters.""" self._attributes["child_parameters"] = val return val
python
wandb/data_types.py
1,692
1,695
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,124
is_constant
def is_constant(self): return self._attributes.get("is_constant")
python
wandb/data_types.py
1,698
1,699
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,125
is_constant
def is_constant(self, val): """Tensor is_constant.""" self._attributes["is_constant"] = val return val
python
wandb/data_types.py
1,702
1,705
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,126
from_keras
def from_keras(cls, layer): node = cls() try: output_shape = layer.output_shape except AttributeError: output_shape = ["multiple"] node.id = layer.name node.name = layer.name node.class_name = layer.__class__.__name__ node.output_shape = output_shape node.num_parameters = layer.count_params() return node
python
wandb/data_types.py
1,708
1,722
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,127
__init__
def __init__(self, from_node, to_node): self._attributes = {} self.from_node = from_node self.to_node = to_node
python
wandb/data_types.py
1,728
1,731
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,128
__repr__
def __repr__(self): temp_attr = dict(self._attributes) del temp_attr["from_node"] del temp_attr["to_node"] temp_attr["from_id"] = self.from_node.id temp_attr["to_id"] = self.to_node.id return str(temp_attr)
python
wandb/data_types.py
1,733
1,739
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,129
to_json
def to_json(self, run=None): return [self.from_node.id, self.to_node.id]
python
wandb/data_types.py
1,741
1,742
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,130
name
def name(self): """Optional, not necessarily unique.""" return self._attributes.get("name")
python
wandb/data_types.py
1,745
1,747
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,131
name
def name(self, val): self._attributes["name"] = val return val
python
wandb/data_types.py
1,750
1,752
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,132
from_node
def from_node(self): return self._attributes.get("from_node")
python
wandb/data_types.py
1,755
1,756
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,133
from_node
def from_node(self, val): self._attributes["from_node"] = val return val
python
wandb/data_types.py
1,759
1,761
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,134
to_node
def to_node(self): return self._attributes.get("to_node")
python
wandb/data_types.py
1,764
1,765
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,135
to_node
def to_node(self, val): self._attributes["to_node"] = val return val
python
wandb/data_types.py
1,768
1,770
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,136
__init__
def __init__( self, box_layers=None, box_score_keys=None, mask_layers=None, class_map=None, **kwargs, ): box_layers = box_layers or {} box_score_keys = box_score_keys or [] mask_layers = mask_layers or {} class_map = class_map or {} if isinstance(box_layers, _dtypes.ConstType): box_layers = box_layers._params["val"] if not isinstance(box_layers, dict): raise TypeError("box_layers must be a dict") else: box_layers = _dtypes.ConstType( {layer_key: set(box_layers[layer_key]) for layer_key in box_layers} ) if isinstance(mask_layers, _dtypes.ConstType): mask_layers = mask_layers._params["val"] if not isinstance(mask_layers, dict): raise TypeError("mask_layers must be a dict") else: mask_layers = _dtypes.ConstType( {layer_key: set(mask_layers[layer_key]) for layer_key in mask_layers} ) if isinstance(box_score_keys, _dtypes.ConstType): box_score_keys = box_score_keys._params["val"] if not isinstance(box_score_keys, list) and not isinstance(box_score_keys, set): raise TypeError("box_score_keys must be a list or a set") else: box_score_keys = _dtypes.ConstType(set(box_score_keys)) if isinstance(class_map, _dtypes.ConstType): class_map = class_map._params["val"] if not isinstance(class_map, dict): raise TypeError("class_map must be a dict") else: class_map = _dtypes.ConstType(class_map) self.params.update( { "box_layers": box_layers, "box_score_keys": box_score_keys, "mask_layers": mask_layers, "class_map": class_map, } )
python
wandb/data_types.py
1,779
1,831
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,137
assign_type
def assign_type(self, wb_type=None): if isinstance(wb_type, _ImageFileType): box_layers_self = self.params["box_layers"].params["val"] or {} box_score_keys_self = self.params["box_score_keys"].params["val"] or [] mask_layers_self = self.params["mask_layers"].params["val"] or {} class_map_self = self.params["class_map"].params["val"] or {} box_layers_other = wb_type.params["box_layers"].params["val"] or {} box_score_keys_other = wb_type.params["box_score_keys"].params["val"] or [] mask_layers_other = wb_type.params["mask_layers"].params["val"] or {} class_map_other = wb_type.params["class_map"].params["val"] or {} # Merge the class_ids from each set of box_layers box_layers = { str(key): set( list(box_layers_self.get(key, [])) + list(box_layers_other.get(key, [])) ) for key in set( list(box_layers_self.keys()) + list(box_layers_other.keys()) ) } # Merge the class_ids from each set of mask_layers mask_layers = { str(key): set( list(mask_layers_self.get(key, [])) + list(mask_layers_other.get(key, [])) ) for key in set( list(mask_layers_self.keys()) + list(mask_layers_other.keys()) ) } # Merge the box score keys box_score_keys = set(list(box_score_keys_self) + list(box_score_keys_other)) # Merge the class_map class_map = { str(key): class_map_self.get(key, class_map_other.get(key, None)) for key in set( list(class_map_self.keys()) + list(class_map_other.keys()) ) } return _ImageFileType(box_layers, box_score_keys, mask_layers, class_map) return _dtypes.InvalidType()
python
wandb/data_types.py
1,833
1,880
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,138
from_obj
def from_obj(cls, py_obj): if not isinstance(py_obj, Image): raise TypeError("py_obj must be a wandb.Image") else: if hasattr(py_obj, "_boxes") and py_obj._boxes: box_layers = { str(key): set(py_obj._boxes[key]._class_labels.keys()) for key in py_obj._boxes.keys() } box_score_keys = { key for val in py_obj._boxes.values() for box in val._val for key in box.get("scores", {}).keys() } else: box_layers = {} box_score_keys = set() if hasattr(py_obj, "_masks") and py_obj._masks: mask_layers = { str(key): set( py_obj._masks[key]._val["class_labels"].keys() if hasattr(py_obj._masks[key], "_val") else [] ) for key in py_obj._masks.keys() } else: mask_layers = {} if hasattr(py_obj, "_classes") and py_obj._classes: class_set = { str(item["id"]): item["name"] for item in py_obj._classes._class_set } else: class_set = {} return cls(box_layers, box_score_keys, mask_layers, class_set)
python
wandb/data_types.py
1,883
1,922
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,139
__init__
def __init__(self, column_types=None): if column_types is None: column_types = _dtypes.UnknownType() if isinstance(column_types, dict): column_types = _dtypes.TypedDictType(column_types) elif not ( isinstance(column_types, _dtypes.TypedDictType) or isinstance(column_types, _dtypes.UnknownType) ): raise TypeError("column_types must be a dict or TypedDictType") self.params.update({"column_types": column_types})
python
wandb/data_types.py
1,930
1,941
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,140
assign_type
def assign_type(self, wb_type=None): if isinstance(wb_type, _TableType): column_types = self.params["column_types"].assign_type( wb_type.params["column_types"] ) if not isinstance(column_types, _dtypes.InvalidType): return _TableType(column_types) return _dtypes.InvalidType()
python
wandb/data_types.py
1,943
1,951
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,141
from_obj
def from_obj(cls, py_obj): if not isinstance(py_obj, Table): raise TypeError("py_obj must be a wandb.Table") else: return cls(py_obj._column_types)
python
wandb/data_types.py
1,954
1,958
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,142
__init__
def __init__(self, table, col_name): assert isinstance(table, Table) assert isinstance(col_name, str) assert col_name in table.columns self.params.update({"table": table, "col_name": col_name})
python
wandb/data_types.py
1,966
1,970
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,143
assign_type
def assign_type(self, wb_type=None): if isinstance(wb_type, _dtypes.StringType): return self elif ( isinstance(wb_type, _ForeignKeyType) and id(self.params["table"]) == id(wb_type.params["table"]) and self.params["col_name"] == wb_type.params["col_name"] ): return self return _dtypes.InvalidType()
python
wandb/data_types.py
1,972
1,982
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,144
from_obj
def from_obj(cls, py_obj): if not isinstance(py_obj, _TableKey): raise TypeError("py_obj must be a _TableKey") else: return cls(py_obj._table, py_obj._col_name)
python
wandb/data_types.py
1,985
1,989
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,145
to_json
def to_json(self, artifact=None): res = super().to_json(artifact) if artifact is not None: table_name = f"media/tables/t_{runid.generate_id()}" entry = artifact.add(self.params["table"], table_name) res["params"]["table"] = entry.path else: raise AssertionError( "_ForeignKeyType does not support serialization without an artifact" ) return res
python
wandb/data_types.py
1,991
2,001
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,146
from_json
def from_json( cls, json_dict, artifact, ): table = None col_name = None if artifact is None: raise AssertionError( "_ForeignKeyType does not support deserialization without an artifact" ) else: table = artifact.get(json_dict["params"]["table"]) col_name = json_dict["params"]["col_name"] if table is None: raise AssertionError("Unable to deserialize referenced table") return cls(table, col_name)
python
wandb/data_types.py
2,004
2,022
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,147
__init__
def __init__(self, table): assert isinstance(table, Table) self.params.update({"table": table})
python
wandb/data_types.py
2,030
2,032
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,148
assign_type
def assign_type(self, wb_type=None): if isinstance(wb_type, _dtypes.NumberType): return self elif isinstance(wb_type, _ForeignIndexType) and id(self.params["table"]) == id( wb_type.params["table"] ): return self return _dtypes.InvalidType()
python
wandb/data_types.py
2,034
2,042
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,149
from_obj
def from_obj(cls, py_obj): if not isinstance(py_obj, _TableIndex): raise TypeError("py_obj must be a _TableIndex") else: return cls(py_obj._table)
python
wandb/data_types.py
2,045
2,049
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,150
to_json
def to_json(self, artifact=None): res = super().to_json(artifact) if artifact is not None: table_name = f"media/tables/t_{runid.generate_id()}" entry = artifact.add(self.params["table"], table_name) res["params"]["table"] = entry.path else: raise AssertionError( "_ForeignIndexType does not support serialization without an artifact" ) return res
python
wandb/data_types.py
2,051
2,061
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,151
from_json
def from_json( cls, json_dict, artifact, ): table = None if artifact is None: raise AssertionError( "_ForeignIndexType does not support deserialization without an artifact" ) else: table = artifact.get(json_dict["params"]["table"]) if table is None: raise AssertionError("Unable to deserialize referenced table") return cls(table)
python
wandb/data_types.py
2,064
2,080
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,152
assign_type
def assign_type(self, wb_type=None): if isinstance(wb_type, _dtypes.StringType) or isinstance( wb_type, _PrimaryKeyType ): return self return _dtypes.InvalidType()
python
wandb/data_types.py
2,087
2,092
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,153
from_obj
def from_obj(cls, py_obj): if not isinstance(py_obj, _TableKey): raise TypeError("py_obj must be a wandb.Table") else: return cls()
python
wandb/data_types.py
2,095
2,099
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,154
_id_generator
def _id_generator(size=10, chars=string.ascii_lowercase + string.digits): return "".join(random.choice(chars) for _ in range(size))
python
wandb/wandb_controller.py
85
86
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,155
__init__
def __init__(self, sweep_id_or_config=None, entity=None, project=None): # sweep id configured in constuctor self._sweep_id: Optional[str] = None # configured parameters # Configuration to be created self._create: Dict = {} # Custom search self._custom_search: Optional[ Callable[ [Union[dict, sweeps.SweepConfig], List[sweeps.SweepRun]], Optional[sweeps.SweepRun], ] ] = None # Custom stopping self._custom_stopping: Optional[ Callable[ [Union[dict, sweeps.SweepConfig], List[sweeps.SweepRun]], List[sweeps.SweepRun], ] ] = None # Program function (used for future jupyter support) self._program_function = None # The following are updated every sweep step # raw sweep object (dict of strings) self._sweep_obj = None # parsed sweep config (dict) self._sweep_config: Optional[Union[dict, sweeps.SweepConfig]] = None # sweep metric used to optimize (str or None) self._sweep_metric: Optional[str] = None # list of _Run objects self._sweep_runs: Optional[List[sweeps.SweepRun]] = None # dictionary mapping name of run to run object self._sweep_runs_map: Optional[Dict[str, sweeps.SweepRun]] = None # scheduler dict (read only from controller) - used as feedback from the server self._scheduler: Optional[Dict] = None # controller dict (write only from controller) - used to send commands to server self._controller: Optional[Dict] = None # keep track of controller dict from previous step self._controller_prev_step: Optional[Dict] = None # Internal # Keep track of whether the sweep has been started self._started: bool = False # indicate whether there is more to schedule self._done_scheduling: bool = False # indicate whether the sweep needs to be created self._defer_sweep_creation: bool = False # count of logged lines since last status self._logged: int = 0 # last status line printed self._laststatus: str = "" # keep track of logged actions for print_actions() self._log_actions: List[Tuple[str, str]] = [] # keep track of logged debug for print_debug() self._log_debug: List[str] = [] # all backend commands use internal api environ = os.environ if entity: env.set_entity(entity, env=environ) if project: env.set_project(project, env=environ) self._api = InternalApi(environ=environ) if isinstance(sweep_id_or_config, str): self._sweep_id = sweep_id_or_config elif isinstance(sweep_id_or_config, dict) or isinstance( sweep_id_or_config, sweeps.SweepConfig ): self._create = sweeps.SweepConfig(sweep_id_or_config) # check for custom search and or stopping functions for config_key, controller_attr in zip( ["method", "early_terminate"], ["_custom_search", "_custom_stopping"] ): if callable(config_key in self._create and self._create[config_key]): setattr(self, controller_attr, self._create[config_key]) self._create[config_key] = "custom" self._sweep_id = self.create(from_dict=True) elif sweep_id_or_config is None: self._defer_sweep_creation = True return else: raise ControllerError("Unhandled sweep controller type") sweep_obj = self._sweep_object_read_from_backend() if sweep_obj is None: raise ControllerError("Can not find sweep") self._sweep_obj = sweep_obj
python
wandb/wandb_controller.py
130
220
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,156
configure_search
def configure_search( self, search: Union[ str, Callable[ [Union[dict, sweeps.SweepConfig], List[sweeps.SweepRun]], Optional[sweeps.SweepRun], ], ], ): self._configure_check() if isinstance(search, str): self._create["method"] = search elif callable(search): self._create["method"] = "custom" self._custom_search = search else: raise ControllerError("Unhandled search type.")
python
wandb/wandb_controller.py
222
239
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,157
configure_stopping
def configure_stopping( self, stopping: Union[ str, Callable[ [Union[dict, sweeps.SweepConfig], List[sweeps.SweepRun]], List[sweeps.SweepRun], ], ], **kwargs, ): self._configure_check() if isinstance(stopping, str): self._create.setdefault("early_terminate", {}) self._create["early_terminate"]["type"] = stopping for k, v in kwargs.items(): self._create["early_terminate"][k] = v elif callable(stopping): self._custom_stopping = stopping(kwargs) self._create.setdefault("early_terminate", {}) self._create["early_terminate"]["type"] = "custom" else: raise ControllerError("Unhandled stopping type.")
python
wandb/wandb_controller.py
241
263
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,158
configure_metric
def configure_metric(self, metric, goal=None): self._configure_check() self._create.setdefault("metric", {}) self._create["metric"]["name"] = metric if goal: self._create["metric"]["goal"] = goal
python
wandb/wandb_controller.py
265
270
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,159
configure_program
def configure_program(self, program): self._configure_check() if isinstance(program, str): self._create["program"] = program elif callable(program): self._create["program"] = "__callable__" self._program_function = program raise ControllerError("Program functions are not supported yet") else: raise ControllerError("Unhandled sweep program type")
python
wandb/wandb_controller.py
272
281
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,160
configure_name
def configure_name(self, name): self._configure_check() self._create["name"] = name
python
wandb/wandb_controller.py
283
285
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,161
configure_description
def configure_description(self, description): self._configure_check() self._create["description"] = description
python
wandb/wandb_controller.py
287
289
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,162
configure_parameter
def configure_parameter( self, name, values=None, value=None, distribution=None, min=None, max=None, mu=None, sigma=None, q=None, a=None, b=None, ): self._configure_check() self._create.setdefault("parameters", {}).setdefault(name, {}) if value is not None or ( values is None and min is None and max is None and distribution is None ): self._create["parameters"][name]["value"] = value if values is not None: self._create["parameters"][name]["values"] = values if min is not None: self._create["parameters"][name]["min"] = min if max is not None: self._create["parameters"][name]["max"] = max if mu is not None: self._create["parameters"][name]["mu"] = mu if sigma is not None: self._create["parameters"][name]["sigma"] = sigma if q is not None: self._create["parameters"][name]["q"] = q if a is not None: self._create["parameters"][name]["a"] = a if b is not None: self._create["parameters"][name]["b"] = b
python
wandb/wandb_controller.py
291
326
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,163
configure_controller
def configure_controller(self, type): """Configure controller to local if type == 'local'.""" self._configure_check() self._create.setdefault("controller", {}) self._create["controller"].setdefault("type", type)
python
wandb/wandb_controller.py
328
332
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,164
configure
def configure(self, sweep_dict_or_config): self._configure_check() if self._create: raise ControllerError("Already configured.") if isinstance(sweep_dict_or_config, dict): self._create = sweep_dict_or_config elif isinstance(sweep_dict_or_config, str): self._create = yaml.safe_load(sweep_dict_or_config) else: raise ControllerError("Unhandled sweep controller type")
python
wandb/wandb_controller.py
334
343
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,165
sweep_config
def sweep_config(self) -> Union[dict, sweeps.SweepConfig]: return self._sweep_config
python
wandb/wandb_controller.py
346
347
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,166
sweep_id
def sweep_id(self) -> str: return self._sweep_id
python
wandb/wandb_controller.py
350
351
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,167
_log
def _log(self) -> None: self._logged += 1
python
wandb/wandb_controller.py
353
354
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,168
_error
def _error(self, s: str) -> None: print("ERROR:", s) self._log()
python
wandb/wandb_controller.py
356
358
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,169
_warn
def _warn(self, s: str) -> None: print("WARN:", s) self._log()
python
wandb/wandb_controller.py
360
362
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,170
_info
def _info(self, s: str) -> None: print("INFO:", s) self._log()
python
wandb/wandb_controller.py
364
366
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,171
_debug
def _debug(self, s: str) -> None: print("DEBUG:", s) self._log()
python
wandb/wandb_controller.py
368
370
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,172
_configure_check
def _configure_check(self) -> None: if self._started: raise ControllerError("Can not configure after sweep has been started.")
python
wandb/wandb_controller.py
372
374
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,173
_validate
def _validate(self, config: Dict) -> str: violations = sweeps.schema_violations_from_proposed_config(config) msg = ( sweep_config_err_text_from_jsonschema_violations(violations) if len(violations) > 0 else "" ) return msg
python
wandb/wandb_controller.py
376
383
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,174
create
def create(self, from_dict: bool = False) -> str: if self._started: raise ControllerError("Can not create after sweep has been started.") if not self._defer_sweep_creation and not from_dict: raise ControllerError("Can not use create on already created sweep.") if not self._create: raise ControllerError("Must configure sweep before create.") # validate sweep config self._create = sweeps.SweepConfig(self._create) # Create sweep sweep_id, warnings = self._api.upsert_sweep(self._create) handle_sweep_config_violations(warnings) print("Create sweep with ID:", sweep_id) sweep_url = wandb_sweep._get_sweep_url(self._api, sweep_id) if sweep_url: print("Sweep URL:", sweep_url) self._sweep_id = sweep_id self._defer_sweep_creation = False return sweep_id
python
wandb/wandb_controller.py
385
406
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,175
run
def run( self, verbose: bool = False, print_status: bool = True, print_actions: bool = False, print_debug: bool = False, ) -> None: if verbose: print_status = True print_actions = True print_debug = True self._start_if_not_started() while not self.done(): if print_status: self.print_status() self.step() if print_actions: self.print_actions() if print_debug: self.print_debug() time.sleep(5)
python
wandb/wandb_controller.py
408
428
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,176
_sweep_object_read_from_backend
def _sweep_object_read_from_backend(self) -> Optional[dict]: specs_json = {} if self._sweep_metric: k = ["_step"] k.append(self._sweep_metric) specs_json = {"keys": k, "samples": 100000} specs = json.dumps(specs_json) # TODO(jhr): catch exceptions? sweep_obj = self._api.sweep(self._sweep_id, specs) if not sweep_obj: return self._sweep_obj = sweep_obj self._sweep_config = yaml.safe_load(sweep_obj["config"]) self._sweep_metric = self._sweep_config.get("metric", {}).get("name") _sweep_runs: List[sweeps.SweepRun] = [] for r in sweep_obj["runs"]: rr = r.copy() if "summaryMetrics" in rr: if rr["summaryMetrics"]: rr["summaryMetrics"] = json.loads(rr["summaryMetrics"]) if "config" not in rr: raise ValueError("sweep object is missing config") rr["config"] = json.loads(rr["config"]) if "history" in rr: if isinstance(rr["history"], list): rr["history"] = [json.loads(d) for d in rr["history"]] else: raise ValueError( "Invalid history value: expected list of json strings: %s" % rr["history"] ) if "sampledHistory" in rr: sampled_history = [] for historyDictList in rr["sampledHistory"]: sampled_history += historyDictList rr["sampledHistory"] = sampled_history _sweep_runs.append(sweeps.SweepRun(**rr)) self._sweep_runs = _sweep_runs self._sweep_runs_map = {r.name: r for r in self._sweep_runs} self._controller = json.loads(sweep_obj.get("controller") or "{}") self._scheduler = json.loads(sweep_obj.get("scheduler") or "{}") self._controller_prev_step = self._controller.copy() return sweep_obj
python
wandb/wandb_controller.py
430
475
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,177
_sweep_object_sync_to_backend
def _sweep_object_sync_to_backend(self) -> None: if self._controller == self._controller_prev_step: return sweep_obj_id = self._sweep_obj["id"] controller = json.dumps(self._controller) _, warnings = self._api.upsert_sweep( self._sweep_config, controller=controller, obj_id=sweep_obj_id ) handle_sweep_config_violations(warnings) self._controller_prev_step = self._controller.copy()
python
wandb/wandb_controller.py
477
486
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,178
_start_if_not_started
def _start_if_not_started(self) -> None: if self._started: return if self._defer_sweep_creation: raise ControllerError( "Must specify or create a sweep before running controller." ) obj = self._sweep_object_read_from_backend() if not obj: return is_local = self._sweep_config.get("controller", {}).get("type") == "local" if not is_local: raise ControllerError( "Only sweeps with a local controller are currently supported." ) self._started = True # reset controller state, we might want to parse this and decide # what we can continue and add a version key, but for now we can # be safe and just reset things on start self._controller = {} self._sweep_object_sync_to_backend()
python
wandb/wandb_controller.py
488
508
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,179
_parse_scheduled
def _parse_scheduled(self): scheduled_list = self._scheduler.get("scheduled") or [] started_ids = [] stopped_runs = [] done_runs = [] for s in scheduled_list: runid = s.get("runid") objid = s.get("id") r = self._sweep_runs_map.get(runid) if not r: continue if r.stopped: stopped_runs.append(runid) summary = r.summary_metrics if r.state == SWEEP_INITIAL_RUN_STATE and not summary: continue started_ids.append(objid) if r.state != "running": done_runs.append(runid) return started_ids, stopped_runs, done_runs
python
wandb/wandb_controller.py
510
529
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,180
_step
def _step(self) -> None: self._start_if_not_started() self._sweep_object_read_from_backend() started_ids, stopped_runs, done_runs = self._parse_scheduled() # Remove schedule entry from controller dict if already scheduled schedule_list = self._controller.get("schedule", []) new_schedule_list = [s for s in schedule_list if s.get("id") not in started_ids] self._controller["schedule"] = new_schedule_list # Remove earlystop entry from controller if already stopped earlystop_list = self._controller.get("earlystop", []) new_earlystop_list = [ r for r in earlystop_list if r not in stopped_runs and r not in done_runs ] self._controller["earlystop"] = new_earlystop_list # Clear out step logs self._log_actions = [] self._log_debug = []
python
wandb/wandb_controller.py
531
551
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,181
step
def step(self) -> None: self._step() suggestion = self.search() self.schedule(suggestion) to_stop = self.stopping() if len(to_stop) > 0: self.stop_runs(to_stop)
python
wandb/wandb_controller.py
553
559
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,182
done
def done(self) -> bool: self._start_if_not_started() state = self._sweep_obj.get("state") if state in [ s.upper() for s in ( sweeps.RunState.preempting.value, SWEEP_INITIAL_RUN_STATE.value, sweeps.RunState.running.value, ) ]: return False return True
python
wandb/wandb_controller.py
561
573
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,183
_search
def _search(self) -> Optional[sweeps.SweepRun]: search = self._custom_search or sweeps.next_run next_run = search(self._sweep_config, self._sweep_runs or []) if next_run is None: self._done_scheduling = True return next_run
python
wandb/wandb_controller.py
575
580
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,184
search
def search(self) -> Optional[sweeps.SweepRun]: self._start_if_not_started() suggestion = self._search() return suggestion
python
wandb/wandb_controller.py
582
585
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,185
_stopping
def _stopping(self) -> List[sweeps.SweepRun]: if "early_terminate" not in self.sweep_config: return [] stopper = self._custom_stopping or sweeps.stop_runs stop_runs = stopper(self._sweep_config, self._sweep_runs or []) debug_lines = "\n".join( [ " ".join([f"{k}={v}" for k, v in run.early_terminate_info.items()]) for run in stop_runs if run.early_terminate_info is not None ] ) if debug_lines: self._log_debug += debug_lines return stop_runs
python
wandb/wandb_controller.py
587
603
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,186
stopping
def stopping(self) -> List[sweeps.SweepRun]: self._start_if_not_started() return self._stopping()
python
wandb/wandb_controller.py
605
607
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,187
schedule
def schedule(self, run: Optional[sweeps.SweepRun]) -> None: self._start_if_not_started() # only schedule one run at a time (for now) if self._controller and self._controller.get("schedule"): return schedule_id = _id_generator() if run is None: schedule_list = [{"id": schedule_id, "data": {"args": None}}] else: param_list = [ "{}={}".format(k, v.get("value")) for k, v in sorted(run.config.items()) ] self._log_actions.append(("schedule", ",".join(param_list))) # schedule one run schedule_list = [{"id": schedule_id, "data": {"args": run.config}}] self._controller["schedule"] = schedule_list self._sweep_object_sync_to_backend()
python
wandb/wandb_controller.py
609
630
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,188
stop_runs
def stop_runs(self, runs: List[sweeps.SweepRun]) -> None: earlystop_list = list({run.name for run in runs}) self._log_actions.append(("stop", ",".join(earlystop_list))) self._controller["earlystop"] = earlystop_list self._sweep_object_sync_to_backend()
python
wandb/wandb_controller.py
632
636
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,189
print_status
def print_status(self) -> None: status = _sweep_status(self._sweep_obj, self._sweep_config, self._sweep_runs) if self._laststatus != status or self._logged: print(status) self._laststatus = status self._logged = 0
python
wandb/wandb_controller.py
638
643
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,190
print_actions
def print_actions(self) -> None: for action, line in self._log_actions: self._info(f"{action.capitalize()} ({line})") self._log_actions = []
python
wandb/wandb_controller.py
645
648
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,191
print_debug
def print_debug(self) -> None: for line in self._log_debug: self._debug(line) self._log_debug = []
python
wandb/wandb_controller.py
650
653
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,192
print_space
def print_space(self) -> None: self._warn("Method not implemented yet.")
python
wandb/wandb_controller.py
655
656
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,193
print_summary
def print_summary(self) -> None: self._warn("Method not implemented yet.")
python
wandb/wandb_controller.py
658
659
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,194
_get_run_counts
def _get_run_counts(runs: List[sweeps.SweepRun]) -> Dict[str, int]: metrics = {} categories = [name for name, _ in sweeps.RunState.__members__.items()] + ["unknown"] for r in runs: state = r.state found = "unknown" for c in categories: if state == c: found = c break metrics.setdefault(found, 0) metrics[found] += 1 return metrics
python
wandb/wandb_controller.py
662
674
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,195
_get_runs_status
def _get_runs_status(metrics): categories = [name for name, _ in sweeps.RunState.__members__.items()] + ["unknown"] mlist = [] for c in categories: if not metrics.get(c): continue mlist.append("%s: %d" % (c.capitalize(), metrics[c])) s = ", ".join(mlist) return s
python
wandb/wandb_controller.py
677
685
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,196
_sweep_status
def _sweep_status( sweep_obj: dict, sweep_conf: Union[dict, sweeps.SweepConfig], sweep_runs: List[sweeps.SweepRun], ) -> str: sweep = sweep_obj["name"] _ = sweep_obj["state"] run_count = len(sweep_runs) run_type_counts = _get_run_counts(sweep_runs) stopped = len([r for r in sweep_runs if r.stopped]) stopping = len([r for r in sweep_runs if r.should_stop]) stopstr = "" if stopped or stopping: stopstr = "Stopped: %d" % stopped if stopping: stopstr += " (Stopping: %d)" % stopping runs_status = _get_runs_status(run_type_counts) method = sweep_conf.get("method", "unknown") stopping = sweep_conf.get("early_terminate", None) sweep_options = [] sweep_options.append(method) if stopping: sweep_options.append(stopping.get("type", "unknown")) sweep_options = ",".join(sweep_options) sections = [] sections.append(f"Sweep: {sweep} ({sweep_options})") if runs_status: sections.append("Runs: %d (%s)" % (run_count, runs_status)) else: sections.append("Runs: %d" % (run_count)) if stopstr: sections.append(stopstr) sections = " | ".join(sections) return sections
python
wandb/wandb_controller.py
688
721
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,197
nested_shape
def nested_shape(array_or_tuple, seen=None): """Figure out the shape of tensors possibly embedded in tuples i.e [0,0] returns (2) ([0,0], [0,0]) returns (2,2) (([0,0], [0,0]),[0,0]) returns ((2,2),2) """ if seen is None: seen = set() if hasattr(array_or_tuple, "size"): # pytorch tensors use V.size() to get size of tensor return list(array_or_tuple.size()) elif hasattr(array_or_tuple, "get_shape"): # tensorflow uses V.get_shape() to get size of tensor return array_or_tuple.get_shape().as_list() elif hasattr(array_or_tuple, "shape"): return array_or_tuple.shape seen.add(id(array_or_tuple)) try: # treat object as iterable return [ nested_shape(item, seen) if id(item) not in seen else 0 for item in list(array_or_tuple) ] except TypeError: # object is not actually iterable # LB: Maybe we should throw an error? return []
python
wandb/wandb_torch.py
18
46
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,198
log_track_init
def log_track_init(log_freq: int) -> List[int]: """create tracking structure used by log_track_update""" l = [0] * 2 l[LOG_TRACK_THRESHOLD] = log_freq return l
python
wandb/wandb_torch.py
52
56
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,199
log_track_update
def log_track_update(log_track: int) -> bool: """count (log_track[0]) up to threshold (log_track[1]), reset count (log_track[0]) and return true when reached""" log_track[LOG_TRACK_COUNT] += 1 if log_track[LOG_TRACK_COUNT] < log_track[LOG_TRACK_THRESHOLD]: return False log_track[LOG_TRACK_COUNT] = 0 return True
python
wandb/wandb_torch.py
59
65
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
1,200
__init__
def __init__(self): global torch torch = wandb.util.get_module("torch", "Could not import torch") self._hook_handles = {} self._num_bins = 64 self._is_cuda_histc_supported = None self.hook_torch = TorchGraph.hook_torch
python
wandb/wandb_torch.py
71
77
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }