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