wandb 0.17.0rc1__py3-none-macosx_10_9_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (842) hide show
  1. package_readme.md +95 -0
  2. wandb/__init__.py +253 -0
  3. wandb/__main__.py +3 -0
  4. wandb/_globals.py +19 -0
  5. wandb/agents/__init__.py +0 -0
  6. wandb/agents/pyagent.py +364 -0
  7. wandb/analytics/__init__.py +3 -0
  8. wandb/analytics/sentry.py +266 -0
  9. wandb/apis/__init__.py +48 -0
  10. wandb/apis/attrs.py +40 -0
  11. wandb/apis/importers/__init__.py +1 -0
  12. wandb/apis/importers/internals/internal.py +386 -0
  13. wandb/apis/importers/internals/protocols.py +99 -0
  14. wandb/apis/importers/internals/util.py +78 -0
  15. wandb/apis/importers/mlflow.py +254 -0
  16. wandb/apis/importers/validation.py +108 -0
  17. wandb/apis/importers/wandb.py +1598 -0
  18. wandb/apis/internal.py +228 -0
  19. wandb/apis/normalize.py +89 -0
  20. wandb/apis/paginator.py +81 -0
  21. wandb/apis/public/__init__.py +34 -0
  22. wandb/apis/public/api.py +1045 -0
  23. wandb/apis/public/artifacts.py +851 -0
  24. wandb/apis/public/const.py +4 -0
  25. wandb/apis/public/files.py +195 -0
  26. wandb/apis/public/history.py +149 -0
  27. wandb/apis/public/jobs.py +634 -0
  28. wandb/apis/public/projects.py +162 -0
  29. wandb/apis/public/query_generator.py +166 -0
  30. wandb/apis/public/reports.py +469 -0
  31. wandb/apis/public/runs.py +803 -0
  32. wandb/apis/public/sweeps.py +240 -0
  33. wandb/apis/public/teams.py +198 -0
  34. wandb/apis/public/users.py +136 -0
  35. wandb/apis/reports/__init__.py +7 -0
  36. wandb/apis/reports/v1/__init__.py +30 -0
  37. wandb/apis/reports/v1/_blocks.py +1406 -0
  38. wandb/apis/reports/v1/_helpers.py +70 -0
  39. wandb/apis/reports/v1/_panels.py +1282 -0
  40. wandb/apis/reports/v1/_templates.py +478 -0
  41. wandb/apis/reports/v1/blocks.py +27 -0
  42. wandb/apis/reports/v1/helpers.py +2 -0
  43. wandb/apis/reports/v1/mutations.py +66 -0
  44. wandb/apis/reports/v1/panels.py +17 -0
  45. wandb/apis/reports/v1/report.py +268 -0
  46. wandb/apis/reports/v1/runset.py +144 -0
  47. wandb/apis/reports/v1/templates.py +7 -0
  48. wandb/apis/reports/v1/util.py +406 -0
  49. wandb/apis/reports/v1/validators.py +131 -0
  50. wandb/apis/reports/v2/__init__.py +20 -0
  51. wandb/apis/reports/v2/blocks.py +25 -0
  52. wandb/apis/reports/v2/expr_parsing.py +257 -0
  53. wandb/apis/reports/v2/gql.py +68 -0
  54. wandb/apis/reports/v2/interface.py +1911 -0
  55. wandb/apis/reports/v2/internal.py +867 -0
  56. wandb/apis/reports/v2/metrics.py +6 -0
  57. wandb/apis/reports/v2/panels.py +15 -0
  58. wandb/beta/workflows.py +283 -0
  59. wandb/bin/apple_gpu_stats +0 -0
  60. wandb/bin/wandb-core +0 -0
  61. wandb/catboost/__init__.py +9 -0
  62. wandb/cli/__init__.py +0 -0
  63. wandb/cli/cli.py +2890 -0
  64. wandb/data_types.py +2068 -0
  65. wandb/docker/__init__.py +342 -0
  66. wandb/docker/auth.py +436 -0
  67. wandb/docker/wandb-entrypoint.sh +33 -0
  68. wandb/docker/www_authenticate.py +94 -0
  69. wandb/env.py +496 -0
  70. wandb/errors/__init__.py +46 -0
  71. wandb/errors/term.py +95 -0
  72. wandb/errors/util.py +57 -0
  73. wandb/fastai/__init__.py +9 -0
  74. wandb/filesync/__init__.py +0 -0
  75. wandb/filesync/dir_watcher.py +403 -0
  76. wandb/filesync/stats.py +100 -0
  77. wandb/filesync/step_checksum.py +145 -0
  78. wandb/filesync/step_prepare.py +199 -0
  79. wandb/filesync/step_upload.py +392 -0
  80. wandb/filesync/upload_job.py +218 -0
  81. wandb/integration/__init__.py +0 -0
  82. wandb/integration/catboost/__init__.py +5 -0
  83. wandb/integration/catboost/catboost.py +178 -0
  84. wandb/integration/cohere/__init__.py +3 -0
  85. wandb/integration/cohere/cohere.py +21 -0
  86. wandb/integration/cohere/resolver.py +347 -0
  87. wandb/integration/diffusers/__init__.py +3 -0
  88. wandb/integration/diffusers/autologger.py +76 -0
  89. wandb/integration/diffusers/pipeline_resolver.py +50 -0
  90. wandb/integration/diffusers/resolvers/__init__.py +9 -0
  91. wandb/integration/diffusers/resolvers/multimodal.py +882 -0
  92. wandb/integration/diffusers/resolvers/utils.py +102 -0
  93. wandb/integration/fastai/__init__.py +249 -0
  94. wandb/integration/gym/__init__.py +85 -0
  95. wandb/integration/huggingface/__init__.py +3 -0
  96. wandb/integration/huggingface/huggingface.py +18 -0
  97. wandb/integration/huggingface/resolver.py +213 -0
  98. wandb/integration/keras/__init__.py +14 -0
  99. wandb/integration/keras/callbacks/__init__.py +5 -0
  100. wandb/integration/keras/callbacks/metrics_logger.py +130 -0
  101. wandb/integration/keras/callbacks/model_checkpoint.py +200 -0
  102. wandb/integration/keras/callbacks/tables_builder.py +226 -0
  103. wandb/integration/keras/keras.py +1080 -0
  104. wandb/integration/kfp/__init__.py +6 -0
  105. wandb/integration/kfp/helpers.py +28 -0
  106. wandb/integration/kfp/kfp_patch.py +324 -0
  107. wandb/integration/kfp/wandb_logging.py +182 -0
  108. wandb/integration/langchain/__init__.py +3 -0
  109. wandb/integration/langchain/wandb_tracer.py +48 -0
  110. wandb/integration/lightgbm/__init__.py +239 -0
  111. wandb/integration/lightning/__init__.py +0 -0
  112. wandb/integration/lightning/fabric/__init__.py +3 -0
  113. wandb/integration/lightning/fabric/logger.py +762 -0
  114. wandb/integration/magic.py +556 -0
  115. wandb/integration/metaflow/__init__.py +3 -0
  116. wandb/integration/metaflow/metaflow.py +383 -0
  117. wandb/integration/openai/__init__.py +3 -0
  118. wandb/integration/openai/fine_tuning.py +454 -0
  119. wandb/integration/openai/openai.py +22 -0
  120. wandb/integration/openai/resolver.py +240 -0
  121. wandb/integration/prodigy/__init__.py +3 -0
  122. wandb/integration/prodigy/prodigy.py +299 -0
  123. wandb/integration/sacred/__init__.py +117 -0
  124. wandb/integration/sagemaker/__init__.py +12 -0
  125. wandb/integration/sagemaker/auth.py +28 -0
  126. wandb/integration/sagemaker/config.py +49 -0
  127. wandb/integration/sagemaker/files.py +3 -0
  128. wandb/integration/sagemaker/resources.py +34 -0
  129. wandb/integration/sb3/__init__.py +3 -0
  130. wandb/integration/sb3/sb3.py +153 -0
  131. wandb/integration/tensorboard/__init__.py +10 -0
  132. wandb/integration/tensorboard/log.py +358 -0
  133. wandb/integration/tensorboard/monkeypatch.py +185 -0
  134. wandb/integration/tensorflow/__init__.py +5 -0
  135. wandb/integration/tensorflow/estimator_hook.py +54 -0
  136. wandb/integration/torch/__init__.py +0 -0
  137. wandb/integration/ultralytics/__init__.py +11 -0
  138. wandb/integration/ultralytics/bbox_utils.py +208 -0
  139. wandb/integration/ultralytics/callback.py +524 -0
  140. wandb/integration/ultralytics/classification_utils.py +83 -0
  141. wandb/integration/ultralytics/mask_utils.py +202 -0
  142. wandb/integration/ultralytics/pose_utils.py +104 -0
  143. wandb/integration/xgboost/__init__.py +11 -0
  144. wandb/integration/xgboost/xgboost.py +189 -0
  145. wandb/integration/yolov8/__init__.py +0 -0
  146. wandb/integration/yolov8/yolov8.py +284 -0
  147. wandb/jupyter.py +501 -0
  148. wandb/keras/__init__.py +19 -0
  149. wandb/lightgbm/__init__.py +9 -0
  150. wandb/magic.py +3 -0
  151. wandb/mpmain/__init__.py +0 -0
  152. wandb/mpmain/__main__.py +1 -0
  153. wandb/old/__init__.py +0 -0
  154. wandb/old/core.py +131 -0
  155. wandb/old/settings.py +173 -0
  156. wandb/old/summary.py +435 -0
  157. wandb/plot/__init__.py +19 -0
  158. wandb/plot/bar.py +42 -0
  159. wandb/plot/confusion_matrix.py +99 -0
  160. wandb/plot/histogram.py +36 -0
  161. wandb/plot/line.py +40 -0
  162. wandb/plot/line_series.py +88 -0
  163. wandb/plot/pr_curve.py +135 -0
  164. wandb/plot/roc_curve.py +117 -0
  165. wandb/plot/scatter.py +32 -0
  166. wandb/plots/__init__.py +6 -0
  167. wandb/plots/explain_text.py +36 -0
  168. wandb/plots/heatmap.py +81 -0
  169. wandb/plots/named_entity.py +43 -0
  170. wandb/plots/part_of_speech.py +50 -0
  171. wandb/plots/plot_definitions.py +768 -0
  172. wandb/plots/precision_recall.py +121 -0
  173. wandb/plots/roc.py +103 -0
  174. wandb/plots/utils.py +195 -0
  175. wandb/proto/__init__.py +0 -0
  176. wandb/proto/v3/__init__.py +0 -0
  177. wandb/proto/v3/wandb_base_pb2.py +54 -0
  178. wandb/proto/v3/wandb_internal_pb2.py +1586 -0
  179. wandb/proto/v3/wandb_server_pb2.py +207 -0
  180. wandb/proto/v3/wandb_settings_pb2.py +111 -0
  181. wandb/proto/v3/wandb_telemetry_pb2.py +105 -0
  182. wandb/proto/v4/__init__.py +0 -0
  183. wandb/proto/v4/wandb_base_pb2.py +29 -0
  184. wandb/proto/v4/wandb_internal_pb2.py +354 -0
  185. wandb/proto/v4/wandb_server_pb2.py +62 -0
  186. wandb/proto/v4/wandb_settings_pb2.py +44 -0
  187. wandb/proto/v4/wandb_telemetry_pb2.py +40 -0
  188. wandb/proto/wandb_base_pb2.py +8 -0
  189. wandb/proto/wandb_deprecated.py +37 -0
  190. wandb/proto/wandb_internal_codegen.py +83 -0
  191. wandb/proto/wandb_internal_pb2.py +8 -0
  192. wandb/proto/wandb_server_pb2.py +8 -0
  193. wandb/proto/wandb_settings_pb2.py +8 -0
  194. wandb/proto/wandb_telemetry_pb2.py +8 -0
  195. wandb/py.typed +0 -0
  196. wandb/sacred/__init__.py +3 -0
  197. wandb/sdk/__init__.py +37 -0
  198. wandb/sdk/artifacts/__init__.py +0 -0
  199. wandb/sdk/artifacts/artifact.py +2317 -0
  200. wandb/sdk/artifacts/artifact_download_logger.py +43 -0
  201. wandb/sdk/artifacts/artifact_file_cache.py +229 -0
  202. wandb/sdk/artifacts/artifact_instance_cache.py +15 -0
  203. wandb/sdk/artifacts/artifact_manifest.py +72 -0
  204. wandb/sdk/artifacts/artifact_manifest_entry.py +205 -0
  205. wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
  206. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +90 -0
  207. wandb/sdk/artifacts/artifact_saver.py +270 -0
  208. wandb/sdk/artifacts/artifact_state.py +11 -0
  209. wandb/sdk/artifacts/artifact_ttl.py +7 -0
  210. wandb/sdk/artifacts/exceptions.py +56 -0
  211. wandb/sdk/artifacts/staging.py +25 -0
  212. wandb/sdk/artifacts/storage_handler.py +60 -0
  213. wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
  214. wandb/sdk/artifacts/storage_handlers/azure_handler.py +194 -0
  215. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +195 -0
  216. wandb/sdk/artifacts/storage_handlers/http_handler.py +113 -0
  217. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +135 -0
  218. wandb/sdk/artifacts/storage_handlers/multi_handler.py +54 -0
  219. wandb/sdk/artifacts/storage_handlers/s3_handler.py +300 -0
  220. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +68 -0
  221. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +133 -0
  222. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +72 -0
  223. wandb/sdk/artifacts/storage_layout.py +6 -0
  224. wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
  225. wandb/sdk/artifacts/storage_policies/register.py +1 -0
  226. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +411 -0
  227. wandb/sdk/artifacts/storage_policy.py +83 -0
  228. wandb/sdk/backend/__init__.py +0 -0
  229. wandb/sdk/backend/backend.py +240 -0
  230. wandb/sdk/data_types/__init__.py +0 -0
  231. wandb/sdk/data_types/_dtypes.py +911 -0
  232. wandb/sdk/data_types/_private.py +10 -0
  233. wandb/sdk/data_types/base_types/__init__.py +0 -0
  234. wandb/sdk/data_types/base_types/json_metadata.py +55 -0
  235. wandb/sdk/data_types/base_types/media.py +313 -0
  236. wandb/sdk/data_types/base_types/wb_value.py +274 -0
  237. wandb/sdk/data_types/helper_types/__init__.py +0 -0
  238. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +293 -0
  239. wandb/sdk/data_types/helper_types/classes.py +159 -0
  240. wandb/sdk/data_types/helper_types/image_mask.py +233 -0
  241. wandb/sdk/data_types/histogram.py +96 -0
  242. wandb/sdk/data_types/html.py +115 -0
  243. wandb/sdk/data_types/image.py +687 -0
  244. wandb/sdk/data_types/molecule.py +241 -0
  245. wandb/sdk/data_types/object_3d.py +363 -0
  246. wandb/sdk/data_types/plotly.py +82 -0
  247. wandb/sdk/data_types/saved_model.py +444 -0
  248. wandb/sdk/data_types/trace_tree.py +438 -0
  249. wandb/sdk/data_types/utils.py +180 -0
  250. wandb/sdk/data_types/video.py +245 -0
  251. wandb/sdk/integration_utils/__init__.py +0 -0
  252. wandb/sdk/integration_utils/auto_logging.py +239 -0
  253. wandb/sdk/integration_utils/data_logging.py +475 -0
  254. wandb/sdk/interface/__init__.py +0 -0
  255. wandb/sdk/interface/constants.py +4 -0
  256. wandb/sdk/interface/interface.py +949 -0
  257. wandb/sdk/interface/interface_queue.py +59 -0
  258. wandb/sdk/interface/interface_relay.py +53 -0
  259. wandb/sdk/interface/interface_shared.py +550 -0
  260. wandb/sdk/interface/interface_sock.py +61 -0
  261. wandb/sdk/interface/message_future.py +27 -0
  262. wandb/sdk/interface/message_future_poll.py +50 -0
  263. wandb/sdk/interface/router.py +118 -0
  264. wandb/sdk/interface/router_queue.py +44 -0
  265. wandb/sdk/interface/router_relay.py +39 -0
  266. wandb/sdk/interface/router_sock.py +36 -0
  267. wandb/sdk/interface/summary_record.py +67 -0
  268. wandb/sdk/internal/__init__.py +0 -0
  269. wandb/sdk/internal/context.py +89 -0
  270. wandb/sdk/internal/datastore.py +297 -0
  271. wandb/sdk/internal/file_pusher.py +184 -0
  272. wandb/sdk/internal/file_stream.py +708 -0
  273. wandb/sdk/internal/flow_control.py +263 -0
  274. wandb/sdk/internal/handler.py +909 -0
  275. wandb/sdk/internal/internal.py +417 -0
  276. wandb/sdk/internal/internal_api.py +4202 -0
  277. wandb/sdk/internal/internal_util.py +100 -0
  278. wandb/sdk/internal/job_builder.py +554 -0
  279. wandb/sdk/internal/profiler.py +78 -0
  280. wandb/sdk/internal/progress.py +111 -0
  281. wandb/sdk/internal/run.py +25 -0
  282. wandb/sdk/internal/sample.py +70 -0
  283. wandb/sdk/internal/sender.py +1642 -0
  284. wandb/sdk/internal/sender_config.py +197 -0
  285. wandb/sdk/internal/settings_static.py +83 -0
  286. wandb/sdk/internal/system/__init__.py +0 -0
  287. wandb/sdk/internal/system/assets/__init__.py +27 -0
  288. wandb/sdk/internal/system/assets/aggregators.py +37 -0
  289. wandb/sdk/internal/system/assets/asset_registry.py +20 -0
  290. wandb/sdk/internal/system/assets/cpu.py +163 -0
  291. wandb/sdk/internal/system/assets/disk.py +210 -0
  292. wandb/sdk/internal/system/assets/gpu.py +414 -0
  293. wandb/sdk/internal/system/assets/gpu_amd.py +230 -0
  294. wandb/sdk/internal/system/assets/gpu_apple.py +177 -0
  295. wandb/sdk/internal/system/assets/interfaces.py +207 -0
  296. wandb/sdk/internal/system/assets/ipu.py +177 -0
  297. wandb/sdk/internal/system/assets/memory.py +166 -0
  298. wandb/sdk/internal/system/assets/network.py +125 -0
  299. wandb/sdk/internal/system/assets/open_metrics.py +299 -0
  300. wandb/sdk/internal/system/assets/tpu.py +154 -0
  301. wandb/sdk/internal/system/assets/trainium.py +398 -0
  302. wandb/sdk/internal/system/env_probe_helpers.py +13 -0
  303. wandb/sdk/internal/system/system_info.py +247 -0
  304. wandb/sdk/internal/system/system_monitor.py +229 -0
  305. wandb/sdk/internal/tb_watcher.py +518 -0
  306. wandb/sdk/internal/thread_local_settings.py +18 -0
  307. wandb/sdk/internal/update.py +113 -0
  308. wandb/sdk/internal/writer.py +206 -0
  309. wandb/sdk/launch/__init__.py +6 -0
  310. wandb/sdk/launch/_launch.py +348 -0
  311. wandb/sdk/launch/_launch_add.py +257 -0
  312. wandb/sdk/launch/_project_spec.py +578 -0
  313. wandb/sdk/launch/agent/__init__.py +5 -0
  314. wandb/sdk/launch/agent/agent.py +878 -0
  315. wandb/sdk/launch/agent/config.py +299 -0
  316. wandb/sdk/launch/agent/job_status_tracker.py +53 -0
  317. wandb/sdk/launch/agent/run_queue_item_file_saver.py +47 -0
  318. wandb/sdk/launch/builder/__init__.py +0 -0
  319. wandb/sdk/launch/builder/abstract.py +89 -0
  320. wandb/sdk/launch/builder/build.py +706 -0
  321. wandb/sdk/launch/builder/docker_builder.py +193 -0
  322. wandb/sdk/launch/builder/kaniko_builder.py +579 -0
  323. wandb/sdk/launch/builder/noop.py +58 -0
  324. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +187 -0
  325. wandb/sdk/launch/create_job.py +520 -0
  326. wandb/sdk/launch/environment/abstract.py +29 -0
  327. wandb/sdk/launch/environment/aws_environment.py +297 -0
  328. wandb/sdk/launch/environment/azure_environment.py +105 -0
  329. wandb/sdk/launch/environment/gcp_environment.py +335 -0
  330. wandb/sdk/launch/environment/local_environment.py +66 -0
  331. wandb/sdk/launch/errors.py +19 -0
  332. wandb/sdk/launch/git_reference.py +109 -0
  333. wandb/sdk/launch/loader.py +249 -0
  334. wandb/sdk/launch/registry/abstract.py +48 -0
  335. wandb/sdk/launch/registry/anon.py +29 -0
  336. wandb/sdk/launch/registry/azure_container_registry.py +124 -0
  337. wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
  338. wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
  339. wandb/sdk/launch/registry/local_registry.py +67 -0
  340. wandb/sdk/launch/runner/__init__.py +0 -0
  341. wandb/sdk/launch/runner/abstract.py +195 -0
  342. wandb/sdk/launch/runner/kubernetes_monitor.py +441 -0
  343. wandb/sdk/launch/runner/kubernetes_runner.py +893 -0
  344. wandb/sdk/launch/runner/local_container.py +299 -0
  345. wandb/sdk/launch/runner/local_process.py +99 -0
  346. wandb/sdk/launch/runner/sagemaker_runner.py +422 -0
  347. wandb/sdk/launch/runner/vertex_runner.py +229 -0
  348. wandb/sdk/launch/sweeps/__init__.py +39 -0
  349. wandb/sdk/launch/sweeps/scheduler.py +738 -0
  350. wandb/sdk/launch/sweeps/scheduler_sweep.py +91 -0
  351. wandb/sdk/launch/sweeps/utils.py +316 -0
  352. wandb/sdk/launch/utils.py +866 -0
  353. wandb/sdk/launch/wandb_reference.py +138 -0
  354. wandb/sdk/lib/__init__.py +5 -0
  355. wandb/sdk/lib/_settings_toposort_generate.py +159 -0
  356. wandb/sdk/lib/_settings_toposort_generated.py +244 -0
  357. wandb/sdk/lib/_wburls_generate.py +25 -0
  358. wandb/sdk/lib/_wburls_generated.py +22 -0
  359. wandb/sdk/lib/apikey.py +258 -0
  360. wandb/sdk/lib/capped_dict.py +26 -0
  361. wandb/sdk/lib/config_util.py +101 -0
  362. wandb/sdk/lib/console.py +39 -0
  363. wandb/sdk/lib/deprecate.py +42 -0
  364. wandb/sdk/lib/disabled.py +190 -0
  365. wandb/sdk/lib/exit_hooks.py +54 -0
  366. wandb/sdk/lib/file_stream_utils.py +118 -0
  367. wandb/sdk/lib/filenames.py +64 -0
  368. wandb/sdk/lib/filesystem.py +372 -0
  369. wandb/sdk/lib/fsm.py +174 -0
  370. wandb/sdk/lib/gitlib.py +239 -0
  371. wandb/sdk/lib/gql_request.py +65 -0
  372. wandb/sdk/lib/handler_util.py +21 -0
  373. wandb/sdk/lib/hashutil.py +62 -0
  374. wandb/sdk/lib/import_hooks.py +275 -0
  375. wandb/sdk/lib/ipython.py +146 -0
  376. wandb/sdk/lib/json_util.py +80 -0
  377. wandb/sdk/lib/lazyloader.py +63 -0
  378. wandb/sdk/lib/mailbox.py +460 -0
  379. wandb/sdk/lib/module.py +69 -0
  380. wandb/sdk/lib/paths.py +106 -0
  381. wandb/sdk/lib/preinit.py +42 -0
  382. wandb/sdk/lib/printer.py +313 -0
  383. wandb/sdk/lib/proto_util.py +69 -0
  384. wandb/sdk/lib/redirect.py +840 -0
  385. wandb/sdk/lib/reporting.py +99 -0
  386. wandb/sdk/lib/retry.py +289 -0
  387. wandb/sdk/lib/run_moment.py +78 -0
  388. wandb/sdk/lib/runid.py +12 -0
  389. wandb/sdk/lib/server.py +52 -0
  390. wandb/sdk/lib/sock_client.py +291 -0
  391. wandb/sdk/lib/sparkline.py +45 -0
  392. wandb/sdk/lib/telemetry.py +100 -0
  393. wandb/sdk/lib/timed_input.py +133 -0
  394. wandb/sdk/lib/timer.py +19 -0
  395. wandb/sdk/lib/tracelog.py +255 -0
  396. wandb/sdk/lib/wburls.py +46 -0
  397. wandb/sdk/service/__init__.py +0 -0
  398. wandb/sdk/service/_startup_debug.py +22 -0
  399. wandb/sdk/service/port_file.py +53 -0
  400. wandb/sdk/service/server.py +119 -0
  401. wandb/sdk/service/server_sock.py +276 -0
  402. wandb/sdk/service/service.py +266 -0
  403. wandb/sdk/service/service_base.py +50 -0
  404. wandb/sdk/service/service_sock.py +70 -0
  405. wandb/sdk/service/streams.py +426 -0
  406. wandb/sdk/verify/__init__.py +0 -0
  407. wandb/sdk/verify/verify.py +501 -0
  408. wandb/sdk/wandb_alerts.py +12 -0
  409. wandb/sdk/wandb_config.py +319 -0
  410. wandb/sdk/wandb_helper.py +54 -0
  411. wandb/sdk/wandb_init.py +1220 -0
  412. wandb/sdk/wandb_login.py +339 -0
  413. wandb/sdk/wandb_manager.py +222 -0
  414. wandb/sdk/wandb_metric.py +110 -0
  415. wandb/sdk/wandb_require.py +92 -0
  416. wandb/sdk/wandb_require_helpers.py +44 -0
  417. wandb/sdk/wandb_run.py +4191 -0
  418. wandb/sdk/wandb_settings.py +1973 -0
  419. wandb/sdk/wandb_setup.py +335 -0
  420. wandb/sdk/wandb_summary.py +150 -0
  421. wandb/sdk/wandb_sweep.py +114 -0
  422. wandb/sdk/wandb_sync.py +75 -0
  423. wandb/sdk/wandb_watch.py +128 -0
  424. wandb/sklearn/__init__.py +37 -0
  425. wandb/sklearn/calculate/__init__.py +32 -0
  426. wandb/sklearn/calculate/calibration_curves.py +125 -0
  427. wandb/sklearn/calculate/class_proportions.py +68 -0
  428. wandb/sklearn/calculate/confusion_matrix.py +92 -0
  429. wandb/sklearn/calculate/decision_boundaries.py +40 -0
  430. wandb/sklearn/calculate/elbow_curve.py +55 -0
  431. wandb/sklearn/calculate/feature_importances.py +67 -0
  432. wandb/sklearn/calculate/learning_curve.py +64 -0
  433. wandb/sklearn/calculate/outlier_candidates.py +69 -0
  434. wandb/sklearn/calculate/residuals.py +86 -0
  435. wandb/sklearn/calculate/silhouette.py +118 -0
  436. wandb/sklearn/calculate/summary_metrics.py +62 -0
  437. wandb/sklearn/plot/__init__.py +35 -0
  438. wandb/sklearn/plot/classifier.py +331 -0
  439. wandb/sklearn/plot/clusterer.py +142 -0
  440. wandb/sklearn/plot/regressor.py +121 -0
  441. wandb/sklearn/plot/shared.py +91 -0
  442. wandb/sklearn/utils.py +183 -0
  443. wandb/sync/__init__.py +3 -0
  444. wandb/sync/sync.py +443 -0
  445. wandb/testing/relay.py +859 -0
  446. wandb/trigger.py +29 -0
  447. wandb/util.py +1925 -0
  448. wandb/vendor/__init__.py +0 -0
  449. wandb/vendor/gql-0.2.0/setup.py +40 -0
  450. wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
  451. wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
  452. wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
  453. wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
  454. wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
  455. wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
  456. wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
  457. wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
  458. wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
  459. wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
  460. wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
  461. wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
  462. wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
  463. wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
  464. wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
  465. wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
  466. wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
  467. wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
  468. wandb/vendor/graphql-core-1.1/setup.py +86 -0
  469. wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
  470. wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
  471. wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
  472. wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
  473. wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
  474. wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
  475. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
  476. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
  477. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
  478. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
  479. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
  480. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
  481. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
  482. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
  483. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
  484. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
  485. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
  486. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
  487. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
  488. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
  489. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
  490. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
  491. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
  492. wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
  493. wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
  494. wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
  495. wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
  496. wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
  497. wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
  498. wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
  499. wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
  500. wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
  501. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
  502. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
  503. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
  504. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
  505. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
  506. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
  507. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
  508. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
  509. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
  510. wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
  511. wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
  512. wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
  513. wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
  514. wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
  515. wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
  516. wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
  517. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
  518. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
  519. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
  520. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
  521. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
  522. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
  523. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
  524. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
  525. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
  526. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
  527. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
  528. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
  529. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
  530. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
  531. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
  532. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
  533. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
  534. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
  535. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
  536. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
  537. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
  538. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
  539. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
  540. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
  541. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
  542. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
  543. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
  544. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
  545. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
  546. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
  547. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
  548. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
  549. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
  550. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
  551. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
  552. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
  553. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
  554. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
  555. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
  556. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
  557. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
  558. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
  559. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
  560. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
  561. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
  562. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
  563. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
  564. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
  565. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
  566. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
  567. wandb/vendor/promise-2.3.0/conftest.py +30 -0
  568. wandb/vendor/promise-2.3.0/setup.py +64 -0
  569. wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
  570. wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
  571. wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
  572. wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
  573. wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
  574. wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
  575. wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
  576. wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
  577. wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
  578. wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
  579. wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
  580. wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
  581. wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
  582. wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
  583. wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
  584. wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
  585. wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
  586. wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
  587. wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
  588. wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
  589. wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
  590. wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
  591. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
  592. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
  593. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
  594. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
  595. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
  596. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
  597. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
  598. wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
  599. wandb/vendor/pygments/__init__.py +90 -0
  600. wandb/vendor/pygments/cmdline.py +568 -0
  601. wandb/vendor/pygments/console.py +74 -0
  602. wandb/vendor/pygments/filter.py +74 -0
  603. wandb/vendor/pygments/filters/__init__.py +350 -0
  604. wandb/vendor/pygments/formatter.py +95 -0
  605. wandb/vendor/pygments/formatters/__init__.py +153 -0
  606. wandb/vendor/pygments/formatters/_mapping.py +85 -0
  607. wandb/vendor/pygments/formatters/bbcode.py +109 -0
  608. wandb/vendor/pygments/formatters/html.py +851 -0
  609. wandb/vendor/pygments/formatters/img.py +600 -0
  610. wandb/vendor/pygments/formatters/irc.py +182 -0
  611. wandb/vendor/pygments/formatters/latex.py +482 -0
  612. wandb/vendor/pygments/formatters/other.py +160 -0
  613. wandb/vendor/pygments/formatters/rtf.py +147 -0
  614. wandb/vendor/pygments/formatters/svg.py +153 -0
  615. wandb/vendor/pygments/formatters/terminal.py +136 -0
  616. wandb/vendor/pygments/formatters/terminal256.py +309 -0
  617. wandb/vendor/pygments/lexer.py +871 -0
  618. wandb/vendor/pygments/lexers/__init__.py +329 -0
  619. wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
  620. wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
  621. wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
  622. wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
  623. wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
  624. wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
  625. wandb/vendor/pygments/lexers/_mapping.py +500 -0
  626. wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
  627. wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
  628. wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
  629. wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
  630. wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
  631. wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
  632. wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
  633. wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
  634. wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
  635. wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
  636. wandb/vendor/pygments/lexers/actionscript.py +240 -0
  637. wandb/vendor/pygments/lexers/agile.py +24 -0
  638. wandb/vendor/pygments/lexers/algebra.py +221 -0
  639. wandb/vendor/pygments/lexers/ambient.py +76 -0
  640. wandb/vendor/pygments/lexers/ampl.py +87 -0
  641. wandb/vendor/pygments/lexers/apl.py +101 -0
  642. wandb/vendor/pygments/lexers/archetype.py +318 -0
  643. wandb/vendor/pygments/lexers/asm.py +641 -0
  644. wandb/vendor/pygments/lexers/automation.py +374 -0
  645. wandb/vendor/pygments/lexers/basic.py +500 -0
  646. wandb/vendor/pygments/lexers/bibtex.py +160 -0
  647. wandb/vendor/pygments/lexers/business.py +612 -0
  648. wandb/vendor/pygments/lexers/c_cpp.py +252 -0
  649. wandb/vendor/pygments/lexers/c_like.py +541 -0
  650. wandb/vendor/pygments/lexers/capnproto.py +78 -0
  651. wandb/vendor/pygments/lexers/chapel.py +102 -0
  652. wandb/vendor/pygments/lexers/clean.py +288 -0
  653. wandb/vendor/pygments/lexers/compiled.py +34 -0
  654. wandb/vendor/pygments/lexers/configs.py +833 -0
  655. wandb/vendor/pygments/lexers/console.py +114 -0
  656. wandb/vendor/pygments/lexers/crystal.py +393 -0
  657. wandb/vendor/pygments/lexers/csound.py +366 -0
  658. wandb/vendor/pygments/lexers/css.py +689 -0
  659. wandb/vendor/pygments/lexers/d.py +251 -0
  660. wandb/vendor/pygments/lexers/dalvik.py +125 -0
  661. wandb/vendor/pygments/lexers/data.py +555 -0
  662. wandb/vendor/pygments/lexers/diff.py +165 -0
  663. wandb/vendor/pygments/lexers/dotnet.py +691 -0
  664. wandb/vendor/pygments/lexers/dsls.py +878 -0
  665. wandb/vendor/pygments/lexers/dylan.py +289 -0
  666. wandb/vendor/pygments/lexers/ecl.py +125 -0
  667. wandb/vendor/pygments/lexers/eiffel.py +65 -0
  668. wandb/vendor/pygments/lexers/elm.py +121 -0
  669. wandb/vendor/pygments/lexers/erlang.py +533 -0
  670. wandb/vendor/pygments/lexers/esoteric.py +277 -0
  671. wandb/vendor/pygments/lexers/ezhil.py +69 -0
  672. wandb/vendor/pygments/lexers/factor.py +344 -0
  673. wandb/vendor/pygments/lexers/fantom.py +250 -0
  674. wandb/vendor/pygments/lexers/felix.py +273 -0
  675. wandb/vendor/pygments/lexers/forth.py +177 -0
  676. wandb/vendor/pygments/lexers/fortran.py +205 -0
  677. wandb/vendor/pygments/lexers/foxpro.py +428 -0
  678. wandb/vendor/pygments/lexers/functional.py +21 -0
  679. wandb/vendor/pygments/lexers/go.py +101 -0
  680. wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
  681. wandb/vendor/pygments/lexers/graph.py +80 -0
  682. wandb/vendor/pygments/lexers/graphics.py +553 -0
  683. wandb/vendor/pygments/lexers/haskell.py +843 -0
  684. wandb/vendor/pygments/lexers/haxe.py +936 -0
  685. wandb/vendor/pygments/lexers/hdl.py +382 -0
  686. wandb/vendor/pygments/lexers/hexdump.py +103 -0
  687. wandb/vendor/pygments/lexers/html.py +602 -0
  688. wandb/vendor/pygments/lexers/idl.py +270 -0
  689. wandb/vendor/pygments/lexers/igor.py +288 -0
  690. wandb/vendor/pygments/lexers/inferno.py +96 -0
  691. wandb/vendor/pygments/lexers/installers.py +322 -0
  692. wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
  693. wandb/vendor/pygments/lexers/iolang.py +63 -0
  694. wandb/vendor/pygments/lexers/j.py +146 -0
  695. wandb/vendor/pygments/lexers/javascript.py +1525 -0
  696. wandb/vendor/pygments/lexers/julia.py +333 -0
  697. wandb/vendor/pygments/lexers/jvm.py +1573 -0
  698. wandb/vendor/pygments/lexers/lisp.py +2621 -0
  699. wandb/vendor/pygments/lexers/make.py +202 -0
  700. wandb/vendor/pygments/lexers/markup.py +595 -0
  701. wandb/vendor/pygments/lexers/math.py +21 -0
  702. wandb/vendor/pygments/lexers/matlab.py +663 -0
  703. wandb/vendor/pygments/lexers/ml.py +769 -0
  704. wandb/vendor/pygments/lexers/modeling.py +358 -0
  705. wandb/vendor/pygments/lexers/modula2.py +1561 -0
  706. wandb/vendor/pygments/lexers/monte.py +204 -0
  707. wandb/vendor/pygments/lexers/ncl.py +894 -0
  708. wandb/vendor/pygments/lexers/nimrod.py +159 -0
  709. wandb/vendor/pygments/lexers/nit.py +64 -0
  710. wandb/vendor/pygments/lexers/nix.py +136 -0
  711. wandb/vendor/pygments/lexers/oberon.py +105 -0
  712. wandb/vendor/pygments/lexers/objective.py +504 -0
  713. wandb/vendor/pygments/lexers/ooc.py +85 -0
  714. wandb/vendor/pygments/lexers/other.py +41 -0
  715. wandb/vendor/pygments/lexers/parasail.py +79 -0
  716. wandb/vendor/pygments/lexers/parsers.py +835 -0
  717. wandb/vendor/pygments/lexers/pascal.py +644 -0
  718. wandb/vendor/pygments/lexers/pawn.py +199 -0
  719. wandb/vendor/pygments/lexers/perl.py +620 -0
  720. wandb/vendor/pygments/lexers/php.py +267 -0
  721. wandb/vendor/pygments/lexers/praat.py +294 -0
  722. wandb/vendor/pygments/lexers/prolog.py +306 -0
  723. wandb/vendor/pygments/lexers/python.py +939 -0
  724. wandb/vendor/pygments/lexers/qvt.py +152 -0
  725. wandb/vendor/pygments/lexers/r.py +453 -0
  726. wandb/vendor/pygments/lexers/rdf.py +270 -0
  727. wandb/vendor/pygments/lexers/rebol.py +431 -0
  728. wandb/vendor/pygments/lexers/resource.py +85 -0
  729. wandb/vendor/pygments/lexers/rnc.py +67 -0
  730. wandb/vendor/pygments/lexers/roboconf.py +82 -0
  731. wandb/vendor/pygments/lexers/robotframework.py +560 -0
  732. wandb/vendor/pygments/lexers/ruby.py +519 -0
  733. wandb/vendor/pygments/lexers/rust.py +220 -0
  734. wandb/vendor/pygments/lexers/sas.py +228 -0
  735. wandb/vendor/pygments/lexers/scripting.py +1222 -0
  736. wandb/vendor/pygments/lexers/shell.py +794 -0
  737. wandb/vendor/pygments/lexers/smalltalk.py +195 -0
  738. wandb/vendor/pygments/lexers/smv.py +79 -0
  739. wandb/vendor/pygments/lexers/snobol.py +83 -0
  740. wandb/vendor/pygments/lexers/special.py +103 -0
  741. wandb/vendor/pygments/lexers/sql.py +681 -0
  742. wandb/vendor/pygments/lexers/stata.py +108 -0
  743. wandb/vendor/pygments/lexers/supercollider.py +90 -0
  744. wandb/vendor/pygments/lexers/tcl.py +145 -0
  745. wandb/vendor/pygments/lexers/templates.py +2283 -0
  746. wandb/vendor/pygments/lexers/testing.py +207 -0
  747. wandb/vendor/pygments/lexers/text.py +25 -0
  748. wandb/vendor/pygments/lexers/textedit.py +169 -0
  749. wandb/vendor/pygments/lexers/textfmts.py +297 -0
  750. wandb/vendor/pygments/lexers/theorem.py +458 -0
  751. wandb/vendor/pygments/lexers/trafficscript.py +54 -0
  752. wandb/vendor/pygments/lexers/typoscript.py +226 -0
  753. wandb/vendor/pygments/lexers/urbi.py +133 -0
  754. wandb/vendor/pygments/lexers/varnish.py +190 -0
  755. wandb/vendor/pygments/lexers/verification.py +111 -0
  756. wandb/vendor/pygments/lexers/web.py +24 -0
  757. wandb/vendor/pygments/lexers/webmisc.py +988 -0
  758. wandb/vendor/pygments/lexers/whiley.py +116 -0
  759. wandb/vendor/pygments/lexers/x10.py +69 -0
  760. wandb/vendor/pygments/modeline.py +44 -0
  761. wandb/vendor/pygments/plugin.py +68 -0
  762. wandb/vendor/pygments/regexopt.py +92 -0
  763. wandb/vendor/pygments/scanner.py +105 -0
  764. wandb/vendor/pygments/sphinxext.py +158 -0
  765. wandb/vendor/pygments/style.py +155 -0
  766. wandb/vendor/pygments/styles/__init__.py +80 -0
  767. wandb/vendor/pygments/styles/abap.py +29 -0
  768. wandb/vendor/pygments/styles/algol.py +63 -0
  769. wandb/vendor/pygments/styles/algol_nu.py +63 -0
  770. wandb/vendor/pygments/styles/arduino.py +98 -0
  771. wandb/vendor/pygments/styles/autumn.py +65 -0
  772. wandb/vendor/pygments/styles/borland.py +51 -0
  773. wandb/vendor/pygments/styles/bw.py +49 -0
  774. wandb/vendor/pygments/styles/colorful.py +81 -0
  775. wandb/vendor/pygments/styles/default.py +73 -0
  776. wandb/vendor/pygments/styles/emacs.py +72 -0
  777. wandb/vendor/pygments/styles/friendly.py +72 -0
  778. wandb/vendor/pygments/styles/fruity.py +42 -0
  779. wandb/vendor/pygments/styles/igor.py +29 -0
  780. wandb/vendor/pygments/styles/lovelace.py +97 -0
  781. wandb/vendor/pygments/styles/manni.py +75 -0
  782. wandb/vendor/pygments/styles/monokai.py +106 -0
  783. wandb/vendor/pygments/styles/murphy.py +80 -0
  784. wandb/vendor/pygments/styles/native.py +65 -0
  785. wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
  786. wandb/vendor/pygments/styles/paraiso_light.py +125 -0
  787. wandb/vendor/pygments/styles/pastie.py +75 -0
  788. wandb/vendor/pygments/styles/perldoc.py +69 -0
  789. wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
  790. wandb/vendor/pygments/styles/rrt.py +33 -0
  791. wandb/vendor/pygments/styles/sas.py +44 -0
  792. wandb/vendor/pygments/styles/stata.py +40 -0
  793. wandb/vendor/pygments/styles/tango.py +141 -0
  794. wandb/vendor/pygments/styles/trac.py +63 -0
  795. wandb/vendor/pygments/styles/vim.py +63 -0
  796. wandb/vendor/pygments/styles/vs.py +38 -0
  797. wandb/vendor/pygments/styles/xcode.py +51 -0
  798. wandb/vendor/pygments/token.py +213 -0
  799. wandb/vendor/pygments/unistring.py +217 -0
  800. wandb/vendor/pygments/util.py +388 -0
  801. wandb/vendor/pynvml/__init__.py +0 -0
  802. wandb/vendor/pynvml/pynvml.py +4779 -0
  803. wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
  804. wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
  805. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
  806. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
  807. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
  808. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
  809. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
  810. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
  811. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
  812. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
  813. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
  814. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
  815. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
  816. wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
  817. wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
  818. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
  819. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
  820. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
  821. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
  822. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
  823. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
  824. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
  825. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
  826. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
  827. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
  828. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
  829. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
  830. wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
  831. wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
  832. wandb/viz.py +123 -0
  833. wandb/wandb_agent.py +586 -0
  834. wandb/wandb_controller.py +720 -0
  835. wandb/wandb_run.py +9 -0
  836. wandb/wandb_torch.py +550 -0
  837. wandb/xgboost/__init__.py +9 -0
  838. wandb-0.17.0rc1.dist-info/METADATA +219 -0
  839. wandb-0.17.0rc1.dist-info/RECORD +842 -0
  840. wandb-0.17.0rc1.dist-info/WHEEL +4 -0
  841. wandb-0.17.0rc1.dist-info/entry_points.txt +3 -0
  842. wandb-0.17.0rc1.dist-info/licenses/LICENSE +21 -0
