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,401 | RunExit | def RunExit( # noqa: N802
self, exit_data: pb.RunExitRecord, context: grpc.ServicerContext
) -> pb.RunExitResult:
stream_id = exit_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface.publish_exit(exit_data.exit_code)
result = pb.RunExitResult()
return result | python | wandb/sdk/service/server_grpc.py | 127 | 134 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,402 | RunPreempting | def RunPreempting( # noqa: N802
self, preempt: pb.RunPreemptingRecord, context: grpc.ServicerContext
) -> pb.RunPreemptingResult:
stream_id = preempt._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_preempting(preempt)
result = pb.RunPreemptingResult()
return result | python | wandb/sdk/service/server_grpc.py | 136 | 143 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,403 | Artifact | def Artifact( # noqa: N802
self, art_data: pb.ArtifactRecord, context: grpc.ServicerContext
) -> pb.ArtifactResult:
stream_id = art_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_artifact(art_data)
result = pb.ArtifactResult()
return result | python | wandb/sdk/service/server_grpc.py | 145 | 152 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,404 | LinkArtifact | def LinkArtifact( # noqa: N802
self,
link_artifact: pb.LinkArtifactRecord,
context: grpc.ServicerContext,
) -> pb.LinkArtifactResult:
stream_id = link_artifact._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_link_artifact(link_artifact)
result = pb.LinkArtifactResult()
return result | python | wandb/sdk/service/server_grpc.py | 154 | 163 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,405 | UseArtifact | def UseArtifact( # noqa: N802
self, use_artifact: pb.UseArtifactRecord, context: grpc.ServicerContext
) -> pb.UseArtifactResult:
stream_id = use_artifact._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_use_artifact(use_artifact)
result = pb.UseArtifactResult()
return result | python | wandb/sdk/service/server_grpc.py | 165 | 172 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,406 | ArtifactSend | def ArtifactSend( # noqa: N802
self, art_send: pb.ArtifactSendRequest, context: grpc.ServicerContext
) -> pb.ArtifactSendResponse:
stream_id = art_send._info.stream_id
iface = self._mux.get_stream(stream_id).interface
resp = iface._communicate_artifact_send(art_send)
assert resp
return resp | python | wandb/sdk/service/server_grpc.py | 174 | 181 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,407 | ArtifactPoll | def ArtifactPoll( # noqa: N802
self, art_poll: pb.ArtifactPollRequest, context: grpc.ServicerContext
) -> pb.ArtifactPollResponse:
stream_id = art_poll._info.stream_id
iface = self._mux.get_stream(stream_id).interface
resp = iface._communicate_artifact_poll(art_poll)
assert resp
return resp | python | wandb/sdk/service/server_grpc.py | 183 | 190 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,408 | Cancel | def Cancel( # noqa: N802
self, cancel: pb.CancelRequest, context: grpc.ServicerContext
) -> pb.CancelResponse:
stream_id = cancel._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_cancel(cancel)
response = pb.CancelResponse()
return response | python | wandb/sdk/service/server_grpc.py | 192 | 199 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,409 | Keepalive | def Keepalive( # noqa: N802
self, keepalive: pb.KeepaliveRequest, context: grpc.ServicerContext
) -> pb.KeepaliveResponse:
stream_id = keepalive._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_keepalive(keepalive)
response = pb.KeepaliveResponse()
return response | python | wandb/sdk/service/server_grpc.py | 201 | 208 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,410 | TBSend | def TBSend( # noqa: N802
self, tb_data: pb.TBRecord, context: grpc.ServicerContext
) -> pb.TBResult:
stream_id = tb_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_tbdata(tb_data)
result = pb.TBResult()
return result | python | wandb/sdk/service/server_grpc.py | 210 | 217 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,411 | PartialLog | def PartialLog( # noqa: N802
self, partial_history: pb.PartialHistoryRequest, context: grpc.ServicerContext
) -> pb.PartialHistoryResponse:
stream_id = partial_history._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_partial_history(partial_history)
# make up a response even though this was async
result = pb.PartialHistoryResponse()
return result | python | wandb/sdk/service/server_grpc.py | 219 | 227 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,412 | Log | def Log( # noqa: N802
self, history: pb.HistoryRecord, context: grpc.ServicerContext
) -> pb.HistoryResult:
stream_id = history._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_history(history)
# make up a response even though this was async
result = pb.HistoryResult()
return result | python | wandb/sdk/service/server_grpc.py | 229 | 237 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,413 | Summary | def Summary( # noqa: N802
self, summary: pb.SummaryRecord, context: grpc.ServicerContext
) -> pb.SummaryResult:
stream_id = summary._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_summary(summary)
# make up a response even though this was async
result = pb.SummaryResult()
return result | python | wandb/sdk/service/server_grpc.py | 239 | 247 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,414 | Telemetry | def Telemetry( # noqa: N802
self, telem: tpb.TelemetryRecord, context: grpc.ServicerContext
) -> tpb.TelemetryResult:
stream_id = telem._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_telemetry(telem)
# make up a response even though this was async
result = tpb.TelemetryResult()
return result | python | wandb/sdk/service/server_grpc.py | 249 | 257 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,415 | Output | def Output( # noqa: N802
self, output_data: pb.OutputRecord, context: grpc.ServicerContext
) -> pb.OutputResult:
stream_id = output_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_output(output_data)
# make up a response even though this was async
result = pb.OutputResult()
return result | python | wandb/sdk/service/server_grpc.py | 259 | 267 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,416 | OutputRaw | def OutputRaw( # noqa: N802
self, output_data: pb.OutputRawRecord, context: grpc.ServicerContext
) -> pb.OutputRawResult:
stream_id = output_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_output_raw(output_data)
# make up a response even though this was async
result = pb.OutputRawResult()
return result | python | wandb/sdk/service/server_grpc.py | 269 | 277 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,417 | Files | def Files( # noqa: N802
self, files_data: pb.FilesRecord, context: grpc.ServicerContext
) -> pb.FilesResult:
stream_id = files_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_files(files_data)
# make up a response even though this was async
result = pb.FilesResult()
return result | python | wandb/sdk/service/server_grpc.py | 279 | 287 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,418 | Config | def Config( # noqa: N802
self, config_data: pb.ConfigRecord, context: grpc.ServicerContext
) -> pb.ConfigResult:
stream_id = config_data._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_config(config_data)
# make up a response even though this was async
result = pb.ConfigResult()
return result | python | wandb/sdk/service/server_grpc.py | 289 | 297 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,419 | Metric | def Metric( # noqa: N802
self, metric: pb.MetricRecord, context: grpc.ServicerContext
) -> pb.MetricResult:
stream_id = metric._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_metric(metric)
# make up a response even though this was async
result = pb.MetricResult()
return result | python | wandb/sdk/service/server_grpc.py | 299 | 307 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,420 | Pause | def Pause( # noqa: N802
self, pause: pb.PauseRequest, context: grpc.ServicerContext
) -> pb.PauseResponse:
stream_id = pause._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_pause(pause)
# make up a response even though this was async
result = pb.PauseResponse()
return result | python | wandb/sdk/service/server_grpc.py | 309 | 317 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,421 | Resume | def Resume( # noqa: N802
self, resume: pb.ResumeRequest, context: grpc.ServicerContext
) -> pb.ResumeResponse:
stream_id = resume._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_resume(resume)
# make up a response even though this was async
result = pb.ResumeResponse()
return result | python | wandb/sdk/service/server_grpc.py | 319 | 327 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,422 | Alert | def Alert( # noqa: N802
self, alert: pb.AlertRecord, context: grpc.ServicerContext
) -> pb.AlertResult:
stream_id = alert._info.stream_id
iface = self._mux.get_stream(stream_id).interface
iface._publish_alert(alert)
# make up a response even though this was async
result = pb.AlertResult()
return result | python | wandb/sdk/service/server_grpc.py | 329 | 337 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,423 | RunStatus | def RunStatus( # noqa: N802
self, run_status: pb.RunStatusRequest, context: grpc.ServicerContext
) -> pb.RunStatusResponse:
stream_id = run_status._info.stream_id
iface = self._mux.get_stream(stream_id).interface
handle = iface._deliver_request_run_status(run_status)
result = handle.wait(timeout=-1)
assert result
return result.response.run_status_response | python | wandb/sdk/service/server_grpc.py | 339 | 347 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,424 | Status | def Status( # noqa: N802
self, status: pb.StatusRequest, context: grpc.ServicerContext
) -> pb.StatusResponse:
stream_id = status._info.stream_id
iface = self._mux.get_stream(stream_id).interface
result = iface._communicate_status(status)
assert result
return result | python | wandb/sdk/service/server_grpc.py | 349 | 356 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,425 | ServerShutdown | def ServerShutdown( # noqa: N802
self,
request: spb.ServerShutdownRequest,
context: grpc.ServicerContext,
) -> spb.ServerShutdownResponse:
result = spb.ServerShutdownResponse()
self._server.stop(5)
return result | python | wandb/sdk/service/server_grpc.py | 358 | 365 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,426 | ServerStatus | def ServerStatus( # noqa: N802
self,
request: spb.ServerStatusRequest,
context: grpc.ServicerContext,
) -> spb.ServerStatusResponse:
result = spb.ServerStatusResponse()
return result | python | wandb/sdk/service/server_grpc.py | 367 | 373 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,427 | ServerInformInit | def ServerInformInit( # noqa: N802
self,
request: spb.ServerInformInitRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformInitResponse:
stream_id = request._info.stream_id
settings = settings_dict_from_pbmap(request._settings_map)
self._mux.add_stream(stream_id, settings=settings)
result = spb.ServerInformInitResponse()
return result | python | wandb/sdk/service/server_grpc.py | 375 | 384 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,428 | ServerInformStart | def ServerInformStart( # noqa: N802
self,
request: spb.ServerInformStartRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformStartResponse:
stream_id = request._info.stream_id
settings = settings_dict_from_pbmap(request._settings_map)
self._mux.update_stream(stream_id, settings=settings)
self._mux.start_stream(stream_id)
result = spb.ServerInformStartResponse()
return result | python | wandb/sdk/service/server_grpc.py | 386 | 396 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,429 | ServerInformFinish | def ServerInformFinish( # noqa: N802
self,
request: spb.ServerInformFinishRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformFinishResponse:
stream_id = request._info.stream_id
self._mux.del_stream(stream_id)
result = spb.ServerInformFinishResponse()
return result | python | wandb/sdk/service/server_grpc.py | 398 | 406 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,430 | ServerInformAttach | def ServerInformAttach( # noqa: N802
self,
request: spb.ServerInformAttachRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformAttachResponse:
stream_id = request._info.stream_id
result = spb.ServerInformAttachResponse()
_pbmap_apply_dict(
result._settings_map,
dict(self._mux._streams[stream_id]._settings),
)
return result | python | wandb/sdk/service/server_grpc.py | 408 | 419 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,431 | ServerInformDetach | def ServerInformDetach( # noqa: N802
self,
request: spb.ServerInformDetachRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformDetachResponse:
# TODO
result = spb.ServerInformDetachResponse()
return result | python | wandb/sdk/service/server_grpc.py | 421 | 428 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,432 | ServerInformTeardown | def ServerInformTeardown( # noqa: N802
self,
request: spb.ServerInformTeardownRequest,
context: grpc.ServicerContext,
) -> spb.ServerInformTeardownResponse:
exit_code = request.exit_code
self._mux.teardown(exit_code)
result = spb.ServerInformTeardownResponse()
return result | python | wandb/sdk/service/server_grpc.py | 430 | 438 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,433 | _pbmap_apply_dict | def _pbmap_apply_dict(
m: "MessageMap[str, spb.SettingsValue]", d: Dict[str, Any]
) -> None:
for k, v in d.items():
if isinstance(v, enum.Enum):
continue
sv = spb.SettingsValue()
if v is None:
sv.null_value = True
elif isinstance(
v, bool
): # order matters when using `isinstance` since it looks at all the subclasses and isinstance(True, int) will be true
sv.bool_value = v
elif isinstance(v, int):
sv.int_value = v
elif isinstance(v, float):
sv.float_value = v
elif isinstance(v, str):
sv.string_value = v
elif isinstance(v, Iterable) and not isinstance(v, (str, bytes, Mapping)):
if all(isinstance(x, str) for x in v): # Iterable[str]
sv.tuple_value.string_values.extend(v)
elif isinstance(v, Mapping):
for kk, vv in v.items():
if isinstance(vv, str):
# flat map
sv.map_value.map_values[kk] = vv
elif isinstance(vv, Mapping):
# nested map
for kkk, vvv in vv.items():
sv.nested_map_value.nested_map_values[kk].map_values[kkk] = vvv
elif isinstance(v, datetime.datetime):
sv.timestamp_value = datetime.datetime.strftime(v, "%Y%m%d_%H%M%S")
else:
raise Exception("unsupported type")
m[k].CopyFrom(sv) | python | wandb/sdk/service/service_base.py | 20 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,434 | __init__ | def __init__(self) -> None:
pass | python | wandb/sdk/service/service_base.py | 61 | 62 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,435 | get_transport | def get_transport(self) -> str:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 65 | 66 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,436 | _svc_inform_init | def _svc_inform_init(self, settings: Settings, run_id: str) -> None:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 69 | 70 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,437 | _svc_inform_start | def _svc_inform_start(self, settings: Settings, run_id: str) -> None:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 73 | 74 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,438 | _svc_inform_attach | def _svc_inform_attach(self, attach_id: str) -> spb.ServerInformAttachResponse:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 77 | 78 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,439 | _svc_inform_finish | def _svc_inform_finish(self, run_id: Optional[str] = None) -> None:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 81 | 82 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,440 | _svc_inform_teardown | def _svc_inform_teardown(self, exit_code: int) -> None:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 85 | 86 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,441 | _svc_connect | def _svc_connect(self, port: int) -> None:
raise NotImplementedError | python | wandb/sdk/service/service_base.py | 89 | 90 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,442 | __init__ | def __init__(
self,
api: "internal_api.Api",
tempdir: "tempfile.TemporaryDirectory",
request_queue: "queue.Queue[Event]",
output_queue: "queue.Queue[step_upload.Event]",
stats: "stats.Stats",
) -> None:
self._api = api
self._tempdir = tempdir
self._request_queue = request_queue
self._output_queue = output_queue
self._stats = stats
self._thread = threading.Thread(target=self._thread_body)
self._thread.daemon = True | python | wandb/filesync/step_checksum.py | 53 | 68 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,443 | _thread_body | def _thread_body(self) -> None:
while True:
req = self._request_queue.get()
if isinstance(req, RequestUpload):
path = req.path
if req.copy:
path = os.path.join(
self._tempdir.name,
f"{runid.generate_id()}-{req.save_name}",
)
filesystem.mkdir_exists_ok(os.path.dirname(path))
try:
# certain linux distros throw an exception when copying
# large files: https://bugs.python.org/issue43743
shutil.copy2(req.path, path)
except OSError:
shutil._USE_CP_SENDFILE = False # type: ignore[attr-defined]
shutil.copy2(req.path, path)
self._stats.init_file(req.save_name, os.path.getsize(path))
self._output_queue.put(
step_upload.RequestUpload(
path,
req.save_name,
None,
None,
req.copy,
None,
None,
None,
)
)
elif isinstance(req, RequestStoreManifestFiles):
for entry in req.manifest.entries.values():
if entry.local_path:
self._stats.init_file(
entry.local_path,
cast(int, entry.size),
is_artifact_file=True,
)
self._output_queue.put(
step_upload.RequestUpload(
entry.local_path,
dir_watcher.SaveName(
entry.path
), # typecast might not be legit
req.artifact_id,
entry.digest,
False,
functools.partial(req.save_fn, entry),
functools.partial(req.save_fn_async, entry),
entry.digest,
)
)
elif isinstance(req, RequestCommitArtifact):
self._output_queue.put(
step_upload.RequestCommitArtifact(
req.artifact_id,
req.finalize,
req.before_commit,
req.result_future,
)
)
elif isinstance(req, RequestFinish):
break
else:
raise Exception("internal error")
self._output_queue.put(step_upload.RequestFinish(req.callback)) | python | wandb/filesync/step_checksum.py | 70 | 138 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,444 | start | def start(self) -> None:
self._thread.start() | python | wandb/filesync/step_checksum.py | 140 | 141 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,445 | is_alive | def is_alive(self) -> bool:
return self._thread.is_alive() | python | wandb/filesync/step_checksum.py | 143 | 144 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,446 | finish | def finish(self) -> None:
self._request_queue.put(RequestFinish(None)) | python | wandb/filesync/step_checksum.py | 146 | 147 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,447 | __init__ | def __init__(
self,
file_path: PathStr,
save_name: SaveName,
file_pusher: "FilePusher",
*args: Any,
**kwargs: Any,
) -> None:
self.file_path = file_path
# Convert windows paths to unix paths
save_name = SaveName(util.to_forward_slash_path(save_name))
self.save_name = save_name
self._file_pusher = file_pusher
self._last_sync: Optional[float] = None | python | wandb/filesync/dir_watcher.py | 39 | 52 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,448 | policy | def policy(self) -> "PolicyName":
raise NotImplementedError | python | wandb/filesync/dir_watcher.py | 56 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,449 | on_modified | def on_modified(self, force: bool = False) -> None:
raise NotImplementedError | python | wandb/filesync/dir_watcher.py | 60 | 61 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,450 | finish | def finish(self) -> None:
raise NotImplementedError | python | wandb/filesync/dir_watcher.py | 64 | 65 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,451 | on_renamed | def on_renamed(self, new_path: PathStr, new_name: SaveName) -> None:
self.file_path = new_path
self.save_name = new_name
self.on_modified() | python | wandb/filesync/dir_watcher.py | 67 | 70 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,452 | on_modified | def on_modified(self, force: bool = False) -> None:
# only upload if we've never uploaded or when .save is called
if self._last_sync is None or force:
self._file_pusher.file_changed(self.save_name, self.file_path)
self._last_sync = os.path.getmtime(self.file_path) | python | wandb/filesync/dir_watcher.py | 76 | 80 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,453 | finish | def finish(self) -> None:
pass | python | wandb/filesync/dir_watcher.py | 82 | 83 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,454 | policy | def policy(self) -> "PolicyName":
return "now" | python | wandb/filesync/dir_watcher.py | 86 | 87 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,455 | on_modified | def on_modified(self, force: bool = False) -> None:
pass | python | wandb/filesync/dir_watcher.py | 93 | 94 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,456 | finish | def finish(self) -> None:
# We use copy=False to avoid possibly expensive copies, and because
# user files shouldn't still be changing at the end of the run.
self._last_sync = os.path.getmtime(self.file_path)
self._file_pusher.file_changed(self.save_name, self.file_path, copy=False) | python | wandb/filesync/dir_watcher.py | 97 | 101 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,457 | policy | def policy(self) -> "PolicyName":
return "end" | python | wandb/filesync/dir_watcher.py | 104 | 105 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,458 | __init__ | def __init__(
self,
file_path: PathStr,
save_name: SaveName,
file_pusher: "FilePusher",
settings: Optional["wandb_settings.Settings"] = None,
*args: Any,
**kwargs: Any,
) -> None:
super().__init__(file_path, save_name, file_pusher, *args, **kwargs)
self._last_uploaded_time: Optional[float] = None
self._last_uploaded_size: int = 0
if settings is not None:
if settings._live_policy_rate_limit is not None:
self.RATE_LIMIT_SECONDS = settings._live_policy_rate_limit
self._min_wait_time: Optional[float] = settings._live_policy_wait_time
else:
self._min_wait_time = None | python | wandb/filesync/dir_watcher.py | 120 | 137 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,459 | current_size | def current_size(self) -> int:
return os.path.getsize(self.file_path) | python | wandb/filesync/dir_watcher.py | 140 | 141 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,460 | min_wait_for_size | def min_wait_for_size(cls, size: int) -> float:
if size < 10 * cls.unit_dict["MB"]:
return 60
elif size < 100 * cls.unit_dict["MB"]:
return 5 * 60
elif size < cls.unit_dict["GB"]:
return 10 * 60
else:
return 20 * 60 | python | wandb/filesync/dir_watcher.py | 144 | 152 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,461 | should_update | def should_update(self) -> bool:
if self._last_uploaded_time is not None:
# Check rate limit by time elapsed
time_elapsed = time.time() - self._last_uploaded_time
# if more than 15 seconds has passed potentially upload it
if time_elapsed < self.RATE_LIMIT_SECONDS:
return False
# Check rate limit by size increase
if float(self._last_uploaded_size) > 0:
size_increase = self.current_size / float(self._last_uploaded_size)
if size_increase < self.RATE_LIMIT_SIZE_INCREASE:
return False
return time_elapsed > (
self._min_wait_time or self.min_wait_for_size(self.current_size)
)
# if the file has never been uploaded, we'll upload it
return True | python | wandb/filesync/dir_watcher.py | 154 | 172 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,462 | on_modified | def on_modified(self, force: bool = False) -> None:
if self.current_size == 0:
return
if self._last_sync == os.path.getmtime(self.file_path):
return
if force or self.should_update():
self.save_file() | python | wandb/filesync/dir_watcher.py | 174 | 180 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,463 | save_file | def save_file(self) -> None:
self._last_sync = os.path.getmtime(self.file_path)
self._last_uploaded_time = time.time()
self._last_uploaded_size = self.current_size
self._file_pusher.file_changed(self.save_name, self.file_path) | python | wandb/filesync/dir_watcher.py | 182 | 186 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,464 | finish | def finish(self) -> None:
self.on_modified(force=True) | python | wandb/filesync/dir_watcher.py | 188 | 189 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,465 | policy | def policy(self) -> "PolicyName":
return "live" | python | wandb/filesync/dir_watcher.py | 192 | 193 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,466 | __init__ | def __init__(
self,
settings: "wandb_settings.Settings",
file_pusher: "FilePusher",
file_dir: Optional[PathStr] = None,
) -> None:
self._file_count = 0
self._dir = file_dir or settings.files_dir
self._settings = settings
self._savename_file_policies: MutableMapping[SaveName, "PolicyName"] = {}
self._user_file_policies: Mapping["PolicyName", MutableSet[GlobStr]] = {
"end": set(),
"live": set(),
"now": set(),
}
self._file_pusher = file_pusher
self._file_event_handlers: MutableMapping[SaveName, FileEventHandler] = {}
self._file_observer = wd_polling.PollingObserver()
self._file_observer.schedule(
self._per_file_event_handler(), self._dir, recursive=True
)
self._file_observer.start()
logger.info("watching files in: %s", settings.files_dir) | python | wandb/filesync/dir_watcher.py | 197 | 219 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,467 | emitter | def emitter(self) -> Optional["wd_api.EventEmitter"]:
try:
return next(iter(self._file_observer.emitters))
except StopIteration:
return None | python | wandb/filesync/dir_watcher.py | 222 | 226 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,468 | update_policy | def update_policy(self, path: GlobStr, policy: "PolicyName") -> None:
# When we're dealing with one of our own media files, there's no need
# to store the policy in memory. _get_file_event_handler will always
# return PolicyNow. Using the path makes syncing historic runs much
# faster if the name happens to include glob escapable characters. In
# the future we may add a flag to "files" records that indicates it's
# policy is not dynamic and doesn't need to be stored / checked.
save_name = SaveName(os.path.relpath(os.path.join(self._dir, path), self._dir))
if save_name.startswith("media/"):
pass
elif path == glob.escape(path):
self._savename_file_policies[save_name] = policy
else:
self._user_file_policies[policy].add(path)
for src_path in glob.glob(os.path.join(self._dir, path)):
save_name = SaveName(os.path.relpath(src_path, self._dir))
feh = self._get_file_event_handler(src_path, save_name)
# handle the case where the policy changed
if feh.policy != policy:
try:
del self._file_event_handlers[save_name]
except KeyError:
# TODO: probably should do locking, but this handles moved files for now
pass
feh = self._get_file_event_handler(src_path, save_name)
feh.on_modified(force=True) | python | wandb/filesync/dir_watcher.py | 228 | 253 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,469 | _per_file_event_handler | def _per_file_event_handler(self) -> "wd_events.FileSystemEventHandler":
"""Create a Watchdog file event handler that does different things for every file."""
file_event_handler = wd_events.PatternMatchingEventHandler()
file_event_handler.on_created = self._on_file_created
file_event_handler.on_modified = self._on_file_modified
file_event_handler.on_moved = self._on_file_moved
file_event_handler._patterns = [os.path.join(self._dir, os.path.normpath("*"))]
# Ignore hidden files/folders
# TODO: what other files should we skip?
file_event_handler._ignore_patterns = [
"*.tmp",
"*.wandb",
"wandb-summary.json",
os.path.join(self._dir, ".*"),
os.path.join(self._dir, "*/.*"),
]
# TODO: pipe in actual settings
for glb in self._settings.ignore_globs:
file_event_handler._ignore_patterns.append(os.path.join(self._dir, glb))
return file_event_handler | python | wandb/filesync/dir_watcher.py | 255 | 275 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,470 | _on_file_created | def _on_file_created(self, event: "wd_events.FileCreatedEvent") -> None:
logger.info("file/dir created: %s", event.src_path)
if os.path.isdir(event.src_path):
return None
self._file_count += 1
# We do the directory scan less often as it grows
if self._file_count % 100 == 0:
emitter = self.emitter
if emitter:
emitter._timeout = int(self._file_count / 100) + 1
save_name = SaveName(os.path.relpath(event.src_path, self._dir))
self._get_file_event_handler(event.src_path, save_name).on_modified() | python | wandb/filesync/dir_watcher.py | 277 | 288 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,471 | _on_file_modified | def _on_file_modified(self, event: "wd_events.FileModifiedEvent") -> None:
logger.info(f"file/dir modified: { event.src_path}")
if os.path.isdir(event.src_path):
return None
save_name = SaveName(os.path.relpath(event.src_path, self._dir))
self._get_file_event_handler(event.src_path, save_name).on_modified() | python | wandb/filesync/dir_watcher.py | 294 | 299 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,472 | _on_file_moved | def _on_file_moved(self, event: "wd_events.FileMovedEvent") -> None:
# TODO: test me...
logger.info(f"file/dir moved: {event.src_path} -> {event.dest_path}")
if os.path.isdir(event.dest_path):
return None
old_save_name = SaveName(os.path.relpath(event.src_path, self._dir))
new_save_name = SaveName(os.path.relpath(event.dest_path, self._dir))
# We have to move the existing file handler to the new name
handler = self._get_file_event_handler(event.src_path, old_save_name)
self._file_event_handlers[new_save_name] = handler
del self._file_event_handlers[old_save_name]
handler.on_renamed(event.dest_path, new_save_name) | python | wandb/filesync/dir_watcher.py | 301 | 314 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,473 | _get_file_event_handler | def _get_file_event_handler(
self, file_path: PathStr, save_name: SaveName
) -> FileEventHandler:
"""Get or create an event handler for a particular file.
file_path: the file's actual path
save_name: its path relative to the run directory (aka the watch directory)
"""
# Always return PolicyNow for any of our media files.
if save_name.startswith("media/"):
return PolicyNow(file_path, save_name, self._file_pusher, self._settings)
if save_name not in self._file_event_handlers:
# TODO: we can use PolicyIgnore if there are files we never want to sync
if "tfevents" in save_name or "graph.pbtxt" in save_name:
self._file_event_handlers[save_name] = PolicyLive(
file_path, save_name, self._file_pusher, self._settings
)
elif save_name in self._savename_file_policies:
policy_name = self._savename_file_policies[save_name]
make_handler = (
PolicyLive
if policy_name == "live"
else PolicyNow
if policy_name == "now"
else PolicyEnd
)
self._file_event_handlers[save_name] = make_handler(
file_path, save_name, self._file_pusher, self._settings
)
else:
make_handler = PolicyEnd
for policy, globs in self._user_file_policies.items():
if policy == "end":
continue
# Convert set to list to avoid RuntimeError's
# TODO: we may need to add locks
for g in list(globs):
paths = glob.glob(os.path.join(self._dir, g))
if any(save_name in p for p in paths):
if policy == "live":
make_handler = PolicyLive
elif policy == "now":
make_handler = PolicyNow
self._file_event_handlers[save_name] = make_handler(
file_path, save_name, self._file_pusher, self._settings
)
return self._file_event_handlers[save_name] | python | wandb/filesync/dir_watcher.py | 316 | 362 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,474 | finish | def finish(self) -> None:
logger.info("shutting down directory watcher")
try:
# avoid hanging if we crashed before the observer was started
if self._file_observer.is_alive():
# rather unfortunatly we need to manually do a final scan of the dir
# with `queue_events`, then iterate through all events before stopping
# the observer to catch all files written. First we need to prevent the
# existing thread from consuming our final events, then we process them
self._file_observer._timeout = 0
self._file_observer._stopped_event.set()
self._file_observer.join()
self.emitter.queue_events(0) # type: ignore[union-attr]
while True:
try:
self._file_observer.dispatch_events(
self._file_observer.event_queue, 0
)
except queue.Empty:
break
# Calling stop unschedules any inflight events so we handled them above
self._file_observer.stop()
# TODO: py2 TypeError: PyCObject_AsVoidPtr called with null pointer
except TypeError:
pass
# TODO: py3 SystemError: <built-in function stop> returned an error
except SystemError:
pass
# Ensure we've at least noticed every file in the run directory. Sometimes
# we miss things because asynchronously watching filesystems isn't reliable.
logger.info("scan: %s", self._dir)
for dirpath, _, filenames in os.walk(self._dir):
for fname in filenames:
file_path = os.path.join(dirpath, fname)
save_name = SaveName(os.path.relpath(file_path, self._dir))
ignored = False
for glb in self._settings.ignore_globs:
if len(fnmatch.filter([save_name], glb)) > 0:
ignored = True
logger.info("ignored: %s matching glob %s", save_name, glb)
break
if ignored:
continue
logger.info("scan save: %s %s", file_path, save_name)
self._get_file_event_handler(file_path, save_name).finish() | python | wandb/filesync/dir_watcher.py | 364 | 410 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,475 | __init__ | def __init__(
self,
stats: "stats.Stats",
api: "internal_api.Api",
file_stream: "file_stream.FileStreamApi",
silent: bool,
save_name: "dir_watcher.SaveName",
path: "dir_watcher.PathStr",
artifact_id: Optional[str],
md5: Optional[str],
copied: bool,
save_fn: Optional["step_upload.SaveFn"],
digest: Optional[str],
) -> None:
"""A file uploader.
Arguments:
push_function: function(save_name, actual_path) which actually uploads
the file.
save_name: string logical location of the file relative to the run
directory.
path: actual string path of the file to upload on the filesystem.
"""
self._stats = stats
self._api = api
self._file_stream = file_stream
self.silent = silent
self.save_name = save_name
self.save_path = self.path = path
self.artifact_id = artifact_id
self.md5 = md5
self.copied = copied
self.save_fn = save_fn
self.digest = digest
super().__init__() | python | wandb/filesync/upload_job.py | 22 | 56 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,476 | run | def run(self) -> None:
success = False
try:
self.push()
success = True
finally:
if self.copied and os.path.isfile(self.save_path):
os.remove(self.save_path)
if success:
self._file_stream.push_success(self.artifact_id, self.save_name) # type: ignore | python | wandb/filesync/upload_job.py | 58 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,477 | push | def push(self) -> None:
if self.save_fn:
# Retry logic must happen in save_fn currently
try:
deduped = self.save_fn(
lambda _, t: self._stats.update_uploaded_file(self.save_path, t)
)
except Exception as e:
self._stats.update_failed_file(self.save_path)
logger.exception("Failed to upload file: %s", self.save_path)
wandb._sentry.exception(e)
message = str(e)
# TODO: this is usually XML, but could be JSON
if hasattr(e, "response"):
message = e.response.content
wandb.termerror(
'Error uploading "{}": {}, {}'.format(
self.save_path, type(e).__name__, message
)
)
raise
if deduped:
logger.info("Skipped uploading %s", self.save_path)
self._stats.set_file_deduped(self.save_path)
else:
logger.info("Uploaded file %s", self.save_path)
return
if self.md5:
# This is the new artifact manifest upload flow, in which we create the
# database entry for the manifest file before creating it. This is used for
# artifact L0 files. Which now is only artifact_manifest.json
_, response = self._api.create_artifact_manifest(
self.save_name, self.md5, self.artifact_id
)
upload_url = response["uploadUrl"]
upload_headers = response["uploadHeaders"]
else:
# The classic file upload flow. We get a signed url and upload the file
# then the backend handles the cloud storage metadata callback to create the
# file entry. This flow has aged like a fine wine.
project = self._api.get_project()
_, upload_headers, result = self._api.upload_urls(project, [self.save_name])
file_info = result[self.save_name]
upload_url = file_info["url"]
if upload_url is None:
logger.info("Skipped uploading %s", self.save_path)
self._stats.set_file_deduped(self.save_name)
else:
extra_headers = {}
for upload_header in upload_headers:
key, val = upload_header.split(":", 1)
extra_headers[key] = val
# Copied from push TODO(artifacts): clean up
# If the upload URL is relative, fill it in with the base URL,
# since its a proxied file store like the on-prem VM.
if upload_url.startswith("/"):
upload_url = f"{self._api.api_url}{upload_url}"
try:
with open(self.save_path, "rb") as f:
self._api.upload_file_retry(
upload_url,
f,
lambda _, t: self.progress(t),
extra_headers=extra_headers,
)
logger.info("Uploaded file %s", self.save_path)
except Exception as e:
self._stats.update_failed_file(self.save_name)
logger.exception("Failed to upload file: %s", self.save_path)
wandb._sentry.exception(e)
if not self.silent:
wandb.termerror(
'Error uploading "{}": {}, {}'.format(
self.save_name, type(e).__name__, e
)
)
raise | python | wandb/filesync/upload_job.py | 69 | 148 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,478 | progress | def progress(self, total_bytes: int) -> None:
self._stats.update_uploaded_file(self.save_name, total_bytes) | python | wandb/filesync/upload_job.py | 150 | 151 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,479 | __init__ | def __init__(
self,
stats: "stats.Stats",
api: "internal_api.Api",
file_stream: "file_stream.FileStreamApi",
silent: bool,
request: "step_upload.RequestUpload",
save_fn_async: "step_upload.SaveFnAsync",
) -> None:
self._stats = stats
self._api = api
self._file_stream = file_stream
self.silent = silent
self._request = request
self._save_fn_async = save_fn_async | python | wandb/filesync/upload_job.py | 162 | 176 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,480 | run | async def run(self) -> None:
try:
deduped = await self._save_fn_async(
lambda _, t: self._stats.update_uploaded_file(self._request.path, t)
)
except Exception as e:
# Async uploads aren't yet (2023-01) battle-tested.
# Fall back to the "normal" synchronous upload.
loop = asyncio.get_event_loop()
logger.exception("async upload failed", exc_info=e)
loop.run_in_executor(None, wandb._sentry.exception, e)
wandb.termwarn(
"Async file upload failed; falling back to sync", repeat=False
)
sync_job = UploadJob(
self._stats,
self._api,
self._file_stream,
self.silent,
self._request.save_name,
self._request.path,
self._request.artifact_id,
self._request.md5,
self._request.copied,
self._request.save_fn,
self._request.digest,
)
await loop.run_in_executor(None, sync_job.run)
else:
self._file_stream.push_success(self._request.artifact_id, self._request.save_name) # type: ignore
if deduped:
logger.info("Skipped uploading %s", self._request.path)
self._stats.set_file_deduped(self._request.path)
else:
logger.info("Uploaded file %s", self._request.path)
finally:
# If we fell back to the sync impl, the file will have already been deleted.
# Doesn't matter, we only try to delete it if it exists.
if self._request.copied:
try:
os.remove(self._request.path)
except OSError:
# The file has already been deleted, we don't have permissions, or something else we can't fix.
pass | python | wandb/filesync/upload_job.py | 178 | 223 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,481 | __init__ | def __init__(self) -> None:
self._stats: MutableMapping[str, "FileStats"] = {}
self._lock = threading.Lock() | python | wandb/filesync/stats.py | 29 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,482 | init_file | def init_file(
self, save_name: str, size: int, is_artifact_file: bool = False
) -> None:
with self._lock:
self._stats[save_name] = FileStats(
deduped=False,
total=size,
uploaded=0,
failed=False,
artifact_file=is_artifact_file,
) | python | wandb/filesync/stats.py | 33 | 43 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,483 | set_file_deduped | def set_file_deduped(self, save_name: str) -> None:
with self._lock:
orig = self._stats[save_name]
self._stats[save_name] = orig._replace(
deduped=True,
uploaded=orig.total,
) | python | wandb/filesync/stats.py | 45 | 51 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,484 | update_uploaded_file | def update_uploaded_file(self, save_name: str, total_uploaded: int) -> None:
with self._lock:
self._stats[save_name] = self._stats[save_name]._replace(
uploaded=total_uploaded,
) | python | wandb/filesync/stats.py | 53 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,485 | update_failed_file | def update_failed_file(self, save_name: str) -> None:
with self._lock:
self._stats[save_name] = self._stats[save_name]._replace(
uploaded=0,
failed=True,
) | python | wandb/filesync/stats.py | 59 | 64 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,486 | summary | def summary(self) -> Summary:
# Need to use list to ensure we get a copy, since other threads may
# modify this while we iterate
with self._lock:
stats = list(self._stats.values())
return Summary(
uploaded_bytes=sum(f.uploaded for f in stats),
total_bytes=sum(f.total for f in stats),
deduped_bytes=sum(f.total for f in stats if f.deduped),
) | python | wandb/filesync/stats.py | 66 | 75 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,487 | file_counts_by_category | def file_counts_by_category(self) -> FileCountsByCategory:
artifact_files = 0
wandb_files = 0
media_files = 0
other_files = 0
# Need to use list to ensure we get a copy, since other threads may
# modify this while we iterate
with self._lock:
file_stats = list(self._stats.items())
for save_name, stats in file_stats:
if stats.artifact_file:
artifact_files += 1
elif wandb.wandb_lib.filenames.is_wandb_file(save_name): # type: ignore[attr-defined] # TODO(spencerpearson): this is probably synonymous with wandb.sdk.lib.filenames...?
wandb_files += 1
elif save_name.startswith("media"):
media_files += 1
else:
other_files += 1
return FileCountsByCategory(
artifact=artifact_files,
wandb=wandb_files,
media=media_files,
other=other_files,
) | python | wandb/filesync/stats.py | 77 | 100 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,488 | __init__ | def __init__(
self,
pool: concurrent.futures.ThreadPoolExecutor,
concurrency_limit: Optional[int],
) -> None:
self.loop = asyncio.new_event_loop()
self.loop.set_default_executor(pool)
self.loop_thread = threading.Thread(
target=self.loop.run_forever,
daemon=True,
name="wandb-upload-async",
)
self.concurrency_limiter = asyncio.Semaphore(
value=concurrency_limit or 128,
# Before Python 3.10: if we don't set `loop=loop`,
# then the Semaphore will bind to the wrong event loop,
# causing errors when a coroutine tries to wait for it;
# see https://pastebin.com/XcrS9suX .
# After 3.10: the `loop` argument doesn't exist.
# So we need to only conditionally pass in `loop`.
**({} if sys.version_info >= (3, 10) else {"loop": self.loop}),
) | python | wandb/filesync/step_upload.py | 80 | 102 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,489 | start | def start(self) -> None:
self.loop_thread.start() | python | wandb/filesync/step_upload.py | 104 | 105 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,490 | stop | def stop(self) -> None:
self.loop.call_soon_threadsafe(self.loop.stop) | python | wandb/filesync/step_upload.py | 107 | 108 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,491 | submit | def submit(self, coro: Awaitable[None]) -> None:
async def run_with_limiter() -> None:
async with self.concurrency_limiter:
await coro
asyncio.run_coroutine_threadsafe(run_with_limiter(), self.loop) | python | wandb/filesync/step_upload.py | 110 | 115 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,492 | run_with_limiter | async def run_with_limiter() -> None:
async with self.concurrency_limiter:
await coro | python | wandb/filesync/step_upload.py | 111 | 113 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,493 | __init__ | def __init__(
self,
api: "internal_api.Api",
stats: "stats.Stats",
event_queue: "queue.Queue[Event]",
max_threads: int,
file_stream: "file_stream.FileStreamApi",
settings: Optional["SettingsStatic"] = None,
) -> None:
self._api = api
self._stats = stats
self._event_queue = event_queue
self._file_stream = file_stream
self._thread = threading.Thread(target=self._thread_body)
self._thread.daemon = True
self._pool = concurrent.futures.ThreadPoolExecutor(
thread_name_prefix="wandb-upload",
max_workers=max_threads,
)
self._async_executor = (
AsyncExecutor(
pool=self._pool,
concurrency_limit=settings._async_upload_concurrency_limit,
)
if settings is not None and settings._async_upload_concurrency_limit
else None
)
# Indexed by files' `save_name`'s, which are their ID's in the Run.
self._running_jobs: MutableMapping[dir_watcher.SaveName, RequestUpload] = {}
self._pending_jobs: MutableSequence[RequestUpload] = []
self._artifacts: MutableMapping[str, "ArtifactStatus"] = {}
self.silent = bool(settings.silent) if settings else False | python | wandb/filesync/step_upload.py | 119 | 156 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,494 | _thread_body | def _thread_body(self) -> None:
event: Optional[Event]
# Wait for event in the queue, and process one by one until a
# finish event is received
finish_callback = None
while True:
event = self._event_queue.get()
if isinstance(event, RequestFinish):
finish_callback = event.callback
break
self._handle_event(event)
# We've received a finish event. At this point, further Upload requests
# are invalid.
# After a finish event is received, iterate through the event queue
# one by one and process all remaining events.
while True:
try:
event = self._event_queue.get(True, 0.2)
except queue.Empty:
event = None
if event:
self._handle_event(event)
elif not self._running_jobs:
# Queue was empty and no jobs left.
self._pool.shutdown(wait=False)
if self._async_executor:
self._async_executor.stop()
if finish_callback:
finish_callback()
break | python | wandb/filesync/step_upload.py | 158 | 189 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,495 | _handle_event | def _handle_event(self, event: Event) -> None:
if isinstance(event, upload_job.EventJobDone):
job = event.job
if event.exc is not None:
logger.exception(
"Failed to upload file: %s", job.path, exc_info=event.exc
)
if job.artifact_id:
if event.exc is None:
self._artifacts[job.artifact_id]["pending_count"] -= 1
self._maybe_commit_artifact(job.artifact_id)
else:
if not self.silent:
termerror(
"Uploading artifact file failed. Artifact won't be committed."
)
self._fail_artifact_futures(job.artifact_id, event.exc)
self._running_jobs.pop(job.save_name)
# If we have any pending jobs, start one now
if self._pending_jobs:
event = self._pending_jobs.pop(0)
self._start_upload_job(event)
elif isinstance(event, RequestCommitArtifact):
if event.artifact_id not in self._artifacts:
self._init_artifact(event.artifact_id)
self._artifacts[event.artifact_id]["commit_requested"] = True
self._artifacts[event.artifact_id]["finalize"] = event.finalize
self._artifacts[event.artifact_id]["pre_commit_callbacks"].add(
event.before_commit
)
self._artifacts[event.artifact_id]["result_futures"].add(
event.result_future
)
self._maybe_commit_artifact(event.artifact_id)
elif isinstance(event, RequestUpload):
if event.artifact_id is not None:
if event.artifact_id not in self._artifacts:
self._init_artifact(event.artifact_id)
self._artifacts[event.artifact_id]["pending_count"] += 1
self._start_upload_job(event)
else:
raise Exception("Programming error: unhandled event: %s" % str(event)) | python | wandb/filesync/step_upload.py | 191 | 234 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,496 | _start_upload_job | def _start_upload_job(self, event: RequestUpload) -> None:
# Operations on a single backend file must be serialized. if
# we're already uploading this file, put the event on the
# end of the queue
if event.save_name in self._running_jobs:
self._pending_jobs.append(event)
return
if self._async_executor and event.save_fn_async is not None:
# (The `and save_fn_async is not None` is because the async code path
# doesn't support all uploads yet: even if the user has requested async,
# we sometimes need to use the sync method instead.)
self._spawn_upload_async(
event,
async_executor=self._async_executor,
)
else:
self._spawn_upload_sync(event) | python | wandb/filesync/step_upload.py | 236 | 253 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,497 | _spawn_upload_sync | def _spawn_upload_sync(self, event: RequestUpload) -> None:
"""Spawn an upload job, and handles the bookkeeping of `self._running_jobs`.
Context: it's important that, whenever we add an entry to `self._running_jobs`,
we ensure that a corresponding `EventJobDone` message will eventually get handled;
otherwise, the `_running_jobs` entry will never get removed, and the StepUpload
will never shut down.
The sole purpose of this function is to make sure that the code that adds an entry
to `self._running_jobs` is textually right next to the code that eventually enqueues
the `EventJobDone` message. This should help keep them in sync.
"""
# Adding the entry to `self._running_jobs` MUST happen in the main thread,
# NOT in the job that gets submitted to the thread-pool, to guard against
# this sequence of events:
# - StepUpload receives a RequestUpload
# ...and therefore spawns a thread to do the upload
# - StepUpload receives a RequestFinish
# ...and checks `self._running_jobs` to see if there are any tasks to wait for...
# ...and there are none, because the addition to `self._running_jobs` happens in
# the background thread, which the scheduler hasn't yet run...
# ...so the StepUpload shuts down. Even though we haven't uploaded the file!
#
# This would be very bad!
# So, this line has to happen _outside_ the `pool.submit()`.
self._running_jobs[event.save_name] = event
def run_and_notify() -> None:
try:
self._do_upload_sync(event)
finally:
self._event_queue.put(
upload_job.EventJobDone(event, exc=sys.exc_info()[1])
)
self._pool.submit(run_and_notify) | python | wandb/filesync/step_upload.py | 255 | 290 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,498 | run_and_notify | def run_and_notify() -> None:
try:
self._do_upload_sync(event)
finally:
self._event_queue.put(
upload_job.EventJobDone(event, exc=sys.exc_info()[1])
) | python | wandb/filesync/step_upload.py | 282 | 288 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,499 | _spawn_upload_async | def _spawn_upload_async(
self,
event: RequestUpload,
async_executor: AsyncExecutor,
) -> None:
"""Equivalent to _spawn_upload_sync, but uses the async event loop instead of a thread, and requires `event.save_fn_async`.
Raises:
AssertionError: if `event.save_fn_async` is None.
"""
assert event.save_fn_async is not None
self._running_jobs[event.save_name] = event
async def run_and_notify() -> None:
try:
await self._do_upload_async(event)
finally:
self._event_queue.put(
upload_job.EventJobDone(event, exc=sys.exc_info()[1])
)
async_executor.submit(run_and_notify()) | python | wandb/filesync/step_upload.py | 292 | 314 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
5,500 | run_and_notify | async def run_and_notify() -> None:
try:
await self._do_upload_async(event)
finally:
self._event_queue.put(
upload_job.EventJobDone(event, exc=sys.exc_info()[1])
) | python | wandb/filesync/step_upload.py | 306 | 312 | {
"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.