wandb/cli/cli.py ADDED
@@ -0,0 +1,2890 @@
1
+ #!/usr/bin/env python
2
+
3
+ import asyncio
4
+ import configparser
5
+ import datetime
6
+ import getpass
7
+ import json
8
+ import logging
9
+ import os
10
+ import pathlib
11
+ import shlex
12
+ import shutil
13
+ import subprocess
14
+ import sys
15
+ import tempfile
16
+ import textwrap
17
+ import time
18
+ import traceback
19
+ from functools import wraps
20
+ from typing import Any, Dict, Optional
21
+
22
+ import click
23
+ import yaml
24
+ from click.exceptions import ClickException
25
+
26
+ # pycreds has a find_executable that works in windows
27
+ from dockerpycreds.utils import find_executable
28
+
29
+ import wandb
30
+ import wandb.env
31
+
32
+ # from wandb.old.core import wandb_dir
33
+ import wandb.sdk.verify.verify as wandb_verify
34
+ from wandb import Config, Error, env, util, wandb_agent, wandb_sdk
35
+ from wandb.apis import InternalApi, PublicApi
36
+ from wandb.apis.public import RunQueue
37
+ from wandb.integration.magic import magic_install
38
+ from wandb.sdk.artifacts.artifact_file_cache import get_artifact_file_cache
39
+ from wandb.sdk.launch import utils as launch_utils
40
+ from wandb.sdk.launch._launch_add import _launch_add
41
+ from wandb.sdk.launch.errors import ExecutionError, LaunchError
42
+ from wandb.sdk.launch.sweeps import utils as sweep_utils
43
+ from wandb.sdk.launch.sweeps.scheduler import Scheduler
44
+ from wandb.sdk.lib import filesystem
45
+ from wandb.sdk.lib.wburls import wburls
46
+ from wandb.sync import SyncManager, get_run_from_path, get_runs
47
+
48
+ # Send cli logs to wandb/debug-cli.<username>.log by default and fallback to a temp dir.
49
+ _wandb_dir = wandb.old.core.wandb_dir(env.get_dir())
50
+ if not os.path.exists(_wandb_dir):
51
+ _wandb_dir = tempfile.gettempdir()
52
+
53
+ try:
54
+ _username = getpass.getuser()
55
+ except KeyError:
56
+ # getuser() could raise KeyError in restricted environments like
57
+ # chroot jails or docker containers. Return user id in these cases.
58
+ _username = str(os.getuid())
59
+
60
+ _wandb_log_path = os.path.join(_wandb_dir, f"debug-cli.{_username}.log")
61
+
62
+ logging.basicConfig(
63
+ filename=_wandb_log_path,
64
+ level=logging.INFO,
65
+ format="%(asctime)s %(levelname)s %(message)s",
66
+ datefmt="%Y-%m-%d %H:%M:%S",
67
+ )
68
+ logging.basicConfig(stream=sys.stdout, level=logging.INFO)
69
+ logger = logging.getLogger("wandb")
70
+
71
+ # Click Contexts
72
+ CONTEXT = {"default_map": {}}
73
+ RUN_CONTEXT = {
74
+ "default_map": {},
75
+ "allow_extra_args": True,
76
+ "ignore_unknown_options": True,
77
+ }
78
+
79
+
80
+ def cli_unsupported(argument):
81
+ wandb.termerror(f"Unsupported argument `{argument}`")
82
+ sys.exit(1)
83
+
84
+
85
+ class ClickWandbException(ClickException):
86
+ def format_message(self):
87
+ # log_file = util.get_log_file_path()
88
+ log_file = ""
89
+ orig_type = f"{self.orig_type.__module__}.{self.orig_type.__name__}"
90
+ if issubclass(self.orig_type, Error):
91
+ return click.style(str(self.message), fg="red")
92
+ else:
93
+ return (
94
+ f"An Exception was raised, see {log_file} for full traceback.\n"
95
+ f"{orig_type}: {self.message}"
96
+ )
97
+
98
+
99
+ def display_error(func):
100
+ """Function decorator for catching common errors and re-raising as wandb.Error."""
101
+
102
+ @wraps(func)
103
+ def wrapper(*args, **kwargs):
104
+ try:
105
+ return func(*args, **kwargs)
106
+ except wandb.Error as e:
107
+ exc_type, exc_value, exc_traceback = sys.exc_info()
108
+ lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
109
+ logger.error("".join(lines))
110
+ wandb.termerror(f"Find detailed error logs at: {_wandb_log_path}")
111
+ click_exc = ClickWandbException(e)
112
+ click_exc.orig_type = exc_type
113
+ raise click_exc.with_traceback(sys.exc_info()[2])
114
+
115
+ return wrapper
116
+
117
+
118
+ _api = None # caching api instance allows patching from unit tests
119
+
120
+
121
+ def _get_cling_api(reset=None):
122
+ """Get a reference to the internal api with cling settings."""
123
+ global _api
124
+ if reset:
125
+ _api = None
126
+ wandb_sdk.wandb_setup._setup(_reset=True)
127
+ if _api is None:
128
+ # TODO(jhr): make a settings object that is better for non runs.
129
+ # only override the necessary setting
130
+ wandb.setup(settings=dict(_cli_only_mode=True))
131
+ _api = InternalApi()
132
+ return _api
133
+
134
+
135
+ def prompt_for_project(ctx, entity):
136
+ """Ask the user for a project, creating one if necessary."""
137
+ result = ctx.invoke(projects, entity=entity, display=False)
138
+ api = _get_cling_api()
139
+ try:
140
+ if len(result) == 0:
141
+ project = click.prompt("Enter a name for your first project")
142
+ # description = editor()
143
+ project = api.upsert_project(project, entity=entity)["name"]
144
+ else:
145
+ project_names = [project["name"] for project in result] + ["Create New"]
146
+ wandb.termlog("Which project should we use?")
147
+ result = util.prompt_choices(project_names)
148
+ if result:
149
+ project = result
150
+ else:
151
+ project = "Create New"
152
+ # TODO: check with the server if the project exists
153
+ if project == "Create New":
154
+ project = click.prompt(
155
+ "Enter a name for your new project", value_proc=api.format_project
156
+ )
157
+ # description = editor()
158
+ project = api.upsert_project(project, entity=entity)["name"]
159
+
160
+ except wandb.errors.CommError as e:
161
+ raise ClickException(str(e))
162
+
163
+ return project
164
+
165
+
166
+ class RunGroup(click.Group):
167
+ @display_error
168
+ def get_command(self, ctx, cmd_name):
169
+ # TODO: check if cmd_name is a file in the current dir and not require `run`?
170
+ rv = click.Group.get_command(self, ctx, cmd_name)
171
+ if rv is not None:
172
+ return rv
173
+ return None
174
+
175
+
176
+ @click.command(cls=RunGroup, invoke_without_command=True)
177
+ @click.version_option(version=wandb.__version__)
178
+ @click.pass_context
179
+ def cli(ctx):
180
+ if ctx.invoked_subcommand is None:
181
+ click.echo(ctx.get_help())
182
+
183
+
184
+ @cli.command(context_settings=CONTEXT, help="List projects", hidden=True)
185
+ @click.option(
186
+ "--entity",
187
+ "-e",
188
+ default=None,
189
+ envvar=env.ENTITY,
190
+ help="The entity to scope the listing to.",
191
+ )
192
+ @display_error
193
+ def projects(entity, display=True):
194
+ api = _get_cling_api()
195
+ projects = api.list_projects(entity=entity)
196
+ if len(projects) == 0:
197
+ message = "No projects found for %s" % entity
198
+ else:
199
+ message = 'Latest projects for "%s"' % entity
200
+ if display:
201
+ click.echo(click.style(message, bold=True))
202
+ for project in projects:
203
+ click.echo(
204
+ "".join(
205
+ (
206
+ click.style(project["name"], fg="blue", bold=True),
207
+ " - ",
208
+ str(project["description"] or "").split("\n")[0],
209
+ )
210
+ )
211
+ )
212
+ return projects
213
+
214
+
215
+ @cli.command(context_settings=CONTEXT, help="Login to Weights & Biases")
216
+ @click.argument("key", nargs=-1)
217
+ @click.option("--cloud", is_flag=True, help="Login to the cloud instead of local")
218
+ @click.option("--host", default=None, help="Login to a specific instance of W&B")
219
+ @click.option(
220
+ "--relogin", default=None, is_flag=True, help="Force relogin if already logged in."
221
+ )
222
+ @click.option("--anonymously", default=False, is_flag=True, help="Log in anonymously")
223
+ @click.option("--verify", default=False, is_flag=True, help="Verify login credentials")
224
+ @display_error
225
+ def login(key, host, cloud, relogin, anonymously, verify, no_offline=False):
226
+ # TODO: handle no_offline
227
+ anon_mode = "must" if anonymously else "never"
228
+
229
+ wandb_sdk.wandb_login._handle_host_wandb_setting(host, cloud)
230
+ # A change in click or the test harness means key can be none...
231
+ key = key[0] if key is not None and len(key) > 0 else None
232
+ if key:
233
+ relogin = True
234
+
235
+ login_settings = dict(
236
+ _cli_only_mode=True,
237
+ _disable_viewer=relogin and not verify,
238
+ anonymous=anon_mode,
239
+ )
240
+ if host is not None:
241
+ login_settings["base_url"] = host
242
+
243
+ try:
244
+ wandb.setup(settings=login_settings)
245
+ except TypeError as e:
246
+ wandb.termerror(str(e))
247
+ sys.exit(1)
248
+
249
+ wandb.login(
250
+ relogin=relogin,
251
+ key=key,
252
+ anonymous=anon_mode,
253
+ host=host,
254
+ force=True,
255
+ verify=verify,
256
+ )
257
+
258
+
259
+ @cli.command(
260
+ context_settings=CONTEXT, help="Run a wandb service", name="service", hidden=True
261
+ )
262
+ @click.option(
263
+ "--sock-port", default=None, type=int, help="The host port to bind socket service."
264
+ )
265
+ @click.option("--port-filename", default=None, help="Save allocated port to file.")
266
+ @click.option("--address", default=None, help="The address to bind service.")
267
+ @click.option("--pid", default=None, type=int, help="The parent process id to monitor.")
268
+ @click.option("--debug", is_flag=True, help="log debug info")
269
+ @click.option("--serve-sock", is_flag=True, help="use socket mode")
270
+ @display_error
271
+ def service(
272
+ sock_port=None,
273
+ port_filename=None,
274
+ address=None,
275
+ pid=None,
276
+ debug=False,
277
+ serve_sock=False,
278
+ ):
279
+ from wandb.sdk.service.server import WandbServer
280
+
281
+ server = WandbServer(
282
+ sock_port=sock_port,
283
+ port_fname=port_filename,
284
+ address=address,
285
+ pid=pid,
286
+ debug=debug,
287
+ serve_sock=serve_sock,
288
+ )
289
+ server.serve()
290
+
291
+
292
+ @cli.command(
293
+ context_settings=CONTEXT, help="Configure a directory with Weights & Biases"
294
+ )
295
+ @click.option("--project", "-p", help="The project to use.")
296
+ @click.option("--entity", "-e", help="The entity to scope the project to.")
297
+ # TODO(jhr): Enable these with settings rework
298
+ # @click.option("--setting", "-s", help="enable an arbitrary setting.", multiple=True)
299
+ # @click.option('--show', is_flag=True, help="Show settings")
300
+ @click.option("--reset", is_flag=True, help="Reset settings")
301
+ @click.option(
302
+ "--mode",
303
+ "-m",
304
+ help=' Can be "online", "offline" or "disabled". Defaults to online.',
305
+ )
306
+ @click.pass_context
307
+ @display_error
308
+ def init(ctx, project, entity, reset, mode):
309
+ from wandb.old.core import __stage_dir__, _set_stage_dir, wandb_dir
310
+
311
+ if __stage_dir__ is None:
312
+ _set_stage_dir("wandb")
313
+
314
+ # non-interactive init
315
+ if reset or project or entity or mode:
316
+ api = InternalApi()
317
+ if reset:
318
+ api.clear_setting("entity", persist=True)
319
+ api.clear_setting("project", persist=True)
320
+ api.clear_setting("mode", persist=True)
321
+ # TODO(jhr): clear more settings?
322
+ if entity:
323
+ api.set_setting("entity", entity, persist=True)
324
+ if project:
325
+ api.set_setting("project", project, persist=True)
326
+ if mode:
327
+ api.set_setting("mode", mode, persist=True)
328
+ return
329
+
330
+ if os.path.isdir(wandb_dir()) and os.path.exists(
331
+ os.path.join(wandb_dir(), "settings")
332
+ ):
333
+ click.confirm(
334
+ click.style(
335
+ "This directory has been configured previously, should we re-configure it?",
336
+ bold=True,
337
+ ),
338
+ abort=True,
339
+ )
340
+ else:
341
+ click.echo(
342
+ click.style("Let's setup this directory for W&B!", fg="green", bold=True)
343
+ )
344
+ api = _get_cling_api()
345
+ if api.api_key is None:
346
+ ctx.invoke(login)
347
+ api = _get_cling_api(reset=True)
348
+
349
+ viewer = api.viewer()
350
+
351
+ # Viewer can be `None` in case your API information became invalid, or
352
+ # in testing if you switch hosts.
353
+ if not viewer:
354
+ click.echo(
355
+ click.style(
356
+ "Your login information seems to be invalid: can you log in again please?",
357
+ fg="red",
358
+ bold=True,
359
+ )
360
+ )
361
+ ctx.invoke(login)
362
+ api = _get_cling_api(reset=True)
363
+
364
+ # This shouldn't happen.
365
+ viewer = api.viewer()
366
+ if not viewer:
367
+ click.echo(
368
+ click.style(
369
+ "We're sorry, there was a problem logging you in. "
370
+ "Please send us a note at support@wandb.com and tell us how this happened.",
371
+ fg="red",
372
+ bold=True,
373
+ )
374
+ )
375
+ sys.exit(1)
376
+
377
+ # At this point we should be logged in successfully.
378
+ if len(viewer["teams"]["edges"]) > 1:
379
+ team_names = [e["node"]["name"] for e in viewer["teams"]["edges"]] + [
380
+ "Manual entry"
381
+ ]
382
+ wandb.termlog(
383
+ "Which team should we use?",
384
+ )
385
+ result = util.prompt_choices(team_names)
386
+ # result can be empty on click
387
+ if result:
388
+ entity = result
389
+ else:
390
+ entity = "Manual Entry"
391
+ if entity == "Manual Entry":
392
+ entity = click.prompt("Enter the name of the team you want to use")
393
+ else:
394
+ entity = viewer.get("entity") or click.prompt(
395
+ "What username or team should we use?"
396
+ )
397
+
398
+ # TODO: this error handling sucks and the output isn't pretty
399
+ try:
400
+ project = prompt_for_project(ctx, entity)
401
+ except ClickWandbException:
402
+ raise ClickException(f"Could not find team: {entity}")
403
+
404
+ api.set_setting("entity", entity, persist=True)
405
+ api.set_setting("project", project, persist=True)
406
+ api.set_setting("base_url", api.settings().get("base_url"), persist=True)
407
+
408
+ filesystem.mkdir_exists_ok(wandb_dir())
409
+ with open(os.path.join(wandb_dir(), ".gitignore"), "w") as file:
410
+ file.write("*\n!settings")
411
+
412
+ click.echo(
413
+ click.style("This directory is configured! Next, track a run:\n", fg="green")
414
+ + textwrap.dedent(
415
+ """\
416
+ * In your training script:
417
+ {code1}
418
+ {code2}
419
+ * then `{run}`.
420
+ """
421
+ ).format(
422
+ code1=click.style("import wandb", bold=True),
423
+ code2=click.style('wandb.init(project="%s")' % project, bold=True),
424
+ run=click.style("python <train.py>", bold=True),
425
+ )
426
+ )
427
+
428
+
429
+ @cli.group()
430
+ def beta():
431
+ """Beta versions of wandb CLI commands. Requires wandb-core."""
432
+ # this is the future that requires wandb-core!
433
+ from wandb.util import get_core_path
434
+
435
+ if not get_core_path():
436
+ click.secho(
437
+ (
438
+ "wandb beta commands require wandb-core, please install with"
439
+ " `pip install wandb-core`"
440
+ ),
441
+ fg="red",
442
+ err=True,
443
+ )
444
+
445
+
446
+ @beta.command(
447
+ name="sync",
448
+ context_settings=CONTEXT,
449
+ help="Upload a training run to W&B",
450
+ )
451
+ @click.pass_context
452
+ @click.argument("wandb_dir", nargs=1, type=click.Path(exists=True))
453
+ @click.option("--id", "run_id", help="The run you want to upload to.")
454
+ @click.option("--project", "-p", help="The project you want to upload to.")
455
+ @click.option("--entity", "-e", help="The entity to scope to.")
456
+ @click.option("--skip-console", is_flag=True, default=False, help="Skip console logs")
457
+ @click.option("--append", is_flag=True, default=False, help="Append run")
458
+ @click.option(
459
+ "--include",
460
+ "-i",
461
+ help="Glob to include. Can be used multiple times.",
462
+ multiple=True,
463
+ )
464
+ @click.option(
465
+ "--exclude",
466
+ "-e",
467
+ help="Glob to exclude. Can be used multiple times.",
468
+ multiple=True,
469
+ )
470
+ @click.option(
471
+ "--mark-synced/--no-mark-synced",
472
+ is_flag=True,
473
+ default=True,
474
+ help="Mark runs as synced",
475
+ )
476
+ @click.option(
477
+ "--skip-synced/--no-skip-synced",
478
+ is_flag=True,
479
+ default=True,
480
+ help="Skip synced runs",
481
+ )
482
+ @click.option(
483
+ "--dry-run", is_flag=True, help="Perform a dry run without uploading anything."
484
+ )
485
+ @display_error
486
+ def sync_beta(
487
+ ctx,
488
+ wandb_dir=None,
489
+ run_id: Optional[str] = None,
490
+ project: Optional[str] = None,
491
+ entity: Optional[str] = None,
492
+ skip_console: bool = False,
493
+ append: bool = False,
494
+ include: Optional[str] = None,
495
+ exclude: Optional[str] = None,
496
+ skip_synced: bool = True,
497
+ mark_synced: bool = True,
498
+ dry_run: bool = False,
499
+ ):
500
+ import concurrent.futures
501
+ from multiprocessing import cpu_count
502
+
503
+ paths = set()
504
+
505
+ # TODO: test file discovery logic
506
+ # include and exclude globs are evaluated relative to the provided base_path
507
+ if include:
508
+ for pattern in include:
509
+ matching_dirs = list(pathlib.Path(wandb_dir).glob(pattern))
510
+ for d in matching_dirs:
511
+ if not d.is_dir():
512
+ continue
513
+ wandb_files = [p for p in d.glob("*.wandb") if p.is_file()]
514
+ if len(wandb_files) > 1:
515
+ print(f"Multiple wandb files found in directory {d}, skipping")
516
+ elif len(wandb_files) == 1:
517
+ paths.add(d)
518
+ else:
519
+ paths.update({p.parent for p in pathlib.Path(wandb_dir).glob("**/*.wandb")})
520
+
521
+ for pattern in exclude:
522
+ matching_dirs = list(pathlib.Path(wandb_dir).glob(pattern))
523
+ for d in matching_dirs:
524
+ if not d.is_dir():
525
+ continue
526
+ if d in paths:
527
+ paths.remove(d)
528
+
529
+ # remove paths that are already synced, if requested
530
+ if skip_synced:
531
+ synced_paths = set()
532
+ for path in paths:
533
+ wandb_synced_files = [p for p in path.glob("*.wandb.synced") if p.is_file()]
534
+ if len(wandb_synced_files) > 1:
535
+ print(
536
+ f"Multiple wandb.synced files found in directory {path}, skipping"
537
+ )
538
+ elif len(wandb_synced_files) == 1:
539
+ synced_paths.add(path)
540
+ paths -= synced_paths
541
+
542
+ if run_id and len(paths) > 1:
543
+ # TODO: handle this more gracefully
544
+ click.echo("id can only be set for a single run.", err=True)
545
+ sys.exit(1)
546
+
547
+ if not paths:
548
+ click.echo("No runs to sync.")
549
+ return
550
+
551
+ click.echo("Found runs:")
552
+ for path in paths:
553
+ click.echo(f" {path}")
554
+
555
+ if dry_run:
556
+ return
557
+
558
+ wandb.sdk.wandb_setup.setup()
559
+
560
+ # TODO: make it thread-safe in the Rust code
561
+ with concurrent.futures.ProcessPoolExecutor(
562
+ max_workers=min(len(paths), cpu_count())
563
+ ) as executor:
564
+ futures = []
565
+ for path in paths:
566
+ # we already know there is only one wandb file in the directory
567
+ wandb_file = [p for p in path.glob("*.wandb") if p.is_file()][0]
568
+ future = executor.submit(
569
+ wandb._sync,
570
+ wandb_file,
571
+ run_id=run_id,
572
+ project=project,
573
+ entity=entity,
574
+ skip_console=skip_console,
575
+ append=append,
576
+ mark_synced=mark_synced,
577
+ )
578
+ futures.append(future)
579
+
580
+ # Wait for tasks to complete
581
+ for _ in concurrent.futures.as_completed(futures):
582
+ pass
583
+
584
+
585
+ @cli.command(
586
+ context_settings=CONTEXT, help="Upload an offline training directory to W&B"
587
+ )
588
+ @click.pass_context
589
+ @click.argument("path", nargs=-1, type=click.Path(exists=True))
590
+ @click.option("--view", is_flag=True, default=False, help="View runs", hidden=True)
591
+ @click.option("--verbose", is_flag=True, default=False, help="Verbose", hidden=True)
592
+ @click.option("--id", "run_id", help="The run you want to upload to.")
593
+ @click.option("--project", "-p", help="The project you want to upload to.")
594
+ @click.option("--entity", "-e", help="The entity to scope to.")
595
+ @click.option(
596
+ "--job_type",
597
+ "job_type",
598
+ help="Specifies the type of run for grouping related runs together.",
599
+ )
600
+ @click.option(
601
+ "--sync-tensorboard/--no-sync-tensorboard",
602
+ is_flag=True,
603
+ default=None,
604
+ help="Stream tfevent files to wandb.",
605
+ )
606
+ @click.option("--include-globs", help="Comma separated list of globs to include.")
607
+ @click.option("--exclude-globs", help="Comma separated list of globs to exclude.")
608
+ @click.option(
609
+ "--include-online/--no-include-online",
610
+ is_flag=True,
611
+ default=None,
612
+ help="Include online runs",
613
+ )
614
+ @click.option(
615
+ "--include-offline/--no-include-offline",
616
+ is_flag=True,
617
+ default=None,
618
+ help="Include offline runs",
619
+ )
620
+ @click.option(
621
+ "--include-synced/--no-include-synced",
622
+ is_flag=True,
623
+ default=None,
624
+ help="Include synced runs",
625
+ )
626
+ @click.option(
627
+ "--mark-synced/--no-mark-synced",
628
+ is_flag=True,
629
+ default=True,
630
+ help="Mark runs as synced",
631
+ )
632
+ @click.option("--sync-all", is_flag=True, default=False, help="Sync all runs")
633
+ @click.option("--clean", is_flag=True, default=False, help="Delete synced runs")
634
+ @click.option(
635
+ "--clean-old-hours",
636
+ default=24,
637
+ help="Delete runs created before this many hours. To be used alongside --clean flag.",
638
+ type=int,
639
+ )
640
+ @click.option(
641
+ "--clean-force",
642
+ is_flag=True,
643
+ default=False,
644
+ help="Clean without confirmation prompt.",
645
+ )
646
+ @click.option("--ignore", hidden=True)
647
+ @click.option("--show", default=5, help="Number of runs to show")
648
+ @click.option("--append", is_flag=True, default=False, help="Append run")
649
+ @click.option("--skip-console", is_flag=True, default=False, help="Skip console logs")
650
+ @display_error
651
+ def sync(
652
+ ctx,
653
+ path=None,
654
+ view=None,
655
+ verbose=None,
656
+ run_id=None,
657
+ project=None,
658
+ entity=None,
659
+ job_type=None, # trace this back to SyncManager
660
+ sync_tensorboard=None,
661
+ include_globs=None,
662
+ exclude_globs=None,
663
+ include_online=None,
664
+ include_offline=None,
665
+ include_synced=None,
666
+ mark_synced=None,
667
+ sync_all=None,
668
+ ignore=None,
669
+ show=None,
670
+ clean=None,
671
+ clean_old_hours=24,
672
+ clean_force=None,
673
+ append=None,
674
+ skip_console=None,
675
+ ):
676
+ api = _get_cling_api()
677
+ if api.api_key is None:
678
+ wandb.termlog("Login to W&B to sync offline runs")
679
+ ctx.invoke(login, no_offline=True)
680
+ api = _get_cling_api(reset=True)
681
+
682
+ if ignore:
683
+ exclude_globs = ignore
684
+ if include_globs:
685
+ include_globs = include_globs.split(",")
686
+ if exclude_globs:
687
+ exclude_globs = exclude_globs.split(",")
688
+
689
+ def _summary():
690
+ all_items = get_runs(
691
+ include_online=True,
692
+ include_offline=True,
693
+ include_synced=True,
694
+ include_unsynced=True,
695
+ )
696
+ sync_items = get_runs(
697
+ include_online=include_online if include_online is not None else True,
698
+ include_offline=include_offline if include_offline is not None else True,
699
+ include_synced=include_synced if include_synced is not None else False,
700
+ include_unsynced=True,
701
+ exclude_globs=exclude_globs,
702
+ include_globs=include_globs,
703
+ )
704
+ synced = []
705
+ unsynced = []
706
+ for item in all_items:
707
+ (synced if item.synced else unsynced).append(item)
708
+ if sync_items:
709
+ wandb.termlog(f"Number of runs to be synced: {len(sync_items)}")
710
+ if show and show < len(sync_items):
711
+ wandb.termlog(f"Showing {show} runs to be synced:")
712
+ for item in sync_items[: (show or len(sync_items))]:
713
+ wandb.termlog(f" {item}")
714
+ else:
715
+ wandb.termlog("No runs to be synced.")
716
+ if synced:
717
+ clean_cmd = click.style("wandb sync --clean", fg="yellow")
718
+ wandb.termlog(
719
+ f"NOTE: use {clean_cmd} to delete {len(synced)} synced runs from local directory."
720
+ )
721
+ if unsynced:
722
+ sync_cmd = click.style("wandb sync --sync-all", fg="yellow")
723
+ wandb.termlog(
724
+ f"NOTE: use {sync_cmd} to sync {len(unsynced)} unsynced runs from local directory."
725
+ )
726
+
727
+ def _sync_path(_path, _sync_tensorboard):
728
+ if run_id and len(_path) > 1:
729
+ wandb.termerror("id can only be set for a single run.")
730
+ sys.exit(1)
731
+ sm = SyncManager(
732
+ project=project,
733
+ entity=entity,
734
+ run_id=run_id,
735
+ job_type=job_type,
736
+ mark_synced=mark_synced,
737
+ app_url=api.app_url,
738
+ view=view,
739
+ verbose=verbose,
740
+ sync_tensorboard=_sync_tensorboard,
741
+ log_path=_wandb_log_path,
742
+ append=append,
743
+ skip_console=skip_console,
744
+ )
745
+ for p in _path:
746
+ sm.add(p)
747
+ sm.start()
748
+ while not sm.is_done():
749
+ _ = sm.poll()
750
+
751
+ def _sync_all():
752
+ sync_items = get_runs(
753
+ include_online=include_online if include_online is not None else True,
754
+ include_offline=include_offline if include_offline is not None else True,
755
+ include_synced=include_synced if include_synced is not None else False,
756
+ include_unsynced=True,
757
+ exclude_globs=exclude_globs,
758
+ include_globs=include_globs,
759
+ )
760
+ if not sync_items:
761
+ wandb.termerror("Nothing to sync.")
762
+ else:
763
+ # When syncing run directories, default to not syncing tensorboard
764
+ sync_tb = sync_tensorboard if sync_tensorboard is not None else False
765
+ _sync_path(sync_items, sync_tb)
766
+
767
+ def _clean():
768
+ if path:
769
+ runs = list(map(get_run_from_path, path))
770
+ if not clean_force:
771
+ click.confirm(
772
+ click.style(
773
+ f"Are you sure you want to remove {len(runs)} runs?",
774
+ bold=True,
775
+ ),
776
+ abort=True,
777
+ )
778
+ for run in runs:
779
+ shutil.rmtree(run.path)
780
+ click.echo(click.style("Success!", fg="green"))
781
+ return
782
+ runs = get_runs(
783
+ include_online=include_online if include_online is not None else True,
784
+ include_offline=include_offline if include_offline is not None else True,
785
+ include_synced=include_synced if include_synced is not None else True,
786
+ include_unsynced=False,
787
+ exclude_globs=exclude_globs,
788
+ include_globs=include_globs,
789
+ )
790
+ since = datetime.datetime.now() - datetime.timedelta(hours=clean_old_hours)
791
+ old_runs = [run for run in runs if run.datetime < since]
792
+ old_runs.sort(key=lambda _run: _run.datetime)
793
+ if old_runs:
794
+ click.echo(
795
+ f"Found {len(runs)} runs, {len(old_runs)} are older than {clean_old_hours} hours"
796
+ )
797
+ for run in old_runs:
798
+ click.echo(run.path)
799
+ if not clean_force:
800
+ click.confirm(
801
+ click.style(
802
+ f"Are you sure you want to remove {len(old_runs)} runs?",
803
+ bold=True,
804
+ ),
805
+ abort=True,
806
+ )
807
+ for run in old_runs:
808
+ shutil.rmtree(run.path)
809
+ click.echo(click.style("Success!", fg="green"))
810
+ else:
811
+ click.echo(
812
+ click.style(
813
+ f"No runs older than {clean_old_hours} hours found", fg="red"
814
+ )
815
+ )
816
+
817
+ if sync_all:
818
+ _sync_all()
819
+ elif clean:
820
+ _clean()
821
+ elif path:
822
+ # When syncing a specific path, default to syncing tensorboard
823
+ sync_tb = sync_tensorboard if sync_tensorboard is not None else True
824
+ _sync_path(path, sync_tb)
825
+ else:
826
+ _summary()
827
+
828
+
829
+ @cli.command(
830
+ context_settings=CONTEXT,
831
+ help="Initialize a hyperparameter sweep. Search for hyperparameters that optimizes a cost function of a machine learning model by testing various combinations.",
832
+ )
833
+ @click.option(
834
+ "--project",
835
+ "-p",
836
+ default=None,
837
+ help="""The name of the project where W&B runs created from the sweep are sent to. If the project is not specified, the run is sent to a project labeled Uncategorized.""",
838
+ )
839
+ @click.option(
840
+ "--entity",
841
+ "-e",
842
+ default=None,
843
+ help="""The username or team name where you want to send W&B runs created by the sweep to. Ensure that the entity you specify already exists. If you don't specify an entity, the run will be sent to your default entity, which is usually your username.""",
844
+ )
845
+ @click.option("--controller", is_flag=True, default=False, help="Run local controller")
846
+ @click.option("--verbose", is_flag=True, default=False, help="Display verbose output")
847
+ @click.option(
848
+ "--name",
849
+ default=None,
850
+ help="The name of the sweep. The sweep ID is used if no name is specified.",
851
+ )
852
+ @click.option("--program", default=None, help="Set sweep program")
853
+ @click.option("--settings", default=None, help="Set sweep settings", hidden=True)
854
+ @click.option("--update", default=None, help="Update pending sweep")
855
+ @click.option(
856
+ "--stop",
857
+ is_flag=True,
858
+ default=False,
859
+ help="Finish a sweep to stop running new runs and let currently running runs finish.",
860
+ )
861
+ @click.option(
862
+ "--cancel",
863
+ is_flag=True,
864
+ default=False,
865
+ help="Cancel a sweep to kill all running runs and stop running new runs.",
866
+ )
867
+ @click.option(
868
+ "--pause",
869
+ is_flag=True,
870
+ default=False,
871
+ help="Pause a sweep to temporarily stop running new runs.",
872
+ )
873
+ @click.option(
874
+ "--resume",
875
+ is_flag=True,
876
+ default=False,
877
+ help="Resume a sweep to continue running new runs.",
878
+ )
879
+ @click.argument("config_yaml_or_sweep_id")
880
+ @click.pass_context
881
+ @display_error
882
+ def sweep(
883
+ ctx,
884
+ project,
885
+ entity,
886
+ controller,
887
+ verbose,
888
+ name,
889
+ program,
890
+ settings,
891
+ update,
892
+ stop,
893
+ cancel,
894
+ pause,
895
+ resume,
896
+ config_yaml_or_sweep_id,
897
+ ):
898
+ state_args = "stop", "cancel", "pause", "resume"
899
+ lcls = locals()
900
+ is_state_change_command = sum(lcls[k] for k in state_args)
901
+ if is_state_change_command > 1:
902
+ raise Exception("Only one state flag (stop/cancel/pause/resume) is allowed.")
903
+ elif is_state_change_command == 1:
904
+ sweep_id = config_yaml_or_sweep_id
905
+ api = _get_cling_api()
906
+ if api.api_key is None:
907
+ wandb.termlog("Login to W&B to use the sweep feature")
908
+ ctx.invoke(login, no_offline=True)
909
+ api = _get_cling_api(reset=True)
910
+ parts = dict(entity=entity, project=project, name=sweep_id)
911
+ err = sweep_utils.parse_sweep_id(parts)
912
+ if err:
913
+ wandb.termerror(err)
914
+ return
915
+ entity = parts.get("entity") or entity
916
+ project = parts.get("project") or project
917
+ sweep_id = parts.get("name") or sweep_id
918
+ state = [s for s in state_args if lcls[s]][0]
919
+ ings = {
920
+ "stop": "Stopping",
921
+ "cancel": "Cancelling",
922
+ "pause": "Pausing",
923
+ "resume": "Resuming",
924
+ }
925
+ wandb.termlog(f"{ings[state]} sweep {entity}/{project}/{sweep_id}")
926
+ getattr(api, "%s_sweep" % state)(sweep_id, entity=entity, project=project)
927
+ wandb.termlog("Done.")
928
+ return
929
+ else:
930
+ config_yaml = config_yaml_or_sweep_id
931
+
932
+ def _parse_settings(settings):
933
+ """Parse settings from json or comma separated assignments."""
934
+ ret = {}
935
+ # TODO(jhr): merge with magic:_parse_magic
936
+ if settings.find("=") > 0:
937
+ for item in settings.split(","):
938
+ kv = item.split("=")
939
+ if len(kv) != 2:
940
+ wandb.termwarn(
941
+ "Unable to parse sweep settings key value pair", repeat=False
942
+ )
943
+ ret.update(dict([kv]))
944
+ return ret
945
+ wandb.termwarn("Unable to parse settings parameter", repeat=False)
946
+ return ret
947
+
948
+ api = _get_cling_api()
949
+ if api.api_key is None:
950
+ wandb.termlog("Login to W&B to use the sweep feature")
951
+ ctx.invoke(login, no_offline=True)
952
+ api = _get_cling_api(reset=True)
953
+
954
+ sweep_obj_id = None
955
+ if update:
956
+ parts = dict(entity=entity, project=project, name=update)
957
+ err = sweep_utils.parse_sweep_id(parts)
958
+ if err:
959
+ wandb.termerror(err)
960
+ return
961
+ entity = parts.get("entity") or entity
962
+ project = parts.get("project") or project
963
+ sweep_id = parts.get("name") or update
964
+
965
+ has_project = (project or api.settings("project")) is not None
966
+ has_entity = (entity or api.settings("entity")) is not None
967
+
968
+ termerror_msg = (
969
+ "Sweep lookup requires a valid %s, and none was specified. \n"
970
+ "Either set a default %s in wandb/settings, or, if invoking \n`wandb sweep` "
971
+ "from the command line, specify the full sweep path via: \n\n"
972
+ " wandb sweep {username}/{projectname}/{sweepid}\n\n"
973
+ )
974
+
975
+ if not has_entity:
976
+ wandb.termerror(termerror_msg % (("entity",) * 2))
977
+ return
978
+
979
+ if not has_project:
980
+ wandb.termerror(termerror_msg % (("project",) * 2))
981
+ return
982
+
983
+ found = api.sweep(sweep_id, "{}", entity=entity, project=project)
984
+ if not found:
985
+ wandb.termerror(f"Could not find sweep {entity}/{project}/{sweep_id}")
986
+ return
987
+ sweep_obj_id = found["id"]
988
+
989
+ action = "Updating" if sweep_obj_id else "Creating"
990
+ wandb.termlog(f"{action} sweep from: {config_yaml}")
991
+ config = sweep_utils.load_sweep_config(config_yaml)
992
+
993
+ # Set or override parameters
994
+ if name:
995
+ config["name"] = name
996
+ if program:
997
+ config["program"] = program
998
+ if settings:
999
+ settings = _parse_settings(settings)
1000
+ if settings:
1001
+ config.setdefault("settings", {})
1002
+ config["settings"].update(settings)
1003
+ if controller:
1004
+ config.setdefault("controller", {})
1005
+ config["controller"]["type"] = "local"
1006
+
1007
+ is_local = config.get("controller", {}).get("type") == "local"
1008
+ if is_local:
1009
+ from wandb import controller as wandb_controller
1010
+
1011
+ tuner = wandb_controller()
1012
+ err = tuner._validate(config)
1013
+ if err:
1014
+ wandb.termerror(f"Error in sweep file: {err}")
1015
+ return
1016
+
1017
+ env = os.environ
1018
+ entity = (
1019
+ entity
1020
+ or env.get("WANDB_ENTITY")
1021
+ or config.get("entity")
1022
+ or api.settings("entity")
1023
+ )
1024
+ project = (
1025
+ project
1026
+ or env.get("WANDB_PROJECT")
1027
+ or config.get("project")
1028
+ or api.settings("project")
1029
+ or util.auto_project_name(config.get("program"))
1030
+ )
1031
+
1032
+ sweep_id, warnings = api.upsert_sweep(
1033
+ config,
1034
+ project=project,
1035
+ entity=entity,
1036
+ obj_id=sweep_obj_id,
1037
+ )
1038
+ sweep_utils.handle_sweep_config_violations(warnings)
1039
+
1040
+ # Log nicely formatted sweep information
1041
+ styled_id = click.style(sweep_id, fg="yellow")
1042
+ wandb.termlog(f"{action} sweep with ID: {styled_id}")
1043
+
1044
+ sweep_url = wandb_sdk.wandb_sweep._get_sweep_url(api, sweep_id)
1045
+ if sweep_url:
1046
+ styled_url = click.style(sweep_url, underline=True, fg="blue")
1047
+ wandb.termlog(f"View sweep at: {styled_url}")
1048
+
1049
+ # re-probe entity and project if it was auto-detected by upsert_sweep
1050
+ entity = entity or env.get("WANDB_ENTITY")
1051
+ project = project or env.get("WANDB_PROJECT")
1052
+
1053
+ if entity and project:
1054
+ sweep_path = f"{entity}/{project}/{sweep_id}"
1055
+ elif project:
1056
+ sweep_path = f"{project}/{sweep_id}"
1057
+ else:
1058
+ sweep_path = sweep_id
1059
+
1060
+ if sweep_path.find(" ") >= 0:
1061
+ sweep_path = f"{sweep_path!r}"
1062
+
1063
+ styled_path = click.style(f"wandb agent {sweep_path}", fg="yellow")
1064
+ wandb.termlog(f"Run sweep agent with: {styled_path}")
1065
+ if controller:
1066
+ wandb.termlog("Starting wandb controller...")
1067
+ from wandb import controller as wandb_controller
1068
+
1069
+ tuner = wandb_controller(sweep_id)
1070
+ tuner.run(verbose=verbose)
1071
+
1072
+
1073
+ @cli.command(
1074
+ context_settings=CONTEXT,
1075
+ no_args_is_help=True,
1076
+ help="Run a W&B launch sweep (Experimental).",
1077
+ )
1078
+ @click.option(
1079
+ "--queue",
1080
+ "-q",
1081
+ default=None,
1082
+ help="The name of a queue to push the sweep to",
1083
+ )
1084
+ @click.option(
1085
+ "--project",
1086
+ "-p",
1087
+ default=None,
1088
+ help="Name of the project which the agent will watch. "
1089
+ "If passed in, will override the project value passed in using a config file",
1090
+ )
1091
+ @click.option(
1092
+ "--entity",
1093
+ "-e",
1094
+ default=None,
1095
+ help="The entity to use. Defaults to current logged-in user",
1096
+ )
1097
+ @click.option(
1098
+ "--resume_id",
1099
+ "-r",
1100
+ default=None,
1101
+ help="Resume a launch sweep by passing an 8-char sweep id. Queue required",
1102
+ )
1103
+ @click.argument("config", required=False, type=click.Path(exists=True))
1104
+ @click.pass_context
1105
+ @display_error
1106
+ def launch_sweep(
1107
+ ctx,
1108
+ project,
1109
+ entity,
1110
+ queue,
1111
+ config,
1112
+ resume_id,
1113
+ ):
1114
+ api = _get_cling_api()
1115
+ env = os.environ
1116
+ if api.api_key is None:
1117
+ wandb.termlog("Login to W&B to use the sweep feature")
1118
+ ctx.invoke(login, no_offline=True)
1119
+ api = _get_cling_api(reset=True)
1120
+
1121
+ entity = entity or env.get("WANDB_ENTITY") or api.settings("entity")
1122
+ if entity is None:
1123
+ wandb.termerror("Must specify entity when using launch")
1124
+ return
1125
+
1126
+ project = project or env.get("WANDB_PROJECT") or api.settings("project")
1127
+ if project is None:
1128
+ wandb.termerror("A project must be configured when using launch")
1129
+ return
1130
+
1131
+ # get personal username, not team name or service account, default to entity
1132
+ author = api.viewer().get("username") or entity
1133
+
1134
+ # if not sweep_config XOR resume_id
1135
+ if not (config or resume_id):
1136
+ wandb.termerror("'config' and/or 'resume_id' required")
1137
+ return
1138
+
1139
+ parsed_user_config = sweep_utils.load_launch_sweep_config(config)
1140
+ # Rip special keys out of config, store in scheduler run_config
1141
+ launch_args: Dict[str, Any] = parsed_user_config.pop("launch", {})
1142
+ scheduler_args: Dict[str, Any] = parsed_user_config.pop("scheduler", {})
1143
+ settings: Dict[str, Any] = scheduler_args.pop("settings", {})
1144
+
1145
+ scheduler_job: Optional[str] = scheduler_args.get("job")
1146
+ if scheduler_job:
1147
+ wandb.termwarn(
1148
+ "Using a scheduler job for launch sweeps is *experimental* and may change without warning"
1149
+ )
1150
+ queue: Optional[str] = queue or launch_args.get("queue")
1151
+
1152
+ sweep_config, sweep_obj_id = None, None
1153
+ if not resume_id:
1154
+ sweep_config = parsed_user_config
1155
+
1156
+ # check method
1157
+ method = sweep_config.get("method")
1158
+ if scheduler_job and not method:
1159
+ sweep_config["method"] = "custom"
1160
+ elif scheduler_job and method != "custom":
1161
+ # TODO(gst): Check if using Anaconda2
1162
+ wandb.termwarn(
1163
+ "Use 'method': 'custom' in the sweep config when using scheduler jobs, "
1164
+ "or omit it entirely. For jobs using the wandb optimization engine (WandbScheduler), "
1165
+ "set the method in the sweep config under scheduler.settings.method "
1166
+ )
1167
+ settings["method"] = method
1168
+
1169
+ if settings.get("method"):
1170
+ # assume WandbScheduler, and user is using this right
1171
+ sweep_config["method"] = settings["method"]
1172
+
1173
+ else: # Resuming an existing sweep
1174
+ found = api.sweep(resume_id, "{}", entity=entity, project=project)
1175
+ if not found:
1176
+ wandb.termerror(f"Could not find sweep {entity}/{project}/{resume_id}")
1177
+ return
1178
+
1179
+ if found.get("state") == "RUNNING":
1180
+ wandb.termerror(
1181
+ f"Cannot resume sweep {entity}/{project}/{resume_id}, it is already running"
1182
+ )
1183
+ return
1184
+
1185
+ sweep_obj_id = found["id"]
1186
+ sweep_config = yaml.safe_load(found["config"])
1187
+ wandb.termlog(f"Resuming from existing sweep {entity}/{project}/{resume_id}")
1188
+ if len(parsed_user_config.keys()) > 0:
1189
+ wandb.termwarn(
1190
+ "Sweep parameters loaded from resumed sweep, ignoring provided config"
1191
+ )
1192
+
1193
+ prev_scheduler = json.loads(found.get("scheduler") or "{}")
1194
+ run_spec = json.loads(prev_scheduler.get("run_spec", "{}"))
1195
+ if (
1196
+ scheduler_job
1197
+ and run_spec.get("job")
1198
+ and run_spec.get("job") != scheduler_job
1199
+ ):
1200
+ wandb.termerror(
1201
+ f"Resuming a launch sweep with a different scheduler job is not supported. Job loaded from sweep: {run_spec.get('job')}, job in config: {scheduler_job}"
1202
+ )
1203
+ return
1204
+
1205
+ prev_scheduler_args, prev_settings = sweep_utils.get_previous_args(run_spec)
1206
+ # Passed in scheduler_args and settings override previous
1207
+ scheduler_args.update(prev_scheduler_args)
1208
+ settings.update(prev_settings)
1209
+ if not queue:
1210
+ wandb.termerror(
1211
+ "Launch-sweeps require setting a 'queue', use --queue option or a 'queue' key in the 'launch' section in the config"
1212
+ )
1213
+ return
1214
+
1215
+ entrypoint = Scheduler.ENTRYPOINT if not scheduler_job else None
1216
+ args = sweep_utils.construct_scheduler_args(
1217
+ return_job=scheduler_job is not None,
1218
+ sweep_config=sweep_config,
1219
+ queue=queue,
1220
+ project=project,
1221
+ author=author,
1222
+ )
1223
+ if not args:
1224
+ return
1225
+
1226
+ # validate training job existence
1227
+ if not sweep_utils.check_job_exists(PublicApi(), sweep_config.get("job")):
1228
+ return False
1229
+
1230
+ # validate scheduler job existence, if present
1231
+ if not sweep_utils.check_job_exists(PublicApi(), scheduler_job):
1232
+ return False
1233
+
1234
+ # Set run overrides for the Scheduler
1235
+ overrides = {"run_config": {}}
1236
+ if launch_args:
1237
+ overrides["run_config"]["launch"] = launch_args
1238
+ if scheduler_args:
1239
+ overrides["run_config"]["scheduler"] = scheduler_args
1240
+ if settings:
1241
+ overrides["run_config"]["settings"] = settings
1242
+
1243
+ if scheduler_job:
1244
+ overrides["run_config"]["sweep_args"] = args
1245
+ else:
1246
+ overrides["args"] = args
1247
+
1248
+ # configure scheduler job resource
1249
+ resource = scheduler_args.get("resource")
1250
+ if resource:
1251
+ if resource == "local-process" and scheduler_job:
1252
+ wandb.termerror(
1253
+ "Scheduler jobs cannot be run with the 'local-process' resource"
1254
+ )
1255
+ return
1256
+ if resource == "local-process" and scheduler_args.get("docker_image"):
1257
+ wandb.termerror(
1258
+ "Scheduler jobs cannot be run with the 'local-process' resource and a docker image"
1259
+ )
1260
+ return
1261
+ else: # no resource set, default local-process if not scheduler job, else container
1262
+ resource = "local-process" if not scheduler_job else "local-container"
1263
+
1264
+ # Launch job spec for the Scheduler
1265
+ launch_scheduler_spec = launch_utils.construct_launch_spec(
1266
+ uri=Scheduler.PLACEHOLDER_URI,
1267
+ api=api,
1268
+ name="Scheduler.WANDB_SWEEP_ID",
1269
+ project=project,
1270
+ entity=entity,
1271
+ docker_image=scheduler_args.get("docker_image"),
1272
+ resource=resource,
1273
+ entry_point=entrypoint,
1274
+ resource_args=scheduler_args.get("resource_args", {}),
1275
+ repository=launch_args.get("registry", {}).get("url", None),
1276
+ job=scheduler_job,
1277
+ version=None,
1278
+ launch_config={"overrides": overrides},
1279
+ run_id="WANDB_SWEEP_ID", # scheduler inits run with sweep_id=run_id
1280
+ author=None, # author gets passed into scheduler override args
1281
+ )
1282
+ launch_scheduler_with_queue = json.dumps(
1283
+ {
1284
+ "queue": queue,
1285
+ "run_queue_project": launch_utils.LAUNCH_DEFAULT_PROJECT,
1286
+ "run_spec": json.dumps(launch_scheduler_spec),
1287
+ }
1288
+ )
1289
+
1290
+ sweep_id, warnings = api.upsert_sweep(
1291
+ sweep_config,
1292
+ project=project,
1293
+ entity=entity,
1294
+ obj_id=sweep_obj_id, # if resuming
1295
+ launch_scheduler=launch_scheduler_with_queue,
1296
+ state="PENDING",
1297
+ )
1298
+ sweep_utils.handle_sweep_config_violations(warnings)
1299
+ # Log nicely formatted sweep information
1300
+ styled_id = click.style(sweep_id, fg="yellow")
1301
+ wandb.termlog(f"{'Resumed' if resume_id else 'Created'} sweep with ID: {styled_id}")
1302
+ sweep_url = wandb_sdk.wandb_sweep._get_sweep_url(api, sweep_id)
1303
+ if sweep_url:
1304
+ styled_url = click.style(sweep_url, underline=True, fg="blue")
1305
+ wandb.termlog(f"View sweep at: {styled_url}")
1306
+ wandb.termlog(f"Scheduler added to launch queue ({queue})")
1307
+
1308
+
1309
+ @cli.command(help=f"Launch or queue a W&B Job. See {wburls.get('cli_launch')}")
1310
+ @click.option("--uri", "-u", metavar="(str)", default=None, hidden=True)
1311
+ @click.option(
1312
+ "--job",
1313
+ "-j",
1314
+ metavar="(str)",
1315
+ default=None,
1316
+ help="Name of the job to launch. If passed in, launch does not require a uri.",
1317
+ )
1318
+ @click.option(
1319
+ "--entry-point",
1320
+ "-E",
1321
+ metavar="NAME",
1322
+ default=None,
1323
+ help="""Entry point within project. [default: main]. If the entry point is not found,
1324
+ attempts to run the project file with the specified name as a script,
1325
+ using 'python' to run .py files and the default shell (specified by
1326
+ environment variable $SHELL) to run .sh files. If passed in, will override the entrypoint value passed in using a config file.""",
1327
+ )
1328
+ @click.option(
1329
+ "--git-version",
1330
+ "-g",
1331
+ metavar="GIT-VERSION",
1332
+ hidden=True,
1333
+ help="Version of the project to run, as a Git commit reference for Git projects.",
1334
+ )
1335
+ @click.option(
1336
+ "--name",
1337
+ envvar="WANDB_NAME",
1338
+ help="""Name of the run under which to launch the run. If not
1339
+ specified, a random run name will be used to launch run. If passed in, will override the name passed in using a config file.""",
1340
+ )
1341
+ @click.option(
1342
+ "--entity",
1343
+ "-e",
1344
+ metavar="(str)",
1345
+ default=None,
1346
+ help="""Name of the target entity which the new run will be sent to. Defaults to using the entity set by local wandb/settings folder.
1347
+ If passed in, will override the entity value passed in using a config file.""",
1348
+ )
1349
+ @click.option(
1350
+ "--project",
1351
+ "-p",
1352
+ metavar="(str)",
1353
+ default=None,
1354
+ help="""Name of the target project which the new run will be sent to. Defaults to using the project name given by the source uri
1355
+ or for github runs, the git repo name. If passed in, will override the project value passed in using a config file.""",
1356
+ )
1357
+ @click.option(
1358
+ "--resource",
1359
+ "-r",
1360
+ metavar="BACKEND",
1361
+ default=None,
1362
+ help="""Execution resource to use for run. Supported values: 'local-process', 'local-container', 'kubernetes', 'sagemaker', 'gcp-vertex'.
1363
+ This is now a required parameter if pushing to a queue with no resource configuration.
1364
+ If passed in, will override the resource value passed in using a config file.""",
1365
+ )
1366
+ @click.option(
1367
+ "--docker-image",
1368
+ "-d",
1369
+ default=None,
1370
+ metavar="DOCKER IMAGE",
1371
+ help="""Specific docker image you'd like to use. In the form name:tag.
1372
+ If passed in, will override the docker image value passed in using a config file.""",
1373
+ )
1374
+ @click.option(
1375
+ "--config",
1376
+ "-c",
1377
+ metavar="FILE",
1378
+ help="""Path to JSON file (must end in '.json') or JSON string which will be passed
1379
+ as a launch config. Dictation how the launched run will be configured.""",
1380
+ )
1381
+ @click.option(
1382
+ "--set-var",
1383
+ "-v",
1384
+ "cli_template_vars",
1385
+ default=None,
1386
+ multiple=True,
1387
+ help="""Set template variable values for queues with allow listing enabled,
1388
+ as key-value pairs e.g. `--set-var key1=value1 --set-var key2=value2`""",
1389
+ )
1390
+ @click.option(
1391
+ "--queue",
1392
+ "-q",
1393
+ is_flag=False,
1394
+ flag_value="default",
1395
+ default=None,
1396
+ help="""Name of run queue to push to. If none, launches single run directly. If supplied without
1397
+ an argument (`--queue`), defaults to queue 'default'. Else, if name supplied, specified run queue must exist under the
1398
+ project and entity supplied.""",
1399
+ )
1400
+ @click.option(
1401
+ "--async",
1402
+ "run_async",
1403
+ is_flag=True,
1404
+ help="""Flag to run the job asynchronously. Defaults to false, i.e. unless --async is set, wandb launch will wait for
1405
+ the job to finish. This option is incompatible with --queue; asynchronous options when running with an agent should be
1406
+ set on wandb launch-agent.""",
1407
+ )
1408
+ @click.option(
1409
+ "--resource-args",
1410
+ "-R",
1411
+ metavar="FILE",
1412
+ help="""Path to JSON file (must end in '.json') or JSON string which will be passed
1413
+ as resource args to the compute resource. The exact content which should be
1414
+ provided is different for each execution backend. See documentation for layout of this file.""",
1415
+ )
1416
+ @click.option(
1417
+ "--build",
1418
+ "-b",
1419
+ is_flag=True,
1420
+ hidden=True,
1421
+ help="Flag to build an associated job and push to queue as an image job.",
1422
+ )
1423
+ @click.option(
1424
+ "--repository",
1425
+ "-rg",
1426
+ is_flag=False,
1427
+ default=None,
1428
+ hidden=True,
1429
+ help="Name of a remote repository. Will be used to push a built image to.",
1430
+ )
1431
+ # TODO: this is only included for back compat. But we should remove this in the future
1432
+ @click.option(
1433
+ "--project-queue",
1434
+ "-pq",
1435
+ default=None,
1436
+ hidden=True,
1437
+ help="Name of the project containing the queue to push to. If none, defaults to entity level queues.",
1438
+ )
1439
+ @click.option(
1440
+ "--dockerfile",
1441
+ "-D",
1442
+ default=None,
1443
+ help="Path to the Dockerfile used to build the job, relative to the job's root",
1444
+ )
1445
+ @click.option(
1446
+ "--priority",
1447
+ "-P",
1448
+ default=None,
1449
+ type=click.Choice(["critical", "high", "medium", "low"]),
1450
+ help="""When --queue is passed, set the priority of the job. Launch jobs with higher priority
1451
+ are served first. The order, from highest to lowest priority, is: critical, high, medium, low""",
1452
+ )
1453
+ @display_error
1454
+ def launch(
1455
+ uri,
1456
+ job,
1457
+ entry_point,
1458
+ git_version,
1459
+ name,
1460
+ resource,
1461
+ entity,
1462
+ project,
1463
+ docker_image,
1464
+ config,
1465
+ cli_template_vars,
1466
+ queue,
1467
+ run_async,
1468
+ resource_args,
1469
+ build,
1470
+ repository,
1471
+ project_queue,
1472
+ dockerfile,
1473
+ priority,
1474
+ ):
1475
+ """Start a W&B run from the given URI.
1476
+
1477
+ The URI can bea wandb URI, a GitHub repo uri, or a local path). In the case of a
1478
+ wandb URI the arguments used in the original run will be used by default. These
1479
+ arguments can be overridden using the args option, or specifying those arguments in
1480
+ the config's 'overrides' key, 'args' field as a list of strings.
1481
+
1482
+ Running `wandb launch [URI]` will launch the run directly. To add the run to a
1483
+ queue, run `wandb launch [URI] --queue [optional queuename]`.
1484
+ """
1485
+ logger.info(
1486
+ f"=== Launch called with kwargs {locals()} CLI Version: {wandb.__version__}==="
1487
+ )
1488
+ from wandb.sdk.launch._launch import _launch
1489
+
1490
+ api = _get_cling_api()
1491
+ wandb._sentry.configure_scope(process_context="launch_cli")
1492
+
1493
+ if run_async and queue is not None:
1494
+ raise LaunchError(
1495
+ "Cannot use both --async and --queue with wandb launch, see help for details."
1496
+ )
1497
+
1498
+ if queue and docker_image and not project:
1499
+ raise LaunchError(
1500
+ "Cannot use --queue and --docker together without a project. Please specify a project with --project or -p."
1501
+ )
1502
+
1503
+ if priority is not None and queue is None:
1504
+ raise LaunchError("--priority flag requires --queue to be set")
1505
+
1506
+ if resource_args is not None:
1507
+ resource_args = util.load_json_yaml_dict(resource_args)
1508
+ if resource_args is None:
1509
+ raise LaunchError("Invalid format for resource-args")
1510
+ else:
1511
+ resource_args = {}
1512
+
1513
+ if entry_point is not None:
1514
+ entry_point = shlex.split(entry_point)
1515
+
1516
+ if config is not None:
1517
+ config = util.load_json_yaml_dict(config)
1518
+ if config is None:
1519
+ raise LaunchError("Invalid format for config")
1520
+ else:
1521
+ config = {}
1522
+
1523
+ resource = resource or config.get("resource")
1524
+
1525
+ if build and queue is None:
1526
+ raise LaunchError("Build flag requires a queue to be set")
1527
+
1528
+ try:
1529
+ launch_utils.check_logged_in(api)
1530
+ except Exception:
1531
+ wandb.termerror(f"Error running job: {traceback.format_exc()}")
1532
+
1533
+ run_id = config.get("run_id")
1534
+
1535
+ if dockerfile:
1536
+ if "overrides" in config:
1537
+ config["overrides"]["dockerfile"] = dockerfile
1538
+ else:
1539
+ config["overrides"] = {"dockerfile": dockerfile}
1540
+
1541
+ if priority is not None:
1542
+ priority_map = {
1543
+ "critical": 0,
1544
+ "high": 1,
1545
+ "medium": 2,
1546
+ "low": 3,
1547
+ }
1548
+ priority = priority_map[priority.lower()]
1549
+
1550
+ template_variables = None
1551
+ if cli_template_vars:
1552
+ if queue is None:
1553
+ raise LaunchError("'--set-var' flag requires queue to be set")
1554
+ if entity is None:
1555
+ entity = launch_utils.get_default_entity(api, config)
1556
+ public_api = PublicApi()
1557
+ runqueue = RunQueue(client=public_api.client, name=queue, entity=entity)
1558
+ template_variables = launch_utils.fetch_and_validate_template_variables(
1559
+ runqueue, cli_template_vars
1560
+ )
1561
+
1562
+ if queue is None:
1563
+ # direct launch
1564
+ try:
1565
+ run = asyncio.run(
1566
+ _launch(
1567
+ api,
1568
+ uri,
1569
+ job,
1570
+ project=project,
1571
+ entity=entity,
1572
+ docker_image=docker_image,
1573
+ name=name,
1574
+ entry_point=entry_point,
1575
+ version=git_version,
1576
+ resource=resource,
1577
+ resource_args=resource_args,
1578
+ launch_config=config,
1579
+ synchronous=(not run_async),
1580
+ run_id=run_id,
1581
+ repository=repository,
1582
+ )
1583
+ )
1584
+ if asyncio.run(run.get_status()).state in [
1585
+ "failed",
1586
+ "stopped",
1587
+ "preempted",
1588
+ ]:
1589
+ wandb.termerror("Launched run exited with non-zero status")
1590
+ sys.exit(1)
1591
+ except LaunchError as e:
1592
+ logger.error("=== %s ===", e)
1593
+ wandb._sentry.exception(e)
1594
+ sys.exit(e)
1595
+ except ExecutionError as e:
1596
+ logger.error("=== %s ===", e)
1597
+ wandb._sentry.exception(e)
1598
+ sys.exit(e)
1599
+ except asyncio.CancelledError:
1600
+ sys.exit(0)
1601
+ else:
1602
+ try:
1603
+ _launch_add(
1604
+ api,
1605
+ uri,
1606
+ job,
1607
+ config,
1608
+ template_variables,
1609
+ project,
1610
+ entity,
1611
+ queue,
1612
+ resource,
1613
+ entry_point,
1614
+ name,
1615
+ git_version,
1616
+ docker_image,
1617
+ project_queue,
1618
+ resource_args,
1619
+ build=build,
1620
+ run_id=run_id,
1621
+ repository=repository,
1622
+ priority=priority,
1623
+ )
1624
+
1625
+ except Exception as e:
1626
+ wandb._sentry.exception(e)
1627
+ raise e
1628
+
1629
+
1630
+ @cli.command(
1631
+ context_settings=CONTEXT,
1632
+ help="Run a W&B launch agent.",
1633
+ )
1634
+ @click.pass_context
1635
+ @click.option(
1636
+ "--queue",
1637
+ "-q",
1638
+ "queues",
1639
+ default=None,
1640
+ multiple=True,
1641
+ metavar="<queue(s)>",
1642
+ help="The name of a queue for the agent to watch. Multiple -q flags supported.",
1643
+ )
1644
+ @click.option(
1645
+ "--project",
1646
+ "-p",
1647
+ default=None,
1648
+ help="""Name of the project which the agent will watch.
1649
+ If passed in, will override the project value passed in using a config file.""",
1650
+ )
1651
+ @click.option(
1652
+ "--entity",
1653
+ "-e",
1654
+ default=None,
1655
+ help="The entity to use. Defaults to current logged-in user",
1656
+ )
1657
+ @click.option(
1658
+ "--log-file",
1659
+ "-l",
1660
+ default=None,
1661
+ help=(
1662
+ "Destination for internal agent logs. Use - for stdout. "
1663
+ "By default all agents logs will go to debug.log in your wandb/ "
1664
+ "subdirectory or WANDB_DIR if set."
1665
+ ),
1666
+ )
1667
+ @click.option(
1668
+ "--max-jobs",
1669
+ "-j",
1670
+ default=None,
1671
+ help="The maximum number of launch jobs this agent can run in parallel. Defaults to 1. Set to -1 for no upper limit",
1672
+ )
1673
+ @click.option(
1674
+ "--config", "-c", default=None, help="path to the agent config yaml to use"
1675
+ )
1676
+ @click.option(
1677
+ "--url",
1678
+ "-u",
1679
+ default=None,
1680
+ hidden=True,
1681
+ help="a wandb client registration URL, this is generated in the UI",
1682
+ )
1683
+ @click.option("--verbose", "-v", count=True, help="Display verbose output")
1684
+ @display_error
1685
+ def launch_agent(
1686
+ ctx,
1687
+ project=None,
1688
+ entity=None,
1689
+ queues=None,
1690
+ max_jobs=None,
1691
+ config=None,
1692
+ url=None,
1693
+ log_file=None,
1694
+ verbose=0,
1695
+ ):
1696
+ logger.info(
1697
+ f"=== Launch-agent called with kwargs {locals()} CLI Version: {wandb.__version__} ==="
1698
+ )
1699
+ if url is not None:
1700
+ raise LaunchError(
1701
+ "--url is not supported in this version, upgrade with: pip install -u wandb"
1702
+ )
1703
+
1704
+ import wandb.sdk.launch._launch as _launch
1705
+
1706
+ if log_file is not None:
1707
+ _launch.set_launch_logfile(log_file)
1708
+
1709
+ api = _get_cling_api()
1710
+ wandb._sentry.configure_scope(process_context="launch_agent")
1711
+ agent_config, api = _launch.resolve_agent_config(
1712
+ entity, project, max_jobs, queues, config, verbose
1713
+ )
1714
+
1715
+ if len(agent_config.get("queues")) == 0:
1716
+ raise LaunchError(
1717
+ "To launch an agent please specify a queue or a list of queues in the configuration file or cli."
1718
+ )
1719
+
1720
+ launch_utils.check_logged_in(api)
1721
+
1722
+ wandb.termlog("Starting launch agent ✨")
1723
+ try:
1724
+ _launch.create_and_run_agent(api, agent_config)
1725
+ except Exception as e:
1726
+ wandb._sentry.exception(e)
1727
+ raise e
1728
+
1729
+
1730
+ @cli.command(context_settings=CONTEXT, help="Run the W&B agent")
1731
+ @click.pass_context
1732
+ @click.option(
1733
+ "--project",
1734
+ "-p",
1735
+ default=None,
1736
+ help="""The name of the project where W&B runs created from the sweep are sent to. If the project is not specified, the run is sent to a project labeled 'Uncategorized'.""",
1737
+ )
1738
+ @click.option(
1739
+ "--entity",
1740
+ "-e",
1741
+ default=None,
1742
+ help="""The username or team name where you want to send W&B runs created by the sweep to. Ensure that the entity you specify already exists. If you don't specify an entity, the run will be sent to your default entity, which is usually your username.""",
1743
+ )
1744
+ @click.option(
1745
+ "--count", default=None, type=int, help="The max number of runs for this agent."
1746
+ )
1747
+ @click.argument("sweep_id")
1748
+ @display_error
1749
+ def agent(ctx, project, entity, count, sweep_id):
1750
+ api = _get_cling_api()
1751
+ if api.api_key is None:
1752
+ wandb.termlog("Login to W&B to use the sweep agent feature")
1753
+ ctx.invoke(login, no_offline=True)
1754
+ api = _get_cling_api(reset=True)
1755
+
1756
+ wandb.termlog("Starting wandb agent 🕵️")
1757
+ wandb_agent.agent(sweep_id, entity=entity, project=project, count=count)
1758
+
1759
+ # you can send local commands like so:
1760
+ # agent_api.command({'type': 'run', 'program': 'train.py',
1761
+ # 'args': ['--max_epochs=10']})
1762
+
1763
+
1764
+ @cli.command(
1765
+ context_settings=RUN_CONTEXT, help="Run a W&B launch sweep scheduler (Experimental)"
1766
+ )
1767
+ @click.pass_context
1768
+ @click.argument("sweep_id")
1769
+ @display_error
1770
+ def scheduler(
1771
+ ctx,
1772
+ sweep_id,
1773
+ ):
1774
+ api = InternalApi()
1775
+ if api.api_key is None:
1776
+ wandb.termlog("Login to W&B to use the sweep scheduler feature")
1777
+ ctx.invoke(login, no_offline=True)
1778
+ api = InternalApi(reset=True)
1779
+
1780
+ wandb._sentry.configure_scope(process_context="sweep_scheduler")
1781
+ wandb.termlog("Starting a Launch Scheduler 🚀")
1782
+ from wandb.sdk.launch.sweeps import load_scheduler
1783
+
1784
+ # TODO(gst): remove this monstrosity
1785
+ # Future-proofing hack to pull any kwargs that get passed in through the CLI
1786
+ kwargs = {}
1787
+ for i, _arg in enumerate(ctx.args):
1788
+ if isinstance(_arg, str) and _arg.startswith("--"):
1789
+ # convert input kwargs from hyphens to underscores
1790
+ _key = _arg[2:].replace("-", "_")
1791
+ _args = ctx.args[i + 1]
1792
+ if str.isdigit(_args):
1793
+ _args = int(_args)
1794
+ kwargs[_key] = _args
1795
+ try:
1796
+ sweep_type = kwargs.get("sweep_type", "wandb")
1797
+ _scheduler = load_scheduler(scheduler_type=sweep_type)(
1798
+ api,
1799
+ sweep_id=sweep_id,
1800
+ **kwargs,
1801
+ )
1802
+ _scheduler.start()
1803
+ except Exception as e:
1804
+ wandb._sentry.exception(e)
1805
+ raise e
1806
+
1807
+
1808
+ @cli.group(help="Commands for managing and viewing W&B jobs")
1809
+ def job() -> None:
1810
+ pass
1811
+
1812
+
1813
+ @job.command("list", help="List jobs in a project")
1814
+ @click.option(
1815
+ "--project",
1816
+ "-p",
1817
+ envvar=env.PROJECT,
1818
+ help="The project you want to list jobs from.",
1819
+ )
1820
+ @click.option(
1821
+ "--entity",
1822
+ "-e",
1823
+ default="models",
1824
+ envvar=env.ENTITY,
1825
+ help="The entity the jobs belong to",
1826
+ )
1827
+ def _list(project, entity):
1828
+ wandb.termlog(f"Listing jobs in {entity}/{project}")
1829
+ public_api = PublicApi()
1830
+ try:
1831
+ jobs = public_api.list_jobs(entity=entity, project=project)
1832
+ except wandb.errors.CommError as e:
1833
+ wandb.termerror(f"{e}")
1834
+ return
1835
+
1836
+ if len(jobs) == 0:
1837
+ wandb.termlog("No jobs found")
1838
+ return
1839
+
1840
+ for job in jobs:
1841
+ aliases = []
1842
+ if len(job["edges"]) == 0:
1843
+ # deleted?
1844
+ continue
1845
+
1846
+ name = job["edges"][0]["node"]["artifactSequence"]["name"]
1847
+ for version in job["edges"]:
1848
+ aliases += [x["alias"] for x in version["node"]["aliases"]]
1849
+
1850
+ # only list the most recent 10 job versions
1851
+ aliases_str = ",".join(aliases[::-1])
1852
+ wandb.termlog(f"{name} -- versions ({len(aliases)}): {aliases_str}")
1853
+
1854
+
1855
+ @job.command(
1856
+ help="Describe a launch job. Provide the launch job in the form of: entity/project/job-name:alias-or-version"
1857
+ )
1858
+ @click.argument("job")
1859
+ def describe(job):
1860
+ public_api = PublicApi()
1861
+ try:
1862
+ job = public_api.job(name=job)
1863
+ except wandb.errors.CommError as e:
1864
+ wandb.termerror(f"{e}")
1865
+ return
1866
+
1867
+ for key in job._job_info:
1868
+ if key.startswith("_"):
1869
+ continue
1870
+ wandb.termlog(f"{key}: {job._job_info[key]}")
1871
+
1872
+
1873
+ @job.command(
1874
+ no_args_is_help=True,
1875
+ )
1876
+ @click.option(
1877
+ "--project",
1878
+ "-p",
1879
+ envvar=env.PROJECT,
1880
+ help="The project you want to list jobs from.",
1881
+ )
1882
+ @click.option(
1883
+ "--entity",
1884
+ "-e",
1885
+ envvar=env.ENTITY,
1886
+ help="The entity the jobs belong to",
1887
+ )
1888
+ @click.option(
1889
+ "--name",
1890
+ "-n",
1891
+ help="Name for the job",
1892
+ )
1893
+ @click.option(
1894
+ "--description",
1895
+ "-d",
1896
+ help="Description for the job",
1897
+ )
1898
+ @click.option(
1899
+ "--alias",
1900
+ "-a",
1901
+ "aliases",
1902
+ help="Alias for the job",
1903
+ multiple=True,
1904
+ default=tuple(),
1905
+ )
1906
+ @click.option(
1907
+ "--entry-point",
1908
+ "-E",
1909
+ "entrypoint",
1910
+ help="Entrypoint to the script, including an executable and an entrypoint file. Required for code or repo jobs",
1911
+ )
1912
+ @click.option(
1913
+ "--git-hash",
1914
+ "-g",
1915
+ "git_hash",
1916
+ type=str,
1917
+ help="Hash to a specific git commit.",
1918
+ )
1919
+ @click.option(
1920
+ "--runtime",
1921
+ "-r",
1922
+ type=str,
1923
+ help="Python runtime to execute the job",
1924
+ )
1925
+ @click.argument(
1926
+ "job_type",
1927
+ type=click.Choice(("git", "code", "image")),
1928
+ )
1929
+ @click.argument("path")
1930
+ def create(
1931
+ path,
1932
+ project,
1933
+ entity,
1934
+ name,
1935
+ job_type,
1936
+ description,
1937
+ aliases,
1938
+ entrypoint,
1939
+ git_hash,
1940
+ runtime,
1941
+ ):
1942
+ """Create a job from a source, without a wandb run.
1943
+
1944
+ Jobs can be of three types, git, code, or image.
1945
+
1946
+ git: A git source, with an entrypoint either in the path or provided explicitly pointing to the main python executable.
1947
+ code: A code path, containing a requirements.txt file.
1948
+ image: A docker image.
1949
+ """
1950
+ from wandb.sdk.launch.create_job import _create_job
1951
+
1952
+ api = _get_cling_api()
1953
+ wandb._sentry.configure_scope(process_context="job_create")
1954
+
1955
+ entity = entity or os.getenv("WANDB_ENTITY") or api.default_entity
1956
+ if not entity:
1957
+ wandb.termerror("No entity provided, use --entity or set WANDB_ENTITY")
1958
+ return
1959
+
1960
+ project = project or os.getenv("WANDB_PROJECT")
1961
+ if not project:
1962
+ wandb.termerror("No project provided, use --project or set WANDB_PROJECT")
1963
+ return
1964
+
1965
+ if entrypoint is None and job_type in ["git", "code"]:
1966
+ wandb.termwarn(
1967
+ f"No entrypoint provided for {job_type} job, defaulting to main.py"
1968
+ )
1969
+ entrypoint = "main.py"
1970
+
1971
+ artifact, action, aliases = _create_job(
1972
+ api=api,
1973
+ path=path,
1974
+ entity=entity,
1975
+ project=project,
1976
+ name=name,
1977
+ job_type=job_type,
1978
+ description=description,
1979
+ aliases=list(aliases),
1980
+ entrypoint=entrypoint,
1981
+ git_hash=git_hash,
1982
+ runtime=runtime,
1983
+ )
1984
+ if not artifact:
1985
+ wandb.termerror("Job creation failed")
1986
+ return
1987
+
1988
+ artifact_path = f"{entity}/{project}/{artifact.name}"
1989
+ msg = f"{action} job: {click.style(artifact_path, fg='yellow')}"
1990
+ if len(aliases) == 1:
1991
+ alias_str = click.style(aliases[0], fg="yellow")
1992
+ msg += f", with alias: {alias_str}"
1993
+ elif len(aliases) > 1:
1994
+ alias_str = click.style(", ".join(aliases), fg="yellow")
1995
+ msg += f", with aliases: {alias_str}"
1996
+
1997
+ wandb.termlog(msg)
1998
+ web_url = util.app_url(api.settings().get("base_url"))
1999
+ url = click.style(f"{web_url}/{entity}/{project}/jobs", underline=True)
2000
+ wandb.termlog(f"View all jobs in project '{project}' here: {url}\n")
2001
+
2002
+
2003
+ @cli.command(context_settings=CONTEXT, help="Run the W&B local sweep controller")
2004
+ @click.option("--verbose", is_flag=True, default=False, help="Display verbose output")
2005
+ @click.argument("sweep_id")
2006
+ @display_error
2007
+ def controller(verbose, sweep_id):
2008
+ click.echo("Starting wandb controller...")
2009
+ from wandb import controller as wandb_controller
2010
+
2011
+ tuner = wandb_controller(sweep_id)
2012
+ tuner.run(verbose=verbose)
2013
+
2014
+
2015
+ @cli.command(context_settings=RUN_CONTEXT, name="docker-run")
2016
+ @click.pass_context
2017
+ @click.argument("docker_run_args", nargs=-1)
2018
+ def docker_run(ctx, docker_run_args):
2019
+ """Wrap `docker run` and adds WANDB_API_KEY and WANDB_DOCKER environment variables.
2020
+
2021
+ This will also set the runtime to nvidia if the nvidia-docker executable is present
2022
+ on the system and --runtime wasn't set.
2023
+
2024
+ See `docker run --help` for more details.
2025
+ """
2026
+ api = InternalApi()
2027
+ args = list(docker_run_args)
2028
+ if len(args) > 0 and args[0] == "run":
2029
+ args.pop(0)
2030
+ if len([a for a in args if a.startswith("--runtime")]) == 0 and find_executable(
2031
+ "nvidia-docker"
2032
+ ):
2033
+ args = ["--runtime", "nvidia"] + args
2034
+ # TODO: image_from_docker_args uses heuristics to find the docker image arg, there are likely cases
2035
+ # where this won't work
2036
+ image = util.image_from_docker_args(args)
2037
+ resolved_image = None
2038
+ if image:
2039
+ resolved_image = wandb.docker.image_id(image)
2040
+ if resolved_image:
2041
+ args = ["-e", "WANDB_DOCKER=%s" % resolved_image] + args
2042
+ else:
2043
+ wandb.termlog(
2044
+ "Couldn't detect image argument, running command without the WANDB_DOCKER env variable"
2045
+ )
2046
+ if api.api_key:
2047
+ args = ["-e", "WANDB_API_KEY=%s" % api.api_key] + args
2048
+ else:
2049
+ wandb.termlog(
2050
+ "Not logged in, run `wandb login` from the host machine to enable result logging"
2051
+ )
2052
+ subprocess.call(["docker", "run"] + args)
2053
+
2054
+
2055
+ @cli.command(context_settings=RUN_CONTEXT)
2056
+ @click.pass_context
2057
+ @click.argument("docker_run_args", nargs=-1)
2058
+ @click.argument("docker_image", required=False)
2059
+ @click.option(
2060
+ "--nvidia/--no-nvidia",
2061
+ default=find_executable("nvidia-docker") is not None,
2062
+ help="Use the nvidia runtime, defaults to nvidia if nvidia-docker is present",
2063
+ )
2064
+ @click.option(
2065
+ "--digest", is_flag=True, default=False, help="Output the image digest and exit"
2066
+ )
2067
+ @click.option(
2068
+ "--jupyter/--no-jupyter", default=False, help="Run jupyter lab in the container"
2069
+ )
2070
+ @click.option(
2071
+ "--dir", default="/app", help="Which directory to mount the code in the container"
2072
+ )
2073
+ @click.option("--no-dir", is_flag=True, help="Don't mount the current directory")
2074
+ @click.option(
2075
+ "--shell", default="/bin/bash", help="The shell to start the container with"
2076
+ )
2077
+ @click.option("--port", default="8888", help="The host port to bind jupyter on")
2078
+ @click.option("--cmd", help="The command to run in the container")
2079
+ @click.option(
2080
+ "--no-tty", is_flag=True, default=False, help="Run the command without a tty"
2081
+ )
2082
+ @display_error
2083
+ def docker(
2084
+ ctx,
2085
+ docker_run_args,
2086
+ docker_image,
2087
+ nvidia,
2088
+ digest,
2089
+ jupyter,
2090
+ dir,
2091
+ no_dir,
2092
+ shell,
2093
+ port,
2094
+ cmd,
2095
+ no_tty,
2096
+ ):
2097
+ """Run your code in a docker container.
2098
+
2099
+ W&B docker lets you run your code in a docker image ensuring wandb is configured. It
2100
+ adds the WANDB_DOCKER and WANDB_API_KEY environment variables to your container and
2101
+ mounts the current directory in /app by default. You can pass additional args which
2102
+ will be added to `docker run` before the image name is declared, we'll choose a
2103
+ default image for you if one isn't passed:
2104
+
2105
+ ```sh
2106
+ wandb docker -v /mnt/dataset:/app/data
2107
+ wandb docker gcr.io/kubeflow-images-public/tensorflow-1.12.0-notebook-cpu:v0.4.0 --jupyter
2108
+ wandb docker wandb/deepo:keras-gpu --no-tty --cmd "python train.py --epochs=5"
2109
+ ```
2110
+
2111
+ By default, we override the entrypoint to check for the existence of wandb and
2112
+ install it if not present. If you pass the --jupyter flag we will ensure jupyter is
2113
+ installed and start jupyter lab on port 8888. If we detect nvidia-docker on your
2114
+ system we will use the nvidia runtime. If you just want wandb to set environment
2115
+ variable to an existing docker run command, see the wandb docker-run command.
2116
+ """
2117
+ api = InternalApi()
2118
+ if not find_executable("docker"):
2119
+ raise ClickException("Docker not installed, install it from https://docker.com")
2120
+ args = list(docker_run_args)
2121
+ image = docker_image or ""
2122
+ # remove run for users used to nvidia-docker
2123
+ if len(args) > 0 and args[0] == "run":
2124
+ args.pop(0)
2125
+ if image == "" and len(args) > 0:
2126
+ image = args.pop(0)
2127
+ # If the user adds docker args without specifying an image (should be rare)
2128
+ if not util.docker_image_regex(image.split("@")[0]):
2129
+ if image:
2130
+ args = args + [image]
2131
+ image = wandb.docker.default_image(gpu=nvidia)
2132
+ subprocess.call(["docker", "pull", image])
2133
+ _, repo_name, tag = wandb.docker.parse(image)
2134
+
2135
+ resolved_image = wandb.docker.image_id(image)
2136
+ if resolved_image is None:
2137
+ raise ClickException(
2138
+ "Couldn't find image locally or in a registry, try running `docker pull %s`"
2139
+ % image
2140
+ )
2141
+ if digest:
2142
+ sys.stdout.write(resolved_image)
2143
+ exit(0)
2144
+
2145
+ existing = wandb.docker.shell(["ps", "-f", "ancestor=%s" % resolved_image, "-q"])
2146
+ if existing:
2147
+ if click.confirm(
2148
+ "Found running container with the same image, do you want to attach?"
2149
+ ):
2150
+ subprocess.call(["docker", "attach", existing.split("\n")[0]])
2151
+ exit(0)
2152
+ cwd = os.getcwd()
2153
+ command = [
2154
+ "docker",
2155
+ "run",
2156
+ "-e",
2157
+ "LANG=C.UTF-8",
2158
+ "-e",
2159
+ "WANDB_DOCKER=%s" % resolved_image,
2160
+ "--ipc=host",
2161
+ "-v",
2162
+ wandb.docker.entrypoint + ":/wandb-entrypoint.sh",
2163
+ "--entrypoint",
2164
+ "/wandb-entrypoint.sh",
2165
+ ]
2166
+ if nvidia:
2167
+ command.extend(["--runtime", "nvidia"])
2168
+ if not no_dir:
2169
+ # TODO: We should default to the working directory if defined
2170
+ command.extend(["-v", cwd + ":" + dir, "-w", dir])
2171
+ if api.api_key:
2172
+ command.extend(["-e", "WANDB_API_KEY=%s" % api.api_key])
2173
+ else:
2174
+ wandb.termlog(
2175
+ "Couldn't find WANDB_API_KEY, run `wandb login` to enable streaming metrics"
2176
+ )
2177
+ if jupyter:
2178
+ command.extend(["-e", "WANDB_ENSURE_JUPYTER=1", "-p", port + ":8888"])
2179
+ no_tty = True
2180
+ cmd = (
2181
+ "jupyter lab --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --notebook-dir %s"
2182
+ % dir
2183
+ )
2184
+ command.extend(args)
2185
+ if no_tty:
2186
+ command.extend([image, shell, "-c", cmd])
2187
+ else:
2188
+ if cmd:
2189
+ command.extend(["-e", "WANDB_COMMAND=%s" % cmd])
2190
+ command.extend(["-it", image, shell])
2191
+ wandb.termlog("Launching docker container \U0001f6a2")
2192
+ subprocess.call(command)
2193
+
2194
+
2195
+ @cli.command(
2196
+ context_settings=RUN_CONTEXT,
2197
+ help="Start a local W&B container (deprecated, see wandb server --help)",
2198
+ hidden=True,
2199
+ )
2200
+ @click.pass_context
2201
+ @click.option("--port", "-p", default="8080", help="The host port to bind W&B local on")
2202
+ @click.option(
2203
+ "--env", "-e", default=[], multiple=True, help="Env vars to pass to wandb/local"
2204
+ )
2205
+ @click.option(
2206
+ "--daemon/--no-daemon", default=True, help="Run or don't run in daemon mode"
2207
+ )
2208
+ @click.option(
2209
+ "--upgrade", is_flag=True, default=False, help="Upgrade to the most recent version"
2210
+ )
2211
+ @click.option(
2212
+ "--edge", is_flag=True, default=False, help="Run the bleeding edge", hidden=True
2213
+ )
2214
+ @display_error
2215
+ def local(ctx, *args, **kwargs):
2216
+ wandb.termwarn("`wandb local` has been replaced with `wandb server start`.")
2217
+ ctx.invoke(start, *args, **kwargs)
2218
+
2219
+
2220
+ @cli.group(help="Commands for operating a local W&B server")
2221
+ def server():
2222
+ pass
2223
+
2224
+
2225
+ @server.command(context_settings=RUN_CONTEXT, help="Start a local W&B server")
2226
+ @click.pass_context
2227
+ @click.option(
2228
+ "--port", "-p", default="8080", help="The host port to bind W&B server on"
2229
+ )
2230
+ @click.option(
2231
+ "--env", "-e", default=[], multiple=True, help="Env vars to pass to wandb/local"
2232
+ )
2233
+ @click.option(
2234
+ "--daemon/--no-daemon", default=True, help="Run or don't run in daemon mode"
2235
+ )
2236
+ @click.option(
2237
+ "--upgrade",
2238
+ is_flag=True,
2239
+ default=False,
2240
+ help="Upgrade to the most recent version",
2241
+ hidden=True,
2242
+ )
2243
+ @click.option(
2244
+ "--edge", is_flag=True, default=False, help="Run the bleeding edge", hidden=True
2245
+ )
2246
+ @display_error
2247
+ def start(ctx, port, env, daemon, upgrade, edge):
2248
+ api = InternalApi()
2249
+ if not find_executable("docker"):
2250
+ raise ClickException("Docker not installed, install it from https://docker.com")
2251
+ local_image_sha = wandb.docker.image_id("wandb/local").split("wandb/local")[-1]
2252
+ registry_image_sha = wandb.docker.image_id_from_registry("wandb/local").split(
2253
+ "wandb/local"
2254
+ )[-1]
2255
+ if local_image_sha != registry_image_sha:
2256
+ if upgrade:
2257
+ subprocess.call(["docker", "pull", "wandb/local"])
2258
+ else:
2259
+ wandb.termlog(
2260
+ "A new version of the W&B server is available, upgrade by calling `wandb server start --upgrade`"
2261
+ )
2262
+ running = subprocess.check_output(
2263
+ ["docker", "ps", "--filter", "name=wandb-local", "--format", "{{.ID}}"]
2264
+ )
2265
+ if running != b"":
2266
+ if upgrade:
2267
+ subprocess.call(["docker", "stop", "wandb-local"])
2268
+ else:
2269
+ wandb.termerror(
2270
+ "A container named wandb-local is already running, run `docker stop wandb-local` if you want to start a new instance"
2271
+ )
2272
+ exit(1)
2273
+ image = "docker.pkg.github.com/wandb/core/local" if edge else "wandb/local"
2274
+ username = getpass.getuser()
2275
+ env_vars = ["-e", "LOCAL_USERNAME=%s" % username]
2276
+ for e in env:
2277
+ env_vars.append("-e")
2278
+ env_vars.append(e)
2279
+ command = [
2280
+ "docker",
2281
+ "run",
2282
+ "--rm",
2283
+ "-v",
2284
+ "wandb:/vol",
2285
+ "-p",
2286
+ port + ":8080",
2287
+ "--name",
2288
+ "wandb-local",
2289
+ ] + env_vars
2290
+ host = f"http://localhost:{port}"
2291
+ api.set_setting("base_url", host, globally=True, persist=True)
2292
+ if daemon:
2293
+ command += ["-d"]
2294
+ command += [image]
2295
+
2296
+ # DEVNULL is only in py3
2297
+ try:
2298
+ from subprocess import DEVNULL
2299
+ except ImportError:
2300
+ DEVNULL = open(os.devnull, "wb") # noqa: N806
2301
+ code = subprocess.call(command, stdout=DEVNULL)
2302
+ if daemon:
2303
+ if code != 0:
2304
+ wandb.termerror(
2305
+ "Failed to launch the W&B server container, see the above error."
2306
+ )
2307
+ exit(1)
2308
+ else:
2309
+ wandb.termlog("W&B server started at http://localhost:%s \U0001f680" % port)
2310
+ wandb.termlog("You can stop the server by running `wandb server stop`")
2311
+ if not api.api_key:
2312
+ # Let the server start before potentially launching a browser
2313
+ time.sleep(2)
2314
+ ctx.invoke(login, host=host)
2315
+
2316
+
2317
+ @server.command(context_settings=RUN_CONTEXT, help="Stop a local W&B server")
2318
+ def stop():
2319
+ if not find_executable("docker"):
2320
+ raise ClickException("Docker not installed, install it from https://docker.com")
2321
+ subprocess.call(["docker", "stop", "wandb-local"])
2322
+
2323
+
2324
+ @cli.group(help="Commands for interacting with artifacts")
2325
+ def artifact():
2326
+ pass
2327
+
2328
+
2329
+ @artifact.command(context_settings=CONTEXT, help="Upload an artifact to wandb")
2330
+ @click.argument("path")
2331
+ @click.option(
2332
+ "--name", "-n", help="The name of the artifact to push: project/artifact_name"
2333
+ )
2334
+ @click.option("--description", "-d", help="A description of this artifact")
2335
+ @click.option("--type", "-t", default="dataset", help="The type of the artifact")
2336
+ @click.option(
2337
+ "--alias",
2338
+ "-a",
2339
+ default=["latest"],
2340
+ multiple=True,
2341
+ help="An alias to apply to this artifact",
2342
+ )
2343
+ @click.option("--id", "run_id", help="The run you want to upload to.")
2344
+ @click.option(
2345
+ "--resume",
2346
+ is_flag=True,
2347
+ default=None,
2348
+ help="Resume the last run from your current directory.",
2349
+ )
2350
+ @click.option(
2351
+ "--skip_cache",
2352
+ is_flag=True,
2353
+ default=False,
2354
+ help="Skip caching while uploading artifact files.",
2355
+ )
2356
+ @click.option(
2357
+ "--policy",
2358
+ default="mutable",
2359
+ type=click.Choice(["mutable", "immutable"]),
2360
+ help="Set the storage policy while uploading artifact files.",
2361
+ )
2362
+ @display_error
2363
+ def put(
2364
+ path,
2365
+ name,
2366
+ description,
2367
+ type,
2368
+ alias,
2369
+ run_id,
2370
+ resume,
2371
+ skip_cache,
2372
+ policy,
2373
+ ):
2374
+ if name is None:
2375
+ name = os.path.basename(path)
2376
+ public_api = PublicApi()
2377
+ entity, project, artifact_name = public_api._parse_artifact_path(name)
2378
+ if project is None:
2379
+ project = click.prompt("Enter the name of the project you want to use")
2380
+ # TODO: settings nightmare...
2381
+ api = InternalApi()
2382
+ api.set_setting("entity", entity)
2383
+ api.set_setting("project", project)
2384
+ artifact = wandb.Artifact(name=artifact_name, type=type, description=description)
2385
+ artifact_path = f"{entity}/{project}/{artifact_name}:{alias[0]}"
2386
+ if os.path.isdir(path):
2387
+ wandb.termlog(f'Uploading directory {path} to: "{artifact_path}" ({type})')
2388
+ artifact.add_dir(path, skip_cache=skip_cache, policy=policy)
2389
+ elif os.path.isfile(path):
2390
+ wandb.termlog(f'Uploading file {path} to: "{artifact_path}" ({type})')
2391
+ artifact.add_file(path, skip_cache=skip_cache, policy=policy)
2392
+ elif "://" in path:
2393
+ wandb.termlog(
2394
+ f'Logging reference artifact from {path} to: "{artifact_path}" ({type})'
2395
+ )
2396
+ artifact.add_reference(path)
2397
+ else:
2398
+ raise ClickException("Path argument must be a file or directory")
2399
+
2400
+ with wandb.init(
2401
+ entity=entity,
2402
+ project=project,
2403
+ config={"path": path},
2404
+ job_type="cli_put",
2405
+ id=run_id,
2406
+ resume=resume,
2407
+ ) as run:
2408
+ run.log_artifact(artifact, aliases=alias)
2409
+ artifact.wait()
2410
+
2411
+ wandb.termlog(
2412
+ "Artifact uploaded, use this artifact in a run by adding:\n", prefix=False
2413
+ )
2414
+ wandb.termlog(
2415
+ f' artifact = run.use_artifact("{artifact.source_qualified_name}")\n',
2416
+ prefix=False,
2417
+ )
2418
+
2419
+
2420
+ @artifact.command(context_settings=CONTEXT, help="Download an artifact from wandb")
2421
+ @click.argument("path")
2422
+ @click.option("--root", help="The directory you want to download the artifact to")
2423
+ @click.option("--type", help="The type of artifact you are downloading")
2424
+ @display_error
2425
+ def get(path, root, type):
2426
+ public_api = PublicApi()
2427
+ entity, project, artifact_name = public_api._parse_artifact_path(path)
2428
+ if project is None:
2429
+ project = click.prompt("Enter the name of the project you want to use")
2430
+
2431
+ try:
2432
+ artifact_parts = artifact_name.split(":")
2433
+ if len(artifact_parts) > 1:
2434
+ version = artifact_parts[1]
2435
+ artifact_name = artifact_parts[0]
2436
+ else:
2437
+ version = "latest"
2438
+ full_path = f"{entity}/{project}/{artifact_name}:{version}"
2439
+ wandb.termlog(
2440
+ "Downloading {type} artifact {full_path}".format(
2441
+ type=type or "dataset", full_path=full_path
2442
+ )
2443
+ )
2444
+ artifact = public_api.artifact(full_path, type=type)
2445
+ path = artifact.download(root=root)
2446
+ wandb.termlog("Artifact downloaded to %s" % path)
2447
+ except ValueError:
2448
+ raise ClickException("Unable to download artifact")
2449
+
2450
+
2451
+ @artifact.command(
2452
+ context_settings=CONTEXT, help="List all artifacts in a wandb project"
2453
+ )
2454
+ @click.argument("path")
2455
+ @click.option("--type", "-t", help="The type of artifacts to list")
2456
+ @display_error
2457
+ def ls(path, type):
2458
+ public_api = PublicApi()
2459
+ if type is not None:
2460
+ types = [public_api.artifact_type(type, path)]
2461
+ else:
2462
+ types = public_api.artifact_types(path)
2463
+
2464
+ for kind in types:
2465
+ for collection in kind.collections():
2466
+ versions = public_api.artifact_versions(
2467
+ kind.type,
2468
+ "/".join([kind.entity, kind.project, collection.name]),
2469
+ per_page=1,
2470
+ )
2471
+ latest = next(versions)
2472
+ print(
2473
+ "{:<15s}{:<15s}{:>15s} {:<20s}".format(
2474
+ kind.type,
2475
+ latest.updated_at,
2476
+ util.to_human_size(latest.size),
2477
+ latest.name,
2478
+ )
2479
+ )
2480
+
2481
+
2482
+ @artifact.group(help="Commands for interacting with the artifact cache")
2483
+ def cache():
2484
+ pass
2485
+
2486
+
2487
+ @cache.command(
2488
+ context_settings=CONTEXT,
2489
+ help="Clean up less frequently used files from the artifacts cache",
2490
+ )
2491
+ @click.argument("target_size")
2492
+ @click.option("--remove-temp/--no-remove-temp", default=False, help="Remove temp files")
2493
+ @display_error
2494
+ def cleanup(target_size, remove_temp):
2495
+ target_size = util.from_human_size(target_size)
2496
+ cache = get_artifact_file_cache()
2497
+ reclaimed_bytes = cache.cleanup(target_size, remove_temp)
2498
+ print(f"Reclaimed {util.to_human_size(reclaimed_bytes)} of space")
2499
+
2500
+
2501
+ @cli.command(context_settings=CONTEXT, help="Pull files from Weights & Biases")
2502
+ @click.argument("run", envvar=env.RUN_ID)
2503
+ @click.option(
2504
+ "--project", "-p", envvar=env.PROJECT, help="The project you want to download."
2505
+ )
2506
+ @click.option(
2507
+ "--entity",
2508
+ "-e",
2509
+ default="models",
2510
+ envvar=env.ENTITY,
2511
+ help="The entity to scope the listing to.",
2512
+ )
2513
+ @display_error
2514
+ def pull(run, project, entity):
2515
+ api = InternalApi()
2516
+ project, run = api.parse_slug(run, project=project)
2517
+ urls = api.download_urls(project, run=run, entity=entity)
2518
+ if len(urls) == 0:
2519
+ raise ClickException("Run has no files")
2520
+ click.echo(f"Downloading: {click.style(project, bold=True)}/{run}")
2521
+
2522
+ for name in urls:
2523
+ if api.file_current(name, urls[name]["md5"]):
2524
+ click.echo("File %s is up to date" % name)
2525
+ else:
2526
+ length, response = api.download_file(urls[name]["url"])
2527
+ # TODO: I had to add this because some versions in CI broke click.progressbar
2528
+ sys.stdout.write("File %s\r" % name)
2529
+ dirname = os.path.dirname(name)
2530
+ if dirname != "":
2531
+ filesystem.mkdir_exists_ok(dirname)
2532
+ with click.progressbar(
2533
+ length=length,
2534
+ label="File %s" % name,
2535
+ fill_char=click.style("&", fg="green"),
2536
+ ) as bar:
2537
+ with open(name, "wb") as f:
2538
+ for data in response.iter_content(chunk_size=4096):
2539
+ f.write(data)
2540
+ bar.update(len(data))
2541
+
2542
+
2543
+ @cli.command(
2544
+ context_settings=CONTEXT, help="Restore code, config and docker state for a run"
2545
+ )
2546
+ @click.pass_context
2547
+ @click.argument("run", envvar=env.RUN_ID)
2548
+ @click.option("--no-git", is_flag=True, default=False, help="Don't restore git state")
2549
+ @click.option(
2550
+ "--branch/--no-branch",
2551
+ default=True,
2552
+ help="Whether to create a branch or checkout detached",
2553
+ )
2554
+ @click.option(
2555
+ "--project", "-p", envvar=env.PROJECT, help="The project you wish to upload to."
2556
+ )
2557
+ @click.option(
2558
+ "--entity", "-e", envvar=env.ENTITY, help="The entity to scope the listing to."
2559
+ )
2560
+ @display_error
2561
+ def restore(ctx, run, no_git, branch, project, entity):
2562
+ from wandb.old.core import wandb_dir
2563
+
2564
+ api = _get_cling_api()
2565
+ if ":" in run:
2566
+ if "/" in run:
2567
+ entity, rest = run.split("/", 1)
2568
+ else:
2569
+ rest = run
2570
+ project, run = rest.split(":", 1)
2571
+ elif run.count("/") > 1:
2572
+ entity, run = run.split("/", 1)
2573
+
2574
+ project, run = api.parse_slug(run, project=project)
2575
+ commit, json_config, patch_content, metadata = api.run_config(
2576
+ project, run=run, entity=entity
2577
+ )
2578
+ repo = metadata.get("git", {}).get("repo")
2579
+ image = metadata.get("docker")
2580
+ restore_message = (
2581
+ """`wandb restore` needs to be run from the same git repository as the original run.
2582
+ Run `git clone %s` and restore from there or pass the --no-git flag."""
2583
+ % repo
2584
+ )
2585
+ if no_git:
2586
+ commit = None
2587
+ elif not api.git.enabled:
2588
+ if repo:
2589
+ raise ClickException(restore_message)
2590
+ elif image:
2591
+ wandb.termlog(
2592
+ "Original run has no git history. Just restoring config and docker"
2593
+ )
2594
+
2595
+ if commit and api.git.enabled:
2596
+ wandb.termlog(f"Fetching origin and finding commit: {commit}")
2597
+ subprocess.check_call(["git", "fetch", "--all"])
2598
+ try:
2599
+ api.git.repo.commit(commit)
2600
+ except ValueError:
2601
+ wandb.termlog(f"Couldn't find original commit: {commit}")
2602
+ commit = None
2603
+ files = api.download_urls(project, run=run, entity=entity)
2604
+ for filename in files:
2605
+ if filename.startswith("upstream_diff_") and filename.endswith(
2606
+ ".patch"
2607
+ ):
2608
+ commit = filename[len("upstream_diff_") : -len(".patch")]
2609
+ try:
2610
+ api.git.repo.commit(commit)
2611
+ except ValueError:
2612
+ commit = None
2613
+ else:
2614
+ break
2615
+
2616
+ if commit:
2617
+ wandb.termlog(f"Falling back to upstream commit: {commit}")
2618
+ patch_path, _ = api.download_write_file(files[filename])
2619
+ else:
2620
+ raise ClickException(restore_message)
2621
+ else:
2622
+ if patch_content:
2623
+ patch_path = os.path.join(wandb_dir(), "diff.patch")
2624
+ with open(patch_path, "w") as f:
2625
+ f.write(patch_content)
2626
+ else:
2627
+ patch_path = None
2628
+
2629
+ branch_name = "wandb/%s" % run
2630
+ if branch and branch_name not in api.git.repo.branches:
2631
+ api.git.repo.git.checkout(commit, b=branch_name)
2632
+ wandb.termlog("Created branch %s" % click.style(branch_name, bold=True))
2633
+ elif branch:
2634
+ wandb.termlog(
2635
+ "Using existing branch, run `git branch -D %s` from master for a clean checkout"
2636
+ % branch_name
2637
+ )
2638
+ api.git.repo.git.checkout(branch_name)
2639
+ else:
2640
+ wandb.termlog("Checking out %s in detached mode" % commit)
2641
+ api.git.repo.git.checkout(commit)
2642
+
2643
+ if patch_path:
2644
+ # we apply the patch from the repository root so git doesn't exclude
2645
+ # things outside the current directory
2646
+ root = api.git.root
2647
+ patch_rel_path = os.path.relpath(patch_path, start=root)
2648
+ # --reject is necessary or else this fails any time a binary file
2649
+ # occurs in the diff
2650
+ exit_code = subprocess.call(
2651
+ ["git", "apply", "--reject", patch_rel_path], cwd=root
2652
+ )
2653
+ if exit_code == 0:
2654
+ wandb.termlog("Applied patch")
2655
+ else:
2656
+ wandb.termerror(
2657
+ "Failed to apply patch, try un-staging any un-committed changes"
2658
+ )
2659
+
2660
+ filesystem.mkdir_exists_ok(wandb_dir())
2661
+ config_path = os.path.join(wandb_dir(), "config.yaml")
2662
+ config = Config()
2663
+ for k, v in json_config.items():
2664
+ if k not in ("_wandb", "wandb_version"):
2665
+ config[k] = v
2666
+ s = b"wandb_version: 1"
2667
+ s += b"\n\n" + yaml.dump(
2668
+ config._as_dict(),
2669
+ Dumper=yaml.SafeDumper,
2670
+ default_flow_style=False,
2671
+ allow_unicode=True,
2672
+ encoding="utf-8",
2673
+ )
2674
+ s = s.decode("utf-8")
2675
+ with open(config_path, "w") as f:
2676
+ f.write(s)
2677
+
2678
+ wandb.termlog("Restored config variables to %s" % config_path)
2679
+ if image:
2680
+ if not metadata["program"].startswith("<") and metadata.get("args") is not None:
2681
+ # TODO: we may not want to default to python here.
2682
+ runner = util.find_runner(metadata["program"]) or ["python"]
2683
+ command = runner + [metadata["program"]] + metadata["args"]
2684
+ cmd = " ".join(command)
2685
+ else:
2686
+ wandb.termlog("Couldn't find original command, just restoring environment")
2687
+ cmd = None
2688
+ wandb.termlog("Docker image found, attempting to start")
2689
+ ctx.invoke(docker, docker_run_args=[image], cmd=cmd)
2690
+
2691
+ return commit, json_config, patch_content, repo, metadata
2692
+
2693
+
2694
+ @cli.command(context_settings=CONTEXT, help="Run any script with wandb", hidden=True)
2695
+ @click.pass_context
2696
+ @click.argument("program")
2697
+ @click.argument("args", nargs=-1)
2698
+ @display_error
2699
+ def magic(ctx, program, args):
2700
+ def magic_run(cmd, globals, locals):
2701
+ try:
2702
+ exec(cmd, globals, locals)
2703
+ finally:
2704
+ pass
2705
+
2706
+ sys.argv[:] = args
2707
+ sys.argv.insert(0, program)
2708
+ sys.path.insert(0, os.path.dirname(program))
2709
+ try:
2710
+ with open(program, "rb") as fp:
2711
+ code = compile(fp.read(), program, "exec")
2712
+ except OSError:
2713
+ click.echo(click.style("Could not launch program: %s" % program, fg="red"))
2714
+ sys.exit(1)
2715
+ globs = {
2716
+ "__file__": program,
2717
+ "__name__": "__main__",
2718
+ "__package__": None,
2719
+ "wandb_magic_install": magic_install,
2720
+ }
2721
+ prep = (
2722
+ """
2723
+ import __main__
2724
+ __main__.__file__ = "%s"
2725
+ wandb_magic_install()
2726
+ """
2727
+ % program
2728
+ )
2729
+ magic_run(prep, globs, None)
2730
+ magic_run(code, globs, None)
2731
+
2732
+
2733
+ @cli.command("online", help="Enable W&B sync")
2734
+ @display_error
2735
+ def online():
2736
+ api = InternalApi()
2737
+ try:
2738
+ api.clear_setting("disabled", persist=True)
2739
+ api.clear_setting("mode", persist=True)
2740
+ except configparser.Error:
2741
+ pass
2742
+ click.echo(
2743
+ "W&B online. Running your script from this directory will now sync to the cloud."
2744
+ )
2745
+
2746
+
2747
+ @cli.command("offline", help="Disable W&B sync")
2748
+ @display_error
2749
+ def offline():
2750
+ api = InternalApi()
2751
+ try:
2752
+ api.set_setting("disabled", "true", persist=True)
2753
+ api.set_setting("mode", "offline", persist=True)
2754
+ click.echo(
2755
+ "W&B offline. Running your script from this directory will only write metadata locally. Use wandb disabled to completely turn off W&B."
2756
+ )
2757
+ except configparser.Error:
2758
+ click.echo(
2759
+ "Unable to write config, copy and paste the following in your terminal to turn off W&B:\nexport WANDB_MODE=offline"
2760
+ )
2761
+
2762
+
2763
+ @cli.command("on", hidden=True)
2764
+ @click.pass_context
2765
+ @display_error
2766
+ def on(ctx):
2767
+ ctx.invoke(online)
2768
+
2769
+
2770
+ @cli.command("off", hidden=True)
2771
+ @click.pass_context
2772
+ @display_error
2773
+ def off(ctx):
2774
+ ctx.invoke(offline)
2775
+
2776
+
2777
+ @cli.command("status", help="Show configuration settings")
2778
+ @click.option(
2779
+ "--settings/--no-settings", help="Show the current settings", default=True
2780
+ )
2781
+ def status(settings):
2782
+ api = _get_cling_api()
2783
+ if settings:
2784
+ click.echo(click.style("Current Settings", bold=True))
2785
+ settings = api.settings()
2786
+ click.echo(
2787
+ json.dumps(settings, sort_keys=True, indent=2, separators=(",", ": "))
2788
+ )
2789
+
2790
+
2791
+ @cli.command("disabled", help="Disable W&B.")
2792
+ @click.option(
2793
+ "--service",
2794
+ is_flag=True,
2795
+ show_default=True,
2796
+ default=True,
2797
+ help="Disable W&B service",
2798
+ )
2799
+ def disabled(service):
2800
+ api = InternalApi()
2801
+ try:
2802
+ api.set_setting("mode", "disabled", persist=True)
2803
+ click.echo("W&B disabled.")
2804
+ os.environ[wandb.env._DISABLE_SERVICE] = str(service)
2805
+ except configparser.Error:
2806
+ click.echo(
2807
+ "Unable to write config, copy and paste the following in your terminal to turn off W&B:\nexport WANDB_MODE=disabled"
2808
+ )
2809
+
2810
+
2811
+ @cli.command("enabled", help="Enable W&B.")
2812
+ @click.option(
2813
+ "--service",
2814
+ is_flag=True,
2815
+ show_default=True,
2816
+ default=True,
2817
+ help="Enable W&B service",
2818
+ )
2819
+ def enabled(service):
2820
+ api = InternalApi()
2821
+ try:
2822
+ api.set_setting("mode", "online", persist=True)
2823
+ click.echo("W&B enabled.")
2824
+ os.environ[wandb.env._DISABLE_SERVICE] = str(not service)
2825
+ except configparser.Error:
2826
+ click.echo(
2827
+ "Unable to write config, copy and paste the following in your terminal to turn on W&B:\nexport WANDB_MODE=online"
2828
+ )
2829
+
2830
+
2831
+ @cli.command("gc", hidden=True, context_settings={"ignore_unknown_options": True})
2832
+ @click.argument("args", nargs=-1)
2833
+ def gc(args):
2834
+ click.echo(
2835
+ "`wandb gc` command has been removed. Use `wandb sync --clean` to clean up synced runs."
2836
+ )
2837
+
2838
+
2839
+ @cli.command(context_settings=CONTEXT, help="Verify your local instance")
2840
+ @click.option("--host", default=None, help="Test a specific instance of W&B")
2841
+ def verify(host):
2842
+ # TODO: (kdg) Build this all into a WandbVerify object, and clean this up.
2843
+ os.environ["WANDB_SILENT"] = "true"
2844
+ os.environ["WANDB_PROJECT"] = "verify"
2845
+ api = _get_cling_api()
2846
+ reinit = False
2847
+ if host is None:
2848
+ host = api.settings("base_url")
2849
+ print(f"Default host selected: {host}")
2850
+ # if the given host does not match the default host, re-run init
2851
+ elif host != api.settings("base_url"):
2852
+ reinit = True
2853
+
2854
+ tmp_dir = tempfile.mkdtemp()
2855
+ print(
2856
+ "Find detailed logs for this test at: {}".format(os.path.join(tmp_dir, "wandb"))
2857
+ )
2858
+ os.chdir(tmp_dir)
2859
+ os.environ["WANDB_BASE_URL"] = host
2860
+ wandb.login(host=host)
2861
+ if reinit:
2862
+ api = _get_cling_api(reset=True)
2863
+ if not wandb_verify.check_host(host):
2864
+ sys.exit(1)
2865
+ if not wandb_verify.check_logged_in(api, host):
2866
+ sys.exit(1)
2867
+ url_success, url = wandb_verify.check_graphql_put(api, host)
2868
+ large_post_success = wandb_verify.check_large_post()
2869
+ wandb_verify.check_secure_requests(
2870
+ api.settings("base_url"),
2871
+ "Checking requests to base url",
2872
+ "Connections are not made over https. SSL required for secure communications.",
2873
+ )
2874
+ if url:
2875
+ wandb_verify.check_secure_requests(
2876
+ url,
2877
+ "Checking requests made over signed URLs",
2878
+ "Signed URL requests not made over https. SSL is required for secure communications.",
2879
+ )
2880
+ wandb_verify.check_cors_configuration(url, host)
2881
+ wandb_verify.check_wandb_version(api)
2882
+ check_run_success = wandb_verify.check_run(api)
2883
+ check_artifacts_success = wandb_verify.check_artifacts()
2884
+ if not (
2885
+ check_artifacts_success
2886
+ and check_run_success
2887
+ and large_post_success
2888
+ and url_success
2889
+ ):
2890
+ sys.exit(1)