wandb 0.21.2__py3-none-macosx_12_0_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (904) hide show
  1. package_readme.md +97 -0
  2. wandb/__init__.py +248 -0
  3. wandb/__init__.pyi +1230 -0
  4. wandb/__main__.py +3 -0
  5. wandb/_iterutils.py +65 -0
  6. wandb/_pydantic/__init__.py +30 -0
  7. wandb/_pydantic/base.py +128 -0
  8. wandb/_pydantic/utils.py +80 -0
  9. wandb/_pydantic/v1_compat.py +284 -0
  10. wandb/agents/__init__.py +0 -0
  11. wandb/agents/pyagent.py +386 -0
  12. wandb/analytics/__init__.py +3 -0
  13. wandb/analytics/sentry.py +267 -0
  14. wandb/apis/__init__.py +48 -0
  15. wandb/apis/attrs.py +50 -0
  16. wandb/apis/importers/__init__.py +1 -0
  17. wandb/apis/importers/internals/internal.py +382 -0
  18. wandb/apis/importers/internals/protocols.py +103 -0
  19. wandb/apis/importers/internals/util.py +78 -0
  20. wandb/apis/importers/mlflow.py +254 -0
  21. wandb/apis/importers/validation.py +108 -0
  22. wandb/apis/importers/wandb.py +1608 -0
  23. wandb/apis/internal.py +239 -0
  24. wandb/apis/normalize.py +81 -0
  25. wandb/apis/paginator.py +138 -0
  26. wandb/apis/public/__init__.py +35 -0
  27. wandb/apis/public/api.py +2449 -0
  28. wandb/apis/public/artifacts.py +1046 -0
  29. wandb/apis/public/automations.py +85 -0
  30. wandb/apis/public/const.py +4 -0
  31. wandb/apis/public/files.py +402 -0
  32. wandb/apis/public/history.py +201 -0
  33. wandb/apis/public/integrations.py +203 -0
  34. wandb/apis/public/jobs.py +742 -0
  35. wandb/apis/public/projects.py +276 -0
  36. wandb/apis/public/query_generator.py +176 -0
  37. wandb/apis/public/registries/__init__.py +0 -0
  38. wandb/apis/public/registries/_freezable_list.py +179 -0
  39. wandb/apis/public/registries/_utils.py +138 -0
  40. wandb/apis/public/registries/registries_search.py +347 -0
  41. wandb/apis/public/registries/registry.py +358 -0
  42. wandb/apis/public/reports.py +595 -0
  43. wandb/apis/public/runs.py +1216 -0
  44. wandb/apis/public/sweeps.py +440 -0
  45. wandb/apis/public/teams.py +235 -0
  46. wandb/apis/public/users.py +177 -0
  47. wandb/apis/public/utils.py +210 -0
  48. wandb/apis/reports/__init__.py +1 -0
  49. wandb/apis/reports/v1/__init__.py +8 -0
  50. wandb/apis/reports/v2/__init__.py +8 -0
  51. wandb/apis/workspaces/__init__.py +8 -0
  52. wandb/automations/__init__.py +73 -0
  53. wandb/automations/_filters/__init__.py +40 -0
  54. wandb/automations/_filters/expressions.py +181 -0
  55. wandb/automations/_filters/operators.py +258 -0
  56. wandb/automations/_filters/run_metrics.py +330 -0
  57. wandb/automations/_generated/__init__.py +177 -0
  58. wandb/automations/_generated/create_automation.py +17 -0
  59. wandb/automations/_generated/create_generic_webhook_integration.py +43 -0
  60. wandb/automations/_generated/delete_automation.py +15 -0
  61. wandb/automations/_generated/enums.py +35 -0
  62. wandb/automations/_generated/fragments.py +358 -0
  63. wandb/automations/_generated/generic_webhook_integrations_by_entity.py +22 -0
  64. wandb/automations/_generated/get_automations.py +24 -0
  65. wandb/automations/_generated/get_automations_by_entity.py +26 -0
  66. wandb/automations/_generated/input_types.py +104 -0
  67. wandb/automations/_generated/integrations_by_entity.py +22 -0
  68. wandb/automations/_generated/operations.py +647 -0
  69. wandb/automations/_generated/slack_integrations_by_entity.py +22 -0
  70. wandb/automations/_generated/update_automation.py +17 -0
  71. wandb/automations/_utils.py +235 -0
  72. wandb/automations/_validators.py +165 -0
  73. wandb/automations/actions.py +218 -0
  74. wandb/automations/automations.py +85 -0
  75. wandb/automations/events.py +285 -0
  76. wandb/automations/integrations.py +45 -0
  77. wandb/automations/scopes.py +78 -0
  78. wandb/beta/workflows.py +324 -0
  79. wandb/bin/gpu_stats +0 -0
  80. wandb/bin/wandb-core +0 -0
  81. wandb/cli/__init__.py +0 -0
  82. wandb/cli/beta.py +175 -0
  83. wandb/cli/cli.py +2883 -0
  84. wandb/data_types.py +66 -0
  85. wandb/docker/__init__.py +290 -0
  86. wandb/docker/names.py +40 -0
  87. wandb/docker/wandb-entrypoint.sh +33 -0
  88. wandb/env.py +535 -0
  89. wandb/errors/__init__.py +17 -0
  90. wandb/errors/errors.py +40 -0
  91. wandb/errors/links.py +73 -0
  92. wandb/errors/term.py +415 -0
  93. wandb/errors/util.py +57 -0
  94. wandb/errors/warnings.py +2 -0
  95. wandb/filesync/__init__.py +0 -0
  96. wandb/filesync/dir_watcher.py +404 -0
  97. wandb/filesync/stats.py +100 -0
  98. wandb/filesync/step_checksum.py +142 -0
  99. wandb/filesync/step_prepare.py +179 -0
  100. wandb/filesync/step_upload.py +287 -0
  101. wandb/filesync/upload_job.py +142 -0
  102. wandb/integration/__init__.py +0 -0
  103. wandb/integration/catboost/__init__.py +5 -0
  104. wandb/integration/catboost/catboost.py +182 -0
  105. wandb/integration/cohere/__init__.py +3 -0
  106. wandb/integration/cohere/cohere.py +21 -0
  107. wandb/integration/cohere/resolver.py +347 -0
  108. wandb/integration/diffusers/__init__.py +3 -0
  109. wandb/integration/diffusers/autologger.py +76 -0
  110. wandb/integration/diffusers/pipeline_resolver.py +50 -0
  111. wandb/integration/diffusers/resolvers/__init__.py +9 -0
  112. wandb/integration/diffusers/resolvers/multimodal.py +881 -0
  113. wandb/integration/diffusers/resolvers/utils.py +102 -0
  114. wandb/integration/fastai/__init__.py +243 -0
  115. wandb/integration/gym/__init__.py +98 -0
  116. wandb/integration/huggingface/__init__.py +3 -0
  117. wandb/integration/huggingface/huggingface.py +18 -0
  118. wandb/integration/huggingface/resolver.py +213 -0
  119. wandb/integration/keras/__init__.py +11 -0
  120. wandb/integration/keras/callbacks/__init__.py +5 -0
  121. wandb/integration/keras/callbacks/metrics_logger.py +129 -0
  122. wandb/integration/keras/callbacks/model_checkpoint.py +188 -0
  123. wandb/integration/keras/callbacks/tables_builder.py +228 -0
  124. wandb/integration/keras/keras.py +1086 -0
  125. wandb/integration/kfp/__init__.py +6 -0
  126. wandb/integration/kfp/helpers.py +28 -0
  127. wandb/integration/kfp/kfp_patch.py +335 -0
  128. wandb/integration/kfp/wandb_logging.py +182 -0
  129. wandb/integration/langchain/__init__.py +3 -0
  130. wandb/integration/langchain/wandb_tracer.py +49 -0
  131. wandb/integration/lightgbm/__init__.py +239 -0
  132. wandb/integration/lightning/__init__.py +0 -0
  133. wandb/integration/lightning/fabric/__init__.py +3 -0
  134. wandb/integration/lightning/fabric/logger.py +763 -0
  135. wandb/integration/metaflow/__init__.py +9 -0
  136. wandb/integration/metaflow/data_pandas.py +74 -0
  137. wandb/integration/metaflow/data_pytorch.py +75 -0
  138. wandb/integration/metaflow/data_sklearn.py +76 -0
  139. wandb/integration/metaflow/errors.py +13 -0
  140. wandb/integration/metaflow/metaflow.py +327 -0
  141. wandb/integration/openai/__init__.py +3 -0
  142. wandb/integration/openai/fine_tuning.py +480 -0
  143. wandb/integration/openai/openai.py +22 -0
  144. wandb/integration/openai/resolver.py +240 -0
  145. wandb/integration/prodigy/__init__.py +3 -0
  146. wandb/integration/prodigy/prodigy.py +291 -0
  147. wandb/integration/sacred/__init__.py +117 -0
  148. wandb/integration/sagemaker/__init__.py +14 -0
  149. wandb/integration/sagemaker/auth.py +29 -0
  150. wandb/integration/sagemaker/config.py +58 -0
  151. wandb/integration/sagemaker/files.py +2 -0
  152. wandb/integration/sagemaker/resources.py +63 -0
  153. wandb/integration/sb3/__init__.py +3 -0
  154. wandb/integration/sb3/sb3.py +147 -0
  155. wandb/integration/sklearn/__init__.py +37 -0
  156. wandb/integration/sklearn/calculate/__init__.py +32 -0
  157. wandb/integration/sklearn/calculate/calibration_curves.py +125 -0
  158. wandb/integration/sklearn/calculate/class_proportions.py +68 -0
  159. wandb/integration/sklearn/calculate/confusion_matrix.py +93 -0
  160. wandb/integration/sklearn/calculate/decision_boundaries.py +40 -0
  161. wandb/integration/sklearn/calculate/elbow_curve.py +55 -0
  162. wandb/integration/sklearn/calculate/feature_importances.py +67 -0
  163. wandb/integration/sklearn/calculate/learning_curve.py +64 -0
  164. wandb/integration/sklearn/calculate/outlier_candidates.py +69 -0
  165. wandb/integration/sklearn/calculate/residuals.py +86 -0
  166. wandb/integration/sklearn/calculate/silhouette.py +118 -0
  167. wandb/integration/sklearn/calculate/summary_metrics.py +62 -0
  168. wandb/integration/sklearn/plot/__init__.py +35 -0
  169. wandb/integration/sklearn/plot/classifier.py +329 -0
  170. wandb/integration/sklearn/plot/clusterer.py +146 -0
  171. wandb/integration/sklearn/plot/regressor.py +121 -0
  172. wandb/integration/sklearn/plot/shared.py +91 -0
  173. wandb/integration/sklearn/utils.py +184 -0
  174. wandb/integration/tensorboard/__init__.py +10 -0
  175. wandb/integration/tensorboard/log.py +351 -0
  176. wandb/integration/tensorboard/monkeypatch.py +186 -0
  177. wandb/integration/tensorflow/__init__.py +5 -0
  178. wandb/integration/tensorflow/estimator_hook.py +54 -0
  179. wandb/integration/torch/__init__.py +0 -0
  180. wandb/integration/torch/wandb_torch.py +554 -0
  181. wandb/integration/ultralytics/__init__.py +11 -0
  182. wandb/integration/ultralytics/bbox_utils.py +215 -0
  183. wandb/integration/ultralytics/callback.py +528 -0
  184. wandb/integration/ultralytics/classification_utils.py +83 -0
  185. wandb/integration/ultralytics/mask_utils.py +202 -0
  186. wandb/integration/ultralytics/pose_utils.py +103 -0
  187. wandb/integration/weave/__init__.py +6 -0
  188. wandb/integration/weave/interface.py +49 -0
  189. wandb/integration/weave/weave.py +63 -0
  190. wandb/integration/xgboost/__init__.py +11 -0
  191. wandb/integration/xgboost/xgboost.py +189 -0
  192. wandb/integration/yolov8/__init__.py +0 -0
  193. wandb/integration/yolov8/yolov8.py +284 -0
  194. wandb/jupyter.py +538 -0
  195. wandb/mpmain/__init__.py +0 -0
  196. wandb/mpmain/__main__.py +1 -0
  197. wandb/old/__init__.py +0 -0
  198. wandb/old/core.py +53 -0
  199. wandb/old/settings.py +176 -0
  200. wandb/old/summary.py +438 -0
  201. wandb/plot/__init__.py +30 -0
  202. wandb/plot/bar.py +71 -0
  203. wandb/plot/confusion_matrix.py +185 -0
  204. wandb/plot/custom_chart.py +147 -0
  205. wandb/plot/histogram.py +66 -0
  206. wandb/plot/line.py +75 -0
  207. wandb/plot/line_series.py +173 -0
  208. wandb/plot/pr_curve.py +186 -0
  209. wandb/plot/roc_curve.py +163 -0
  210. wandb/plot/scatter.py +66 -0
  211. wandb/plot/utils.py +184 -0
  212. wandb/plot/viz.py +41 -0
  213. wandb/proto/__init__.py +0 -0
  214. wandb/proto/v3/__init__.py +0 -0
  215. wandb/proto/v3/wandb_base_pb2.py +55 -0
  216. wandb/proto/v3/wandb_internal_pb2.py +1728 -0
  217. wandb/proto/v3/wandb_server_pb2.py +228 -0
  218. wandb/proto/v3/wandb_settings_pb2.py +122 -0
  219. wandb/proto/v3/wandb_telemetry_pb2.py +106 -0
  220. wandb/proto/v4/__init__.py +0 -0
  221. wandb/proto/v4/wandb_base_pb2.py +30 -0
  222. wandb/proto/v4/wandb_internal_pb2.py +382 -0
  223. wandb/proto/v4/wandb_server_pb2.py +67 -0
  224. wandb/proto/v4/wandb_settings_pb2.py +47 -0
  225. wandb/proto/v4/wandb_telemetry_pb2.py +41 -0
  226. wandb/proto/v5/wandb_base_pb2.py +31 -0
  227. wandb/proto/v5/wandb_internal_pb2.py +383 -0
  228. wandb/proto/v5/wandb_server_pb2.py +68 -0
  229. wandb/proto/v5/wandb_settings_pb2.py +48 -0
  230. wandb/proto/v5/wandb_telemetry_pb2.py +42 -0
  231. wandb/proto/v6/wandb_base_pb2.py +41 -0
  232. wandb/proto/v6/wandb_internal_pb2.py +393 -0
  233. wandb/proto/v6/wandb_server_pb2.py +78 -0
  234. wandb/proto/v6/wandb_settings_pb2.py +58 -0
  235. wandb/proto/v6/wandb_telemetry_pb2.py +52 -0
  236. wandb/proto/wandb_base_pb2.py +12 -0
  237. wandb/proto/wandb_deprecated.py +59 -0
  238. wandb/proto/wandb_generate_deprecated.py +30 -0
  239. wandb/proto/wandb_generate_proto.py +49 -0
  240. wandb/proto/wandb_internal_pb2.py +18 -0
  241. wandb/proto/wandb_server_pb2.py +12 -0
  242. wandb/proto/wandb_settings_pb2.py +12 -0
  243. wandb/proto/wandb_telemetry_pb2.py +12 -0
  244. wandb/py.typed +0 -0
  245. wandb/sdk/__init__.py +37 -0
  246. wandb/sdk/artifacts/__init__.py +0 -0
  247. wandb/sdk/artifacts/_factories.py +17 -0
  248. wandb/sdk/artifacts/_generated/__init__.py +508 -0
  249. wandb/sdk/artifacts/_generated/add_aliases.py +21 -0
  250. wandb/sdk/artifacts/_generated/artifact_by_id.py +17 -0
  251. wandb/sdk/artifacts/_generated/artifact_by_name.py +22 -0
  252. wandb/sdk/artifacts/_generated/artifact_collection_membership_file_urls.py +43 -0
  253. wandb/sdk/artifacts/_generated/artifact_collection_membership_files.py +43 -0
  254. wandb/sdk/artifacts/_generated/artifact_created_by.py +47 -0
  255. wandb/sdk/artifacts/_generated/artifact_file_urls.py +22 -0
  256. wandb/sdk/artifacts/_generated/artifact_type.py +31 -0
  257. wandb/sdk/artifacts/_generated/artifact_used_by.py +43 -0
  258. wandb/sdk/artifacts/_generated/artifact_version_files.py +36 -0
  259. wandb/sdk/artifacts/_generated/artifact_via_membership_by_name.py +26 -0
  260. wandb/sdk/artifacts/_generated/create_artifact_collection_tag_assignments.py +36 -0
  261. wandb/sdk/artifacts/_generated/delete_aliases.py +21 -0
  262. wandb/sdk/artifacts/_generated/delete_artifact.py +28 -0
  263. wandb/sdk/artifacts/_generated/delete_artifact_collection_tag_assignments.py +25 -0
  264. wandb/sdk/artifacts/_generated/delete_artifact_portfolio.py +35 -0
  265. wandb/sdk/artifacts/_generated/delete_artifact_sequence.py +35 -0
  266. wandb/sdk/artifacts/_generated/enums.py +22 -0
  267. wandb/sdk/artifacts/_generated/fetch_artifact_manifest.py +38 -0
  268. wandb/sdk/artifacts/_generated/fetch_linked_artifacts.py +67 -0
  269. wandb/sdk/artifacts/_generated/fetch_registries.py +32 -0
  270. wandb/sdk/artifacts/_generated/fragments.py +459 -0
  271. wandb/sdk/artifacts/_generated/input_types.py +46 -0
  272. wandb/sdk/artifacts/_generated/link_artifact.py +27 -0
  273. wandb/sdk/artifacts/_generated/move_artifact_collection.py +35 -0
  274. wandb/sdk/artifacts/_generated/operations.py +1223 -0
  275. wandb/sdk/artifacts/_generated/project_artifact_collection.py +101 -0
  276. wandb/sdk/artifacts/_generated/project_artifact_collections.py +33 -0
  277. wandb/sdk/artifacts/_generated/project_artifact_type.py +24 -0
  278. wandb/sdk/artifacts/_generated/project_artifact_types.py +24 -0
  279. wandb/sdk/artifacts/_generated/project_artifacts.py +42 -0
  280. wandb/sdk/artifacts/_generated/registry_collections.py +34 -0
  281. wandb/sdk/artifacts/_generated/registry_versions.py +34 -0
  282. wandb/sdk/artifacts/_generated/run_input_artifacts.py +51 -0
  283. wandb/sdk/artifacts/_generated/run_output_artifacts.py +51 -0
  284. wandb/sdk/artifacts/_generated/unlink_artifact.py +25 -0
  285. wandb/sdk/artifacts/_generated/update_artifact.py +26 -0
  286. wandb/sdk/artifacts/_generated/update_artifact_portfolio.py +35 -0
  287. wandb/sdk/artifacts/_generated/update_artifact_sequence.py +35 -0
  288. wandb/sdk/artifacts/_graphql_fragments.py +19 -0
  289. wandb/sdk/artifacts/_internal_artifact.py +54 -0
  290. wandb/sdk/artifacts/_validators.py +309 -0
  291. wandb/sdk/artifacts/artifact.py +2702 -0
  292. wandb/sdk/artifacts/artifact_download_logger.py +45 -0
  293. wandb/sdk/artifacts/artifact_file_cache.py +251 -0
  294. wandb/sdk/artifacts/artifact_instance_cache.py +17 -0
  295. wandb/sdk/artifacts/artifact_manifest.py +76 -0
  296. wandb/sdk/artifacts/artifact_manifest_entry.py +258 -0
  297. wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
  298. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +94 -0
  299. wandb/sdk/artifacts/artifact_saver.py +277 -0
  300. wandb/sdk/artifacts/artifact_state.py +13 -0
  301. wandb/sdk/artifacts/artifact_ttl.py +9 -0
  302. wandb/sdk/artifacts/exceptions.py +71 -0
  303. wandb/sdk/artifacts/staging.py +27 -0
  304. wandb/sdk/artifacts/storage_handler.py +62 -0
  305. wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
  306. wandb/sdk/artifacts/storage_handlers/azure_handler.py +214 -0
  307. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +224 -0
  308. wandb/sdk/artifacts/storage_handlers/http_handler.py +114 -0
  309. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +142 -0
  310. wandb/sdk/artifacts/storage_handlers/multi_handler.py +56 -0
  311. wandb/sdk/artifacts/storage_handlers/s3_handler.py +339 -0
  312. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +68 -0
  313. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +131 -0
  314. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +74 -0
  315. wandb/sdk/artifacts/storage_layout.py +8 -0
  316. wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
  317. wandb/sdk/artifacts/storage_policies/register.py +1 -0
  318. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +580 -0
  319. wandb/sdk/artifacts/storage_policy.py +75 -0
  320. wandb/sdk/backend/__init__.py +0 -0
  321. wandb/sdk/backend/backend.py +57 -0
  322. wandb/sdk/data_types/__init__.py +0 -0
  323. wandb/sdk/data_types/_dtypes.py +914 -0
  324. wandb/sdk/data_types/_private.py +10 -0
  325. wandb/sdk/data_types/audio.py +208 -0
  326. wandb/sdk/data_types/base_types/__init__.py +0 -0
  327. wandb/sdk/data_types/base_types/json_metadata.py +55 -0
  328. wandb/sdk/data_types/base_types/media.py +339 -0
  329. wandb/sdk/data_types/base_types/wb_value.py +295 -0
  330. wandb/sdk/data_types/bokeh.py +87 -0
  331. wandb/sdk/data_types/graph.py +439 -0
  332. wandb/sdk/data_types/helper_types/__init__.py +0 -0
  333. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +327 -0
  334. wandb/sdk/data_types/helper_types/classes.py +159 -0
  335. wandb/sdk/data_types/helper_types/image_mask.py +251 -0
  336. wandb/sdk/data_types/histogram.py +107 -0
  337. wandb/sdk/data_types/html.py +165 -0
  338. wandb/sdk/data_types/image.py +974 -0
  339. wandb/sdk/data_types/molecule.py +250 -0
  340. wandb/sdk/data_types/object_3d.py +495 -0
  341. wandb/sdk/data_types/plotly.py +95 -0
  342. wandb/sdk/data_types/saved_model.py +435 -0
  343. wandb/sdk/data_types/table.py +1468 -0
  344. wandb/sdk/data_types/table_decorators.py +108 -0
  345. wandb/sdk/data_types/trace_tree.py +440 -0
  346. wandb/sdk/data_types/utils.py +260 -0
  347. wandb/sdk/data_types/video.py +303 -0
  348. wandb/sdk/integration_utils/__init__.py +0 -0
  349. wandb/sdk/integration_utils/auto_logging.py +232 -0
  350. wandb/sdk/integration_utils/data_logging.py +475 -0
  351. wandb/sdk/interface/__init__.py +0 -0
  352. wandb/sdk/interface/constants.py +4 -0
  353. wandb/sdk/interface/interface.py +1056 -0
  354. wandb/sdk/interface/interface_queue.py +40 -0
  355. wandb/sdk/interface/interface_shared.py +471 -0
  356. wandb/sdk/interface/interface_sock.py +49 -0
  357. wandb/sdk/interface/summary_record.py +67 -0
  358. wandb/sdk/internal/__init__.py +0 -0
  359. wandb/sdk/internal/_generated/__init__.py +15 -0
  360. wandb/sdk/internal/_generated/enums.py +4 -0
  361. wandb/sdk/internal/_generated/input_types.py +4 -0
  362. wandb/sdk/internal/_generated/operations.py +15 -0
  363. wandb/sdk/internal/_generated/server_features_query.py +27 -0
  364. wandb/sdk/internal/context.py +89 -0
  365. wandb/sdk/internal/datastore.py +293 -0
  366. wandb/sdk/internal/file_pusher.py +177 -0
  367. wandb/sdk/internal/file_stream.py +686 -0
  368. wandb/sdk/internal/handler.py +854 -0
  369. wandb/sdk/internal/incremental_table_util.py +53 -0
  370. wandb/sdk/internal/internal_api.py +4723 -0
  371. wandb/sdk/internal/job_builder.py +639 -0
  372. wandb/sdk/internal/profiler.py +79 -0
  373. wandb/sdk/internal/progress.py +77 -0
  374. wandb/sdk/internal/run.py +27 -0
  375. wandb/sdk/internal/sample.py +70 -0
  376. wandb/sdk/internal/sender.py +1692 -0
  377. wandb/sdk/internal/sender_config.py +203 -0
  378. wandb/sdk/internal/settings_static.py +120 -0
  379. wandb/sdk/internal/tb_watcher.py +519 -0
  380. wandb/sdk/internal/thread_local_settings.py +18 -0
  381. wandb/sdk/launch/__init__.py +15 -0
  382. wandb/sdk/launch/_launch.py +331 -0
  383. wandb/sdk/launch/_launch_add.py +255 -0
  384. wandb/sdk/launch/_project_spec.py +565 -0
  385. wandb/sdk/launch/agent/__init__.py +5 -0
  386. wandb/sdk/launch/agent/agent.py +931 -0
  387. wandb/sdk/launch/agent/config.py +296 -0
  388. wandb/sdk/launch/agent/job_status_tracker.py +55 -0
  389. wandb/sdk/launch/agent/run_queue_item_file_saver.py +39 -0
  390. wandb/sdk/launch/builder/__init__.py +0 -0
  391. wandb/sdk/launch/builder/abstract.py +156 -0
  392. wandb/sdk/launch/builder/build.py +296 -0
  393. wandb/sdk/launch/builder/context_manager.py +235 -0
  394. wandb/sdk/launch/builder/docker_builder.py +177 -0
  395. wandb/sdk/launch/builder/kaniko_builder.py +595 -0
  396. wandb/sdk/launch/builder/noop.py +58 -0
  397. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +188 -0
  398. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  399. wandb/sdk/launch/create_job.py +541 -0
  400. wandb/sdk/launch/environment/abstract.py +29 -0
  401. wandb/sdk/launch/environment/aws_environment.py +322 -0
  402. wandb/sdk/launch/environment/azure_environment.py +105 -0
  403. wandb/sdk/launch/environment/gcp_environment.py +334 -0
  404. wandb/sdk/launch/environment/local_environment.py +65 -0
  405. wandb/sdk/launch/errors.py +13 -0
  406. wandb/sdk/launch/git_reference.py +109 -0
  407. wandb/sdk/launch/inputs/files.py +148 -0
  408. wandb/sdk/launch/inputs/internal.py +314 -0
  409. wandb/sdk/launch/inputs/manage.py +113 -0
  410. wandb/sdk/launch/inputs/schema.py +40 -0
  411. wandb/sdk/launch/loader.py +249 -0
  412. wandb/sdk/launch/registry/abstract.py +48 -0
  413. wandb/sdk/launch/registry/anon.py +29 -0
  414. wandb/sdk/launch/registry/azure_container_registry.py +124 -0
  415. wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
  416. wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
  417. wandb/sdk/launch/registry/local_registry.py +65 -0
  418. wandb/sdk/launch/runner/__init__.py +0 -0
  419. wandb/sdk/launch/runner/abstract.py +185 -0
  420. wandb/sdk/launch/runner/kubernetes_monitor.py +473 -0
  421. wandb/sdk/launch/runner/kubernetes_runner.py +1285 -0
  422. wandb/sdk/launch/runner/local_container.py +301 -0
  423. wandb/sdk/launch/runner/local_process.py +78 -0
  424. wandb/sdk/launch/runner/sagemaker_runner.py +424 -0
  425. wandb/sdk/launch/runner/vertex_runner.py +225 -0
  426. wandb/sdk/launch/sweeps/__init__.py +37 -0
  427. wandb/sdk/launch/sweeps/scheduler.py +739 -0
  428. wandb/sdk/launch/sweeps/scheduler_sweep.py +90 -0
  429. wandb/sdk/launch/sweeps/utils.py +324 -0
  430. wandb/sdk/launch/utils.py +746 -0
  431. wandb/sdk/launch/wandb_reference.py +138 -0
  432. wandb/sdk/lib/__init__.py +5 -0
  433. wandb/sdk/lib/apikey.py +334 -0
  434. wandb/sdk/lib/asyncio_compat.py +213 -0
  435. wandb/sdk/lib/asyncio_manager.py +252 -0
  436. wandb/sdk/lib/capped_dict.py +26 -0
  437. wandb/sdk/lib/config_util.py +101 -0
  438. wandb/sdk/lib/console_capture.py +219 -0
  439. wandb/sdk/lib/credentials.py +141 -0
  440. wandb/sdk/lib/deprecate.py +27 -0
  441. wandb/sdk/lib/disabled.py +30 -0
  442. wandb/sdk/lib/exit_hooks.py +54 -0
  443. wandb/sdk/lib/file_stream_utils.py +118 -0
  444. wandb/sdk/lib/filenames.py +64 -0
  445. wandb/sdk/lib/filesystem.py +372 -0
  446. wandb/sdk/lib/fsm.py +165 -0
  447. wandb/sdk/lib/gitlib.py +240 -0
  448. wandb/sdk/lib/gql_request.py +65 -0
  449. wandb/sdk/lib/handler_util.py +21 -0
  450. wandb/sdk/lib/hashutil.py +106 -0
  451. wandb/sdk/lib/import_hooks.py +275 -0
  452. wandb/sdk/lib/interrupt.py +37 -0
  453. wandb/sdk/lib/ipython.py +126 -0
  454. wandb/sdk/lib/json_util.py +75 -0
  455. wandb/sdk/lib/lazyloader.py +63 -0
  456. wandb/sdk/lib/module.py +72 -0
  457. wandb/sdk/lib/paths.py +106 -0
  458. wandb/sdk/lib/preinit.py +42 -0
  459. wandb/sdk/lib/printer.py +571 -0
  460. wandb/sdk/lib/printer_asyncio.py +48 -0
  461. wandb/sdk/lib/progress.py +320 -0
  462. wandb/sdk/lib/proto_util.py +90 -0
  463. wandb/sdk/lib/redirect.py +876 -0
  464. wandb/sdk/lib/retry.py +395 -0
  465. wandb/sdk/lib/run_moment.py +82 -0
  466. wandb/sdk/lib/runid.py +12 -0
  467. wandb/sdk/lib/server.py +58 -0
  468. wandb/sdk/lib/service/ipc_support.py +13 -0
  469. wandb/sdk/lib/service/service_client.py +106 -0
  470. wandb/sdk/lib/service/service_connection.py +192 -0
  471. wandb/sdk/lib/service/service_port_file.py +105 -0
  472. wandb/sdk/lib/service/service_process.py +111 -0
  473. wandb/sdk/lib/service/service_token.py +181 -0
  474. wandb/sdk/lib/sparkline.py +44 -0
  475. wandb/sdk/lib/telemetry.py +100 -0
  476. wandb/sdk/lib/timed_input.py +133 -0
  477. wandb/sdk/lib/timer.py +19 -0
  478. wandb/sdk/lib/wb_logging.py +161 -0
  479. wandb/sdk/mailbox/__init__.py +23 -0
  480. wandb/sdk/mailbox/mailbox.py +143 -0
  481. wandb/sdk/mailbox/mailbox_handle.py +132 -0
  482. wandb/sdk/mailbox/response_handle.py +99 -0
  483. wandb/sdk/mailbox/wait_with_progress.py +100 -0
  484. wandb/sdk/projects/_generated/__init__.py +47 -0
  485. wandb/sdk/projects/_generated/delete_project.py +22 -0
  486. wandb/sdk/projects/_generated/enums.py +4 -0
  487. wandb/sdk/projects/_generated/fetch_registry.py +22 -0
  488. wandb/sdk/projects/_generated/fragments.py +41 -0
  489. wandb/sdk/projects/_generated/input_types.py +13 -0
  490. wandb/sdk/projects/_generated/operations.py +88 -0
  491. wandb/sdk/projects/_generated/rename_project.py +27 -0
  492. wandb/sdk/projects/_generated/upsert_registry_project.py +27 -0
  493. wandb/sdk/verify/__init__.py +0 -0
  494. wandb/sdk/verify/verify.py +555 -0
  495. wandb/sdk/wandb_alerts.py +12 -0
  496. wandb/sdk/wandb_config.py +323 -0
  497. wandb/sdk/wandb_helper.py +54 -0
  498. wandb/sdk/wandb_init.py +1581 -0
  499. wandb/sdk/wandb_login.py +332 -0
  500. wandb/sdk/wandb_metric.py +112 -0
  501. wandb/sdk/wandb_require.py +88 -0
  502. wandb/sdk/wandb_require_helpers.py +44 -0
  503. wandb/sdk/wandb_run.py +4088 -0
  504. wandb/sdk/wandb_settings.py +2105 -0
  505. wandb/sdk/wandb_setup.py +560 -0
  506. wandb/sdk/wandb_summary.py +150 -0
  507. wandb/sdk/wandb_sweep.py +120 -0
  508. wandb/sdk/wandb_sync.py +71 -0
  509. wandb/sdk/wandb_watch.py +146 -0
  510. wandb/sklearn.py +35 -0
  511. wandb/sync/__init__.py +3 -0
  512. wandb/sync/sync.py +452 -0
  513. wandb/trigger.py +29 -0
  514. wandb/util.py +2040 -0
  515. wandb/vendor/__init__.py +0 -0
  516. wandb/vendor/gql-0.2.0/setup.py +40 -0
  517. wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
  518. wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
  519. wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
  520. wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
  521. wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
  522. wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
  523. wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
  524. wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
  525. wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
  526. wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
  527. wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
  528. wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
  529. wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
  530. wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
  531. wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
  532. wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
  533. wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
  534. wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
  535. wandb/vendor/graphql-core-1.1/setup.py +86 -0
  536. wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
  537. wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
  538. wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
  539. wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
  540. wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
  541. wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
  542. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
  543. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
  544. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
  545. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
  546. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
  547. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
  548. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
  549. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
  550. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
  551. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
  552. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
  553. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
  554. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
  555. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
  556. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
  557. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
  558. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
  559. wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
  560. wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
  561. wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
  562. wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
  563. wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
  564. wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
  565. wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
  566. wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
  567. wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
  568. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
  569. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
  570. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
  571. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
  572. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
  573. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
  574. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
  575. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
  576. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
  577. wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
  578. wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
  579. wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
  580. wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
  581. wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
  582. wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
  583. wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
  584. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
  585. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
  586. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
  587. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
  588. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
  589. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
  590. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
  591. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
  592. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
  593. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
  594. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
  595. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
  596. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
  597. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
  598. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
  599. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
  600. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
  601. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
  602. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
  603. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
  604. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
  605. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
  606. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
  607. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
  608. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
  609. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
  610. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
  611. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
  612. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
  613. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
  614. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
  615. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
  616. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
  617. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
  618. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
  619. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
  620. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
  621. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
  622. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
  623. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
  624. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
  625. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
  626. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
  627. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
  628. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
  629. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
  630. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
  631. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
  632. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
  633. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
  634. wandb/vendor/promise-2.3.0/conftest.py +30 -0
  635. wandb/vendor/promise-2.3.0/setup.py +64 -0
  636. wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
  637. wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
  638. wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
  639. wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
  640. wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
  641. wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
  642. wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
  643. wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
  644. wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
  645. wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
  646. wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
  647. wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
  648. wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
  649. wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
  650. wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
  651. wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
  652. wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
  653. wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
  654. wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
  655. wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
  656. wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
  657. wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
  658. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
  659. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
  660. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
  661. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
  662. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
  663. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
  664. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
  665. wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
  666. wandb/vendor/pygments/__init__.py +90 -0
  667. wandb/vendor/pygments/cmdline.py +568 -0
  668. wandb/vendor/pygments/console.py +74 -0
  669. wandb/vendor/pygments/filter.py +74 -0
  670. wandb/vendor/pygments/filters/__init__.py +350 -0
  671. wandb/vendor/pygments/formatter.py +95 -0
  672. wandb/vendor/pygments/formatters/__init__.py +153 -0
  673. wandb/vendor/pygments/formatters/_mapping.py +85 -0
  674. wandb/vendor/pygments/formatters/bbcode.py +109 -0
  675. wandb/vendor/pygments/formatters/html.py +851 -0
  676. wandb/vendor/pygments/formatters/img.py +600 -0
  677. wandb/vendor/pygments/formatters/irc.py +182 -0
  678. wandb/vendor/pygments/formatters/latex.py +482 -0
  679. wandb/vendor/pygments/formatters/other.py +160 -0
  680. wandb/vendor/pygments/formatters/rtf.py +147 -0
  681. wandb/vendor/pygments/formatters/svg.py +153 -0
  682. wandb/vendor/pygments/formatters/terminal.py +136 -0
  683. wandb/vendor/pygments/formatters/terminal256.py +309 -0
  684. wandb/vendor/pygments/lexer.py +871 -0
  685. wandb/vendor/pygments/lexers/__init__.py +329 -0
  686. wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
  687. wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
  688. wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
  689. wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
  690. wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
  691. wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
  692. wandb/vendor/pygments/lexers/_mapping.py +500 -0
  693. wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
  694. wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
  695. wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
  696. wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
  697. wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
  698. wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
  699. wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
  700. wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
  701. wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
  702. wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
  703. wandb/vendor/pygments/lexers/actionscript.py +240 -0
  704. wandb/vendor/pygments/lexers/agile.py +24 -0
  705. wandb/vendor/pygments/lexers/algebra.py +221 -0
  706. wandb/vendor/pygments/lexers/ambient.py +76 -0
  707. wandb/vendor/pygments/lexers/ampl.py +87 -0
  708. wandb/vendor/pygments/lexers/apl.py +101 -0
  709. wandb/vendor/pygments/lexers/archetype.py +318 -0
  710. wandb/vendor/pygments/lexers/asm.py +641 -0
  711. wandb/vendor/pygments/lexers/automation.py +374 -0
  712. wandb/vendor/pygments/lexers/basic.py +500 -0
  713. wandb/vendor/pygments/lexers/bibtex.py +160 -0
  714. wandb/vendor/pygments/lexers/business.py +612 -0
  715. wandb/vendor/pygments/lexers/c_cpp.py +252 -0
  716. wandb/vendor/pygments/lexers/c_like.py +541 -0
  717. wandb/vendor/pygments/lexers/capnproto.py +78 -0
  718. wandb/vendor/pygments/lexers/chapel.py +102 -0
  719. wandb/vendor/pygments/lexers/clean.py +288 -0
  720. wandb/vendor/pygments/lexers/compiled.py +34 -0
  721. wandb/vendor/pygments/lexers/configs.py +833 -0
  722. wandb/vendor/pygments/lexers/console.py +114 -0
  723. wandb/vendor/pygments/lexers/crystal.py +393 -0
  724. wandb/vendor/pygments/lexers/csound.py +366 -0
  725. wandb/vendor/pygments/lexers/css.py +689 -0
  726. wandb/vendor/pygments/lexers/d.py +251 -0
  727. wandb/vendor/pygments/lexers/dalvik.py +125 -0
  728. wandb/vendor/pygments/lexers/data.py +555 -0
  729. wandb/vendor/pygments/lexers/diff.py +165 -0
  730. wandb/vendor/pygments/lexers/dotnet.py +691 -0
  731. wandb/vendor/pygments/lexers/dsls.py +878 -0
  732. wandb/vendor/pygments/lexers/dylan.py +289 -0
  733. wandb/vendor/pygments/lexers/ecl.py +125 -0
  734. wandb/vendor/pygments/lexers/eiffel.py +65 -0
  735. wandb/vendor/pygments/lexers/elm.py +121 -0
  736. wandb/vendor/pygments/lexers/erlang.py +533 -0
  737. wandb/vendor/pygments/lexers/esoteric.py +277 -0
  738. wandb/vendor/pygments/lexers/ezhil.py +69 -0
  739. wandb/vendor/pygments/lexers/factor.py +344 -0
  740. wandb/vendor/pygments/lexers/fantom.py +250 -0
  741. wandb/vendor/pygments/lexers/felix.py +273 -0
  742. wandb/vendor/pygments/lexers/forth.py +177 -0
  743. wandb/vendor/pygments/lexers/fortran.py +205 -0
  744. wandb/vendor/pygments/lexers/foxpro.py +428 -0
  745. wandb/vendor/pygments/lexers/functional.py +21 -0
  746. wandb/vendor/pygments/lexers/go.py +101 -0
  747. wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
  748. wandb/vendor/pygments/lexers/graph.py +80 -0
  749. wandb/vendor/pygments/lexers/graphics.py +553 -0
  750. wandb/vendor/pygments/lexers/haskell.py +843 -0
  751. wandb/vendor/pygments/lexers/haxe.py +936 -0
  752. wandb/vendor/pygments/lexers/hdl.py +382 -0
  753. wandb/vendor/pygments/lexers/hexdump.py +103 -0
  754. wandb/vendor/pygments/lexers/html.py +602 -0
  755. wandb/vendor/pygments/lexers/idl.py +270 -0
  756. wandb/vendor/pygments/lexers/igor.py +288 -0
  757. wandb/vendor/pygments/lexers/inferno.py +96 -0
  758. wandb/vendor/pygments/lexers/installers.py +322 -0
  759. wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
  760. wandb/vendor/pygments/lexers/iolang.py +63 -0
  761. wandb/vendor/pygments/lexers/j.py +146 -0
  762. wandb/vendor/pygments/lexers/javascript.py +1525 -0
  763. wandb/vendor/pygments/lexers/julia.py +333 -0
  764. wandb/vendor/pygments/lexers/jvm.py +1573 -0
  765. wandb/vendor/pygments/lexers/lisp.py +2621 -0
  766. wandb/vendor/pygments/lexers/make.py +202 -0
  767. wandb/vendor/pygments/lexers/markup.py +595 -0
  768. wandb/vendor/pygments/lexers/math.py +21 -0
  769. wandb/vendor/pygments/lexers/matlab.py +663 -0
  770. wandb/vendor/pygments/lexers/ml.py +769 -0
  771. wandb/vendor/pygments/lexers/modeling.py +358 -0
  772. wandb/vendor/pygments/lexers/modula2.py +1561 -0
  773. wandb/vendor/pygments/lexers/monte.py +204 -0
  774. wandb/vendor/pygments/lexers/ncl.py +894 -0
  775. wandb/vendor/pygments/lexers/nimrod.py +159 -0
  776. wandb/vendor/pygments/lexers/nit.py +64 -0
  777. wandb/vendor/pygments/lexers/nix.py +136 -0
  778. wandb/vendor/pygments/lexers/oberon.py +105 -0
  779. wandb/vendor/pygments/lexers/objective.py +504 -0
  780. wandb/vendor/pygments/lexers/ooc.py +85 -0
  781. wandb/vendor/pygments/lexers/other.py +41 -0
  782. wandb/vendor/pygments/lexers/parasail.py +79 -0
  783. wandb/vendor/pygments/lexers/parsers.py +835 -0
  784. wandb/vendor/pygments/lexers/pascal.py +644 -0
  785. wandb/vendor/pygments/lexers/pawn.py +199 -0
  786. wandb/vendor/pygments/lexers/perl.py +620 -0
  787. wandb/vendor/pygments/lexers/php.py +267 -0
  788. wandb/vendor/pygments/lexers/praat.py +294 -0
  789. wandb/vendor/pygments/lexers/prolog.py +306 -0
  790. wandb/vendor/pygments/lexers/python.py +939 -0
  791. wandb/vendor/pygments/lexers/qvt.py +152 -0
  792. wandb/vendor/pygments/lexers/r.py +453 -0
  793. wandb/vendor/pygments/lexers/rdf.py +270 -0
  794. wandb/vendor/pygments/lexers/rebol.py +431 -0
  795. wandb/vendor/pygments/lexers/resource.py +85 -0
  796. wandb/vendor/pygments/lexers/rnc.py +67 -0
  797. wandb/vendor/pygments/lexers/roboconf.py +82 -0
  798. wandb/vendor/pygments/lexers/robotframework.py +560 -0
  799. wandb/vendor/pygments/lexers/ruby.py +519 -0
  800. wandb/vendor/pygments/lexers/rust.py +220 -0
  801. wandb/vendor/pygments/lexers/sas.py +228 -0
  802. wandb/vendor/pygments/lexers/scripting.py +1222 -0
  803. wandb/vendor/pygments/lexers/shell.py +794 -0
  804. wandb/vendor/pygments/lexers/smalltalk.py +195 -0
  805. wandb/vendor/pygments/lexers/smv.py +79 -0
  806. wandb/vendor/pygments/lexers/snobol.py +83 -0
  807. wandb/vendor/pygments/lexers/special.py +103 -0
  808. wandb/vendor/pygments/lexers/sql.py +681 -0
  809. wandb/vendor/pygments/lexers/stata.py +108 -0
  810. wandb/vendor/pygments/lexers/supercollider.py +90 -0
  811. wandb/vendor/pygments/lexers/tcl.py +145 -0
  812. wandb/vendor/pygments/lexers/templates.py +2283 -0
  813. wandb/vendor/pygments/lexers/testing.py +207 -0
  814. wandb/vendor/pygments/lexers/text.py +25 -0
  815. wandb/vendor/pygments/lexers/textedit.py +169 -0
  816. wandb/vendor/pygments/lexers/textfmts.py +297 -0
  817. wandb/vendor/pygments/lexers/theorem.py +458 -0
  818. wandb/vendor/pygments/lexers/trafficscript.py +54 -0
  819. wandb/vendor/pygments/lexers/typoscript.py +226 -0
  820. wandb/vendor/pygments/lexers/urbi.py +133 -0
  821. wandb/vendor/pygments/lexers/varnish.py +190 -0
  822. wandb/vendor/pygments/lexers/verification.py +111 -0
  823. wandb/vendor/pygments/lexers/web.py +24 -0
  824. wandb/vendor/pygments/lexers/webmisc.py +988 -0
  825. wandb/vendor/pygments/lexers/whiley.py +116 -0
  826. wandb/vendor/pygments/lexers/x10.py +69 -0
  827. wandb/vendor/pygments/modeline.py +44 -0
  828. wandb/vendor/pygments/plugin.py +68 -0
  829. wandb/vendor/pygments/regexopt.py +92 -0
  830. wandb/vendor/pygments/scanner.py +105 -0
  831. wandb/vendor/pygments/sphinxext.py +158 -0
  832. wandb/vendor/pygments/style.py +155 -0
  833. wandb/vendor/pygments/styles/__init__.py +80 -0
  834. wandb/vendor/pygments/styles/abap.py +29 -0
  835. wandb/vendor/pygments/styles/algol.py +63 -0
  836. wandb/vendor/pygments/styles/algol_nu.py +63 -0
  837. wandb/vendor/pygments/styles/arduino.py +98 -0
  838. wandb/vendor/pygments/styles/autumn.py +65 -0
  839. wandb/vendor/pygments/styles/borland.py +51 -0
  840. wandb/vendor/pygments/styles/bw.py +49 -0
  841. wandb/vendor/pygments/styles/colorful.py +81 -0
  842. wandb/vendor/pygments/styles/default.py +73 -0
  843. wandb/vendor/pygments/styles/emacs.py +72 -0
  844. wandb/vendor/pygments/styles/friendly.py +72 -0
  845. wandb/vendor/pygments/styles/fruity.py +42 -0
  846. wandb/vendor/pygments/styles/igor.py +29 -0
  847. wandb/vendor/pygments/styles/lovelace.py +97 -0
  848. wandb/vendor/pygments/styles/manni.py +75 -0
  849. wandb/vendor/pygments/styles/monokai.py +106 -0
  850. wandb/vendor/pygments/styles/murphy.py +80 -0
  851. wandb/vendor/pygments/styles/native.py +65 -0
  852. wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
  853. wandb/vendor/pygments/styles/paraiso_light.py +125 -0
  854. wandb/vendor/pygments/styles/pastie.py +75 -0
  855. wandb/vendor/pygments/styles/perldoc.py +69 -0
  856. wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
  857. wandb/vendor/pygments/styles/rrt.py +33 -0
  858. wandb/vendor/pygments/styles/sas.py +44 -0
  859. wandb/vendor/pygments/styles/stata.py +40 -0
  860. wandb/vendor/pygments/styles/tango.py +141 -0
  861. wandb/vendor/pygments/styles/trac.py +63 -0
  862. wandb/vendor/pygments/styles/vim.py +63 -0
  863. wandb/vendor/pygments/styles/vs.py +38 -0
  864. wandb/vendor/pygments/styles/xcode.py +51 -0
  865. wandb/vendor/pygments/token.py +213 -0
  866. wandb/vendor/pygments/unistring.py +217 -0
  867. wandb/vendor/pygments/util.py +388 -0
  868. wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
  869. wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
  870. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
  871. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
  872. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
  873. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
  874. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
  875. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
  876. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
  877. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
  878. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
  879. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
  880. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
  881. wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
  882. wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
  883. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
  884. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
  885. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
  886. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
  887. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
  888. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
  889. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
  890. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
  891. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
  892. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
  893. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
  894. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
  895. wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
  896. wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
  897. wandb/wandb_agent.py +580 -0
  898. wandb/wandb_controller.py +719 -0
  899. wandb/wandb_run.py +8 -0
  900. wandb-0.21.2.dist-info/METADATA +223 -0
  901. wandb-0.21.2.dist-info/RECORD +904 -0
  902. wandb-0.21.2.dist-info/WHEEL +4 -0
  903. wandb-0.21.2.dist-info/entry_points.txt +3 -0
  904. wandb-0.21.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1581 @@
1
+ """Defines wandb.init() and associated classes and methods.
2
+
3
+ `wandb.init()` indicates the beginning of a new run. In an ML training pipeline,
4
+ you could add `wandb.init()` to the beginning of your training script as well as
5
+ your evaluation script, and each step would be tracked as a run in W&B.
6
+
7
+ For more on using `wandb.init()`, including code snippets, check out our
8
+ [guide and FAQs](https://docs.wandb.ai/guides/track/launch).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import contextlib
14
+ import dataclasses
15
+ import json
16
+ import logging
17
+ import os
18
+ import pathlib
19
+ import platform
20
+ import sys
21
+ import tempfile
22
+ import time
23
+ from typing import TYPE_CHECKING, Iterable, Iterator, Sequence
24
+
25
+ from typing_extensions import Any, Literal, Protocol, Self
26
+
27
+ import wandb
28
+ import wandb.env
29
+ from wandb import env, trigger
30
+ from wandb.errors import CommError, Error, UsageError
31
+ from wandb.errors.links import url_registry
32
+ from wandb.errors.util import ProtobufErrorHandler
33
+ from wandb.integration import sagemaker, weave
34
+ from wandb.proto.wandb_deprecated import Deprecated
35
+ from wandb.sdk.lib import ipython as wb_ipython
36
+ from wandb.sdk.lib import progress, runid, wb_logging
37
+ from wandb.sdk.lib.paths import StrPath
38
+ from wandb.util import _is_artifact_representation
39
+
40
+ from . import wandb_login, wandb_setup
41
+ from .backend.backend import Backend
42
+ from .lib import SummaryDisabled, filesystem, module, paths, printer, telemetry
43
+ from .lib.deprecate import deprecate
44
+ from .mailbox import wait_with_progress
45
+ from .wandb_helper import parse_config
46
+ from .wandb_run import Run, TeardownHook, TeardownStage
47
+ from .wandb_settings import Settings
48
+
49
+ if TYPE_CHECKING:
50
+ import wandb.jupyter
51
+
52
+
53
+ def _huggingface_version() -> str | None:
54
+ if "transformers" in sys.modules:
55
+ trans = wandb.util.get_module("transformers")
56
+ if hasattr(trans, "__version__"):
57
+ return str(trans.__version__)
58
+ return None
59
+
60
+
61
+ def _handle_launch_config(settings: Settings) -> dict[str, Any]:
62
+ launch_run_config: dict[str, Any] = {}
63
+ if not settings.launch:
64
+ return launch_run_config
65
+ if os.environ.get("WANDB_CONFIG") is not None:
66
+ try:
67
+ launch_run_config = json.loads(os.environ.get("WANDB_CONFIG", "{}"))
68
+ except (ValueError, SyntaxError):
69
+ wandb.termwarn("Malformed WANDB_CONFIG, using original config")
70
+ elif settings.launch_config_path and os.path.exists(settings.launch_config_path):
71
+ with open(settings.launch_config_path) as fp:
72
+ launch_config = json.loads(fp.read())
73
+ launch_run_config = launch_config.get("overrides", {}).get("run_config")
74
+ else:
75
+ i = 0
76
+ chunks = []
77
+ while True:
78
+ key = f"WANDB_CONFIG_{i}"
79
+ if key in os.environ:
80
+ chunks.append(os.environ[key])
81
+ i += 1
82
+ else:
83
+ break
84
+ if len(chunks) > 0:
85
+ config_string = "".join(chunks)
86
+ try:
87
+ launch_run_config = json.loads(config_string)
88
+ except (ValueError, SyntaxError):
89
+ wandb.termwarn("Malformed WANDB_CONFIG, using original config")
90
+
91
+ return launch_run_config
92
+
93
+
94
+ @dataclasses.dataclass(frozen=True)
95
+ class _ConfigParts:
96
+ base_no_artifacts: dict[str, Any]
97
+ """The run config passed to `init()` minus any artifact-valued keys."""
98
+
99
+ sweep_no_artifacts: dict[str, Any]
100
+ """The config loaded as part of a sweep minus any artifact-valued keys."""
101
+
102
+ launch_no_artifacts: dict[str, Any]
103
+ """The config loaded as part of Launch minus any artifact-valued keys."""
104
+
105
+ artifacts: dict[str, Any]
106
+ """Artifact keys removed from config dictionaries.
107
+
108
+ Due to implementation details of how a Run is constructed,
109
+ artifacts must be inserted into its config after initialization.
110
+ """
111
+
112
+
113
+ class _PrinterCallback(Protocol):
114
+ """A callback for displaying messages after a printer is configured.
115
+
116
+ This is used for a few messages that may be generated before run settings
117
+ are computed, which are necessary for creating a printer.
118
+ """
119
+
120
+ def __call__(self, run_printer: printer.Printer) -> None:
121
+ """Display information through the given printer."""
122
+
123
+
124
+ def _noop_printer_callback() -> _PrinterCallback:
125
+ """A printer callback that does not print anything."""
126
+ return lambda _: None
127
+
128
+
129
+ def _concat_printer_callbacks(
130
+ cbs: Iterable[_PrinterCallback],
131
+ ) -> _PrinterCallback:
132
+ """Returns a printer callback that runs the given callbacks in order."""
133
+
134
+ def do_callbacks(run_printer: printer.Printer) -> None:
135
+ for cb in cbs:
136
+ cb(run_printer)
137
+
138
+ return do_callbacks
139
+
140
+
141
+ class _WandbInit:
142
+ def __init__(
143
+ self,
144
+ wl: wandb_setup._WandbSetup,
145
+ telemetry: telemetry.TelemetryRecord,
146
+ ) -> None:
147
+ self._wl = wl
148
+
149
+ self._telemetry = telemetry
150
+ """Telemetry gathered before creating a run.
151
+
152
+ After the run is created, `telemetry.context()` is used instead.
153
+ """
154
+
155
+ self.kwargs = None
156
+ self.run: Run | None = None
157
+ self.backend: Backend | None = None
158
+
159
+ self._teardown_hooks: list[TeardownHook] = []
160
+ self.notebook: wandb.jupyter.Notebook | None = None
161
+
162
+ self.deprecated_features_used: dict[str, str] = dict()
163
+
164
+ @property
165
+ def _logger(self) -> wandb_setup.Logger:
166
+ return self._wl._get_logger()
167
+
168
+ def maybe_login(self, init_settings: Settings) -> None:
169
+ """Log in if we are not creating an offline or disabled run.
170
+
171
+ This may change the W&B singleton settings.
172
+
173
+ Args:
174
+ init_settings: Settings passed to `wandb.init()` or set via
175
+ keyword arguments.
176
+ """
177
+ # Allow settings passed to init() to override inferred values.
178
+ #
179
+ # Calling login() may change settings on the singleton,
180
+ # so these may not be the final run settings.
181
+ run_settings = self._wl.settings.model_copy()
182
+ run_settings.update_from_settings(init_settings)
183
+
184
+ # NOTE: _noop or _offline can become true after _login().
185
+ # _noop happens if _login hits a timeout.
186
+ # _offline can be selected by the user at the login prompt.
187
+ if run_settings._noop or run_settings._offline:
188
+ return
189
+
190
+ wandb_login._login(
191
+ anonymous=run_settings.anonymous,
192
+ host=run_settings.base_url,
193
+ force=run_settings.force,
194
+ _disable_warning=True,
195
+ _silent=run_settings.quiet or run_settings.silent,
196
+ )
197
+
198
+ def warn_env_vars_change_after_setup(self) -> _PrinterCallback:
199
+ """Warn if environment variables changed after `wandb.setup()`.
200
+
201
+ Returns:
202
+ A callback to print any generated warnings.
203
+ """
204
+ if not self._wl.did_environment_change():
205
+ return _noop_printer_callback()
206
+
207
+ def print_warning(run_printer: printer.Printer) -> None:
208
+ line = (
209
+ "Changes to your `wandb` environment variables will be ignored "
210
+ "because your `wandb` session has already started. "
211
+ "For more information on how to modify your settings with "
212
+ "`wandb.init()` arguments, please refer to "
213
+ f"{run_printer.link(url_registry.url('wandb-init'), 'the W&B docs')}."
214
+ )
215
+ run_printer.display(line, level="warn")
216
+
217
+ return print_warning
218
+
219
+ def clear_run_path_if_sweep_or_launch(
220
+ self,
221
+ init_settings: Settings,
222
+ ) -> _PrinterCallback:
223
+ """Clear project/entity/run_id keys if in a Sweep or a Launch context.
224
+
225
+ Args:
226
+ init_settings: Settings specified in the call to `wandb.init()`.
227
+
228
+ Returns:
229
+ A callback to print any generated warnings.
230
+ """
231
+ when_doing_thing = ""
232
+
233
+ if self._wl.settings.sweep_id:
234
+ when_doing_thing = "when running a sweep"
235
+ elif self._wl.settings.launch:
236
+ when_doing_thing = "when running from a wandb launch context"
237
+
238
+ if not when_doing_thing:
239
+ return _noop_printer_callback()
240
+
241
+ warnings = []
242
+
243
+ def warn(key: str, value: str) -> None:
244
+ warnings.append(f"Ignoring {key} {value!r} {when_doing_thing}.")
245
+
246
+ if init_settings.project is not None:
247
+ warn("project", init_settings.project)
248
+ init_settings.project = None
249
+ if init_settings.entity is not None:
250
+ warn("entity", init_settings.entity)
251
+ init_settings.entity = None
252
+ if init_settings.run_id is not None:
253
+ warn("run_id", init_settings.run_id)
254
+ init_settings.run_id = None
255
+
256
+ def print_warnings(run_printer: printer.Printer) -> None:
257
+ for warning in warnings:
258
+ run_printer.display(warning, level="warn")
259
+
260
+ return print_warnings
261
+
262
+ def make_run_settings(
263
+ self,
264
+ init_settings: Settings,
265
+ ) -> tuple[Settings, _PrinterCallback]:
266
+ """Returns the run's settings and any warnings.
267
+
268
+ Args:
269
+ init_settings: Settings passed to `wandb.init()` or set via
270
+ keyword arguments.
271
+ """
272
+ warning_callbacks: list[_PrinterCallback] = [
273
+ self.warn_env_vars_change_after_setup(),
274
+ self.clear_run_path_if_sweep_or_launch(init_settings),
275
+ ]
276
+
277
+ # Inherit global settings.
278
+ settings = self._wl.settings.model_copy()
279
+
280
+ # Apply settings from wandb.init() call.
281
+ settings.update_from_settings(init_settings)
282
+
283
+ # Infer the run ID from SageMaker.
284
+ if not settings.sagemaker_disable and sagemaker.is_using_sagemaker():
285
+ if sagemaker.set_run_id(settings):
286
+ self._logger.info("set run ID and group based on SageMaker")
287
+ self._telemetry.feature.sagemaker = True
288
+
289
+ # get status of code saving before applying user settings
290
+ save_code_pre_user_settings = settings.save_code
291
+ if not settings._offline and not settings._noop:
292
+ user_settings = self._wl._load_user_settings()
293
+ if user_settings is not None:
294
+ settings.update_from_dict(user_settings)
295
+
296
+ # ensure that user settings don't set saving to true
297
+ # if user explicitly set these to false in UI
298
+ if save_code_pre_user_settings is False:
299
+ settings.save_code = False
300
+
301
+ # TODO: remove this once we refactor the client. This is a temporary
302
+ # fix to make sure that we use the same project name for wandb-core.
303
+ # The reason this is not going through the settings object is to
304
+ # avoid failure cases in other parts of the code that will be
305
+ # removed with the switch to wandb-core.
306
+ if settings.project is None:
307
+ settings.project = wandb.util.auto_project_name(settings.program)
308
+
309
+ settings.x_start_time = time.time()
310
+
311
+ # In shared mode, generate a unique label if not provided.
312
+ # The label is used to distinguish between system metrics and console logs
313
+ # from different writers to the same run.
314
+ if settings._shared and not settings.x_label:
315
+ # TODO: If executed in a known distributed environment (e.g. Ray or SLURM),
316
+ # use the env vars to generate a label (e.g. SLURM_JOB_ID or RANK)
317
+ prefix = settings.host or ""
318
+ label = runid.generate_id()
319
+ settings.x_label = f"{prefix}-{label}" if prefix else label
320
+
321
+ return settings, _concat_printer_callbacks(warning_callbacks)
322
+
323
+ def _load_autoresume_run_id(self, resume_file: pathlib.Path) -> str | None:
324
+ """Returns the run_id stored in the auto-resume file, if any.
325
+
326
+ Returns `None` if the file does not exist or is not in a valid format.
327
+
328
+ Args:
329
+ resume_file: The file path to use for resume='auto' mode.
330
+ """
331
+ if not resume_file.exists():
332
+ return None
333
+
334
+ with resume_file.open() as f:
335
+ try:
336
+ return json.load(f)["run_id"]
337
+
338
+ except json.JSONDecodeError as e:
339
+ self._logger.exception(
340
+ f"could not decode {resume_file}, ignoring",
341
+ exc_info=e,
342
+ )
343
+ return None
344
+
345
+ except KeyError:
346
+ self._logger.exception(
347
+ f"resume file at {resume_file} did not store a run_id"
348
+ )
349
+ return None
350
+
351
+ def _save_autoresume_run_id(
352
+ self,
353
+ *,
354
+ resume_file: pathlib.Path,
355
+ run_id: str,
356
+ ) -> None:
357
+ """Write the run ID to the auto-resume file."""
358
+ resume_file.parent.mkdir(exist_ok=True)
359
+ with resume_file.open("w") as f:
360
+ json.dump({"run_id": run_id}, f)
361
+
362
+ def set_run_id(self, settings: Settings) -> None:
363
+ """Set the run ID and possibly save it to the auto-resume file.
364
+
365
+ After this, `settings.run_id` is guaranteed to be set.
366
+
367
+ If a `resume_from` is provided and `run_id` is not set, initialize
368
+ `run_id` with the `resume_from` run's `run_id`.
369
+
370
+ Args:
371
+ settings: The run's settings derived from the environment
372
+ and explicit values passed to `wandb.init()`.
373
+ """
374
+ if settings.resume == "auto" and settings.resume_fname:
375
+ resume_path = pathlib.Path(settings.resume_fname)
376
+ else:
377
+ resume_path = None
378
+
379
+ if resume_path:
380
+ previous_id = self._load_autoresume_run_id(resume_path)
381
+
382
+ if not previous_id:
383
+ pass
384
+ elif settings.run_id is None:
385
+ self._logger.info(f"loaded run ID from {resume_path}")
386
+ settings.run_id = previous_id
387
+ elif settings.run_id != previous_id:
388
+ wandb.termwarn(
389
+ f"Ignoring ID {previous_id} loaded due to resume='auto'"
390
+ f" because the run ID is set to {settings.run_id}.",
391
+ )
392
+
393
+ # If no run ID was inferred, explicitly set, or loaded from an
394
+ # auto-resume file, then we generate a new ID.
395
+ if settings.run_id is None:
396
+ # If resume_from is provided and run_id is not already set,
397
+ # initialize run_id with the value from resume_from.
398
+ if settings.resume_from:
399
+ settings.run_id = settings.resume_from.run
400
+ else:
401
+ settings.run_id = runid.generate_id()
402
+
403
+ if resume_path:
404
+ self._save_autoresume_run_id(
405
+ resume_file=resume_path,
406
+ run_id=settings.run_id,
407
+ )
408
+
409
+ def make_run_config(
410
+ self,
411
+ settings: Settings,
412
+ config: dict | str | None = None,
413
+ config_exclude_keys: list[str] | None = None,
414
+ config_include_keys: list[str] | None = None,
415
+ ) -> _ConfigParts:
416
+ """Construct the run's config.
417
+
418
+ Args:
419
+ settings: The run's finalized settings.
420
+ config: The config passed to `init()`.
421
+ config_exclude_keys: Deprecated. Keys to filter out from `config`.
422
+ config_include_keys: Deprecated. Keys to include from `config`.
423
+
424
+ Returns:
425
+ Initial values for the run's config.
426
+ """
427
+ if config_exclude_keys:
428
+ self.deprecated_features_used["init__config_exclude_keys"] = (
429
+ "config_exclude_keys is deprecated. Use"
430
+ " `config=wandb.helper.parse_config(config_object,"
431
+ " exclude=('key',))` instead."
432
+ )
433
+ if config_include_keys:
434
+ self.deprecated_features_used["init__config_include_keys"] = (
435
+ "config_include_keys is deprecated. Use"
436
+ " `config=wandb.helper.parse_config(config_object,"
437
+ " include=('key',))` instead."
438
+ )
439
+ config = parse_config(
440
+ config or dict(),
441
+ include=config_include_keys,
442
+ exclude=config_exclude_keys,
443
+ )
444
+
445
+ result = _ConfigParts(
446
+ base_no_artifacts=dict(),
447
+ sweep_no_artifacts=dict(),
448
+ launch_no_artifacts=dict(),
449
+ artifacts=dict(),
450
+ )
451
+
452
+ if not settings.sagemaker_disable and sagemaker.is_using_sagemaker():
453
+ sagemaker_config = sagemaker.parse_sm_config()
454
+ self._split_artifacts_from_config(
455
+ sagemaker_config,
456
+ config_target=result.base_no_artifacts,
457
+ artifacts=result.artifacts,
458
+ )
459
+ self._telemetry.feature.sagemaker = True
460
+
461
+ if self._wl.config:
462
+ self._split_artifacts_from_config(
463
+ self._wl.config,
464
+ config_target=result.base_no_artifacts,
465
+ artifacts=result.artifacts,
466
+ )
467
+
468
+ if config and isinstance(config, dict):
469
+ self._split_artifacts_from_config(
470
+ config,
471
+ config_target=result.base_no_artifacts,
472
+ artifacts=result.artifacts,
473
+ )
474
+
475
+ if self._wl._sweep_config:
476
+ self._split_artifacts_from_config(
477
+ self._wl._sweep_config,
478
+ config_target=result.sweep_no_artifacts,
479
+ artifacts=result.artifacts,
480
+ )
481
+
482
+ if launch_config := _handle_launch_config(settings):
483
+ self._split_artifacts_from_config(
484
+ launch_config,
485
+ config_target=result.launch_no_artifacts,
486
+ artifacts=result.artifacts,
487
+ )
488
+
489
+ wandb_internal = result.base_no_artifacts.setdefault("_wandb", dict())
490
+
491
+ if settings.save_code and settings.program_relpath:
492
+ wandb_internal["code_path"] = paths.LogicalPath(
493
+ os.path.join("code", settings.program_relpath)
494
+ )
495
+ if settings.fork_from is not None:
496
+ wandb_internal["branch_point"] = {
497
+ "run_id": settings.fork_from.run,
498
+ "step": settings.fork_from.value,
499
+ }
500
+ if settings.resume_from is not None:
501
+ wandb_internal["branch_point"] = {
502
+ "run_id": settings.resume_from.run,
503
+ "step": settings.resume_from.value,
504
+ }
505
+
506
+ return result
507
+
508
+ def teardown(self) -> None:
509
+ # TODO: currently this is only called on failed wandb.init attempts
510
+ # normally this happens on the run object
511
+ self._logger.info("tearing down wandb.init")
512
+ for hook in self._teardown_hooks:
513
+ hook.call()
514
+
515
+ def _split_artifacts_from_config(
516
+ self,
517
+ config_source: dict,
518
+ config_target: dict,
519
+ artifacts: dict,
520
+ ) -> None:
521
+ for k, v in config_source.items():
522
+ if _is_artifact_representation(v):
523
+ artifacts[k] = v
524
+ else:
525
+ config_target.setdefault(k, v)
526
+
527
+ def _safe_symlink(
528
+ self, base: str, target: str, name: str, delete: bool = False
529
+ ) -> None:
530
+ # TODO(jhr): do this with relpaths, but i can't figure it out on no sleep
531
+ if not hasattr(os, "symlink"):
532
+ return
533
+
534
+ pid = os.getpid()
535
+ tmp_name = os.path.join(base, f"{name}.{pid}")
536
+
537
+ if delete:
538
+ try:
539
+ os.remove(os.path.join(base, name))
540
+ except OSError:
541
+ pass
542
+ target = os.path.relpath(target, base)
543
+ try:
544
+ os.symlink(target, tmp_name)
545
+ os.rename(tmp_name, os.path.join(base, name))
546
+ except OSError:
547
+ pass
548
+
549
+ def _pre_run_cell_hook(self, *args, **kwargs) -> None:
550
+ """Hook for the IPython pre_run_cell event.
551
+
552
+ This pauses a run, preventing system metrics from being collected
553
+ the run's runtime from increasing. It also uploads the notebook's code.
554
+ """
555
+ if not self.backend:
556
+ return
557
+
558
+ if self.notebook and self.notebook.save_ipynb():
559
+ assert self.run is not None
560
+ res = self.run.log_code(root=None)
561
+ self._logger.info("saved code: %s", res)
562
+
563
+ if self.backend.interface is not None:
564
+ self._logger.info("pausing backend")
565
+ self.backend.interface.publish_pause()
566
+
567
+ def _post_run_cell_hook(self, *args, **kwargs) -> None:
568
+ """Hook for the IPython post_run_cell event.
569
+
570
+ Resumes collection of system metrics and the run's timer.
571
+ """
572
+ if self.backend is None or self.backend.interface is None:
573
+ return
574
+
575
+ self._logger.info("resuming backend")
576
+ self.backend.interface.publish_resume()
577
+
578
+ def _jupyter_teardown(self) -> None:
579
+ """Teardown hooks and display saving, called with wandb.finish."""
580
+ assert self.notebook
581
+ ipython = self.notebook.shell
582
+
583
+ if self.run:
584
+ self.notebook.save_history(self.run)
585
+
586
+ if self.notebook.save_ipynb():
587
+ assert self.run is not None
588
+ res = self.run.log_code(root=None)
589
+ self._logger.info("saved code and history: %s", res)
590
+ self._logger.info("cleaning up jupyter logic")
591
+
592
+ ipython.events.unregister("pre_run_cell", self._pre_run_cell_hook)
593
+ ipython.events.unregister("post_run_cell", self._post_run_cell_hook)
594
+
595
+ ipython.display_pub.publish = ipython.display_pub._orig_publish
596
+ del ipython.display_pub._orig_publish
597
+
598
+ def monkeypatch_ipython(self, settings: Settings) -> None:
599
+ """Add hooks, and session history saving."""
600
+ self.notebook = wandb.jupyter.Notebook(settings)
601
+ ipython = self.notebook.shell
602
+
603
+ # Monkey patch ipython publish to capture displayed outputs
604
+ if not hasattr(ipython.display_pub, "_orig_publish"):
605
+ self._logger.info("configuring jupyter hooks %s", self)
606
+ ipython.display_pub._orig_publish = ipython.display_pub.publish
607
+
608
+ ipython.events.register("pre_run_cell", self._pre_run_cell_hook)
609
+ ipython.events.register("post_run_cell", self._post_run_cell_hook)
610
+
611
+ self._teardown_hooks.append(
612
+ TeardownHook(self._jupyter_teardown, TeardownStage.EARLY)
613
+ )
614
+
615
+ def publish(data, metadata=None, **kwargs) -> None:
616
+ ipython.display_pub._orig_publish(data, metadata=metadata, **kwargs)
617
+ assert self.notebook is not None
618
+ self.notebook.save_display(
619
+ ipython.execution_count, {"data": data, "metadata": metadata}
620
+ )
621
+
622
+ ipython.display_pub.publish = publish
623
+
624
+ @contextlib.contextmanager
625
+ def setup_run_log_directory(self, settings: Settings) -> Iterator[None]:
626
+ """Set up the run's log directory.
627
+
628
+ This is a context manager that closes and unregisters the log handler
629
+ in case of an uncaught exception, so that future logged messages do not
630
+ modify this run's log file.
631
+ """
632
+ filesystem.mkdir_exists_ok(os.path.dirname(settings.log_user))
633
+ filesystem.mkdir_exists_ok(os.path.dirname(settings.log_internal))
634
+ filesystem.mkdir_exists_ok(os.path.dirname(settings.sync_file))
635
+ filesystem.mkdir_exists_ok(settings.files_dir)
636
+ filesystem.mkdir_exists_ok(settings._tmp_code_dir)
637
+
638
+ if settings.symlink:
639
+ self._safe_symlink(
640
+ os.path.dirname(settings.sync_symlink_latest),
641
+ os.path.dirname(settings.sync_file),
642
+ os.path.basename(settings.sync_symlink_latest),
643
+ delete=True,
644
+ )
645
+ self._safe_symlink(
646
+ os.path.dirname(settings.log_symlink_user),
647
+ settings.log_user,
648
+ os.path.basename(settings.log_symlink_user),
649
+ delete=True,
650
+ )
651
+ self._safe_symlink(
652
+ os.path.dirname(settings.log_symlink_internal),
653
+ settings.log_internal,
654
+ os.path.basename(settings.log_symlink_internal),
655
+ delete=True,
656
+ )
657
+
658
+ assert settings.run_id
659
+ handler = wb_logging.add_file_handler(
660
+ settings.run_id,
661
+ pathlib.Path(settings.log_user),
662
+ )
663
+
664
+ if env.is_debug():
665
+ handler.setLevel(logging.DEBUG)
666
+
667
+ disposed = False
668
+
669
+ def dispose_handler() -> None:
670
+ nonlocal disposed
671
+
672
+ if not disposed:
673
+ disposed = True
674
+ logging.getLogger("wandb").removeHandler(handler)
675
+ handler.close()
676
+
677
+ try:
678
+ self._teardown_hooks.append(
679
+ TeardownHook(
680
+ call=dispose_handler,
681
+ stage=TeardownStage.LATE,
682
+ )
683
+ )
684
+
685
+ self._wl._early_logger_flush(logging.getLogger("wandb"))
686
+ self._logger.info(f"Logging user logs to {settings.log_user}")
687
+ self._logger.info(f"Logging internal logs to {settings.log_internal}")
688
+
689
+ yield
690
+ except Exception:
691
+ dispose_handler()
692
+ raise
693
+
694
+ def make_disabled_run(self, config: _ConfigParts) -> Run:
695
+ """Returns a Run-like object where all methods are no-ops.
696
+
697
+ This method is used when the `mode` setting is set to "disabled", such as
698
+ by wandb.init(mode="disabled") or by setting the WANDB_MODE environment
699
+ variable to "disabled".
700
+
701
+ It creates a Run object that mimics the behavior of a normal Run but doesn't
702
+ communicate with the W&B servers.
703
+
704
+ The returned Run object has all expected attributes and methods, but they
705
+ are no-op versions that don't perform any actual logging or communication.
706
+ """
707
+ run_id = runid.generate_id()
708
+ drun = Run(
709
+ settings=Settings(
710
+ mode="disabled",
711
+ x_files_dir=tempfile.gettempdir(),
712
+ run_id=run_id,
713
+ run_tags=tuple(),
714
+ run_notes=None,
715
+ run_group=None,
716
+ run_name=f"dummy-{run_id}",
717
+ project="dummy",
718
+ entity="dummy",
719
+ )
720
+ )
721
+ # config, summary, and metadata objects
722
+ drun._config = wandb.sdk.wandb_config.Config()
723
+ drun._config.update(config.sweep_no_artifacts)
724
+ drun._config.update(config.base_no_artifacts)
725
+ drun.summary = SummaryDisabled() # type: ignore
726
+
727
+ # methods
728
+ drun.log = lambda data, *_, **__: drun.summary.update(data) # type: ignore[method-assign]
729
+ drun.finish = lambda *_, **__: module.unset_globals() # type: ignore[method-assign]
730
+ drun.join = drun.finish # type: ignore[method-assign]
731
+ drun.define_metric = lambda *_, **__: wandb.sdk.wandb_metric.Metric("dummy") # type: ignore[method-assign]
732
+ drun.save = lambda *_, **__: False # type: ignore[method-assign]
733
+ for symbol in (
734
+ "alert",
735
+ "finish_artifact",
736
+ "get_project_url",
737
+ "get_sweep_url",
738
+ "get_url",
739
+ "link_artifact",
740
+ "link_model",
741
+ "use_artifact",
742
+ "log_code",
743
+ "log_model",
744
+ "use_model",
745
+ "mark_preempting",
746
+ "restore",
747
+ "status",
748
+ "watch",
749
+ "unwatch",
750
+ "upsert_artifact",
751
+ "_finish",
752
+ ):
753
+ setattr(drun, symbol, lambda *_, **__: None) # type: ignore
754
+
755
+ # set properties to None
756
+ for attr in ("url", "project_url", "sweep_url"):
757
+ setattr(type(drun), attr, property(lambda _: None))
758
+
759
+ class _ChainableNoOp:
760
+ """An object that allows chaining arbitrary attributes and method calls."""
761
+
762
+ def __getattr__(self, _: str) -> Self:
763
+ return self
764
+
765
+ def __call__(self, *_: Any, **__: Any) -> Self:
766
+ return self
767
+
768
+ class _ChainableNoOpField:
769
+ # This is used to chain arbitrary attributes and method calls.
770
+ # For example, `run.log_artifact().state` will work in disabled mode.
771
+ def __init__(self) -> None:
772
+ self._value = None
773
+
774
+ def __set__(self, instance: Any, value: Any) -> None:
775
+ self._value = value
776
+
777
+ def __get__(self, instance: Any, owner: type) -> Any:
778
+ return _ChainableNoOp() if (self._value is None) else self._value
779
+
780
+ def __call__(self, *args: Any, **kwargs: Any) -> _ChainableNoOp:
781
+ return _ChainableNoOp()
782
+
783
+ drun.log_artifact = _ChainableNoOpField() # type: ignore
784
+ # attributes
785
+ drun._start_time = time.time()
786
+ drun._starting_step = 0
787
+ drun._step = 0
788
+ drun._attach_id = None
789
+ drun._backend = None
790
+
791
+ # set the disabled run as the global run
792
+ module.set_global(
793
+ run=drun,
794
+ config=drun.config,
795
+ log=drun.log,
796
+ summary=drun.summary,
797
+ save=drun.save,
798
+ use_artifact=drun.use_artifact,
799
+ log_artifact=drun.log_artifact,
800
+ define_metric=drun.define_metric,
801
+ alert=drun.alert,
802
+ watch=drun.watch,
803
+ unwatch=drun.unwatch,
804
+ )
805
+ return drun
806
+
807
+ def init( # noqa: C901
808
+ self,
809
+ settings: Settings,
810
+ config: _ConfigParts,
811
+ run_printer: printer.Printer,
812
+ ) -> Run:
813
+ self._logger.info("calling init triggers")
814
+ trigger.call("on_init")
815
+
816
+ assert self._wl is not None
817
+
818
+ self._logger.info(
819
+ f"wandb.init called with sweep_config: {config.sweep_no_artifacts}"
820
+ f"\nconfig: {config.base_no_artifacts}"
821
+ )
822
+
823
+ if previous_run := self._wl.most_recent_active_run:
824
+ if (
825
+ settings.reinit in (True, "finish_previous")
826
+ # calling wandb.init() in notebooks finishes previous runs
827
+ # by default for user convenience.
828
+ or (settings.reinit == "default" and wb_ipython.in_notebook())
829
+ ):
830
+ run_printer.display(
831
+ "Finishing previous runs because reinit is set"
832
+ f" to {settings.reinit!r}."
833
+ )
834
+ self._wl.finish_all_active_runs()
835
+
836
+ elif settings.reinit == "create_new":
837
+ self._logger.info(
838
+ "wandb.init() called while a run is active,"
839
+ " and reinit is set to 'create_new', so continuing"
840
+ )
841
+
842
+ else:
843
+ run_printer.display(
844
+ "wandb.init() called while a run is active and reinit is"
845
+ f" set to {settings.reinit!r}, so returning the previous"
846
+ " run."
847
+ )
848
+
849
+ with telemetry.context(run=previous_run) as tel:
850
+ tel.feature.init_return_run = True
851
+
852
+ return previous_run
853
+
854
+ self._logger.info("starting backend")
855
+
856
+ service = self._wl.ensure_service()
857
+ self._logger.info("sending inform_init request")
858
+ service.inform_init(
859
+ settings=settings.to_proto(),
860
+ run_id=settings.run_id, # type: ignore
861
+ )
862
+
863
+ backend = Backend(settings=settings, service=service)
864
+ backend.ensure_launched()
865
+ self._logger.info("backend started and connected")
866
+
867
+ # resuming needs access to the server, check server_status()?
868
+ run = Run(
869
+ config=config.base_no_artifacts,
870
+ settings=settings,
871
+ sweep_config=config.sweep_no_artifacts,
872
+ launch_config=config.launch_no_artifacts,
873
+ )
874
+
875
+ # Populate initial telemetry
876
+ with telemetry.context(run=run, obj=self._telemetry) as tel:
877
+ tel.cli_version = wandb.__version__
878
+ tel.python_version = platform.python_version()
879
+ tel.platform = f"{platform.system()}-{platform.machine()}".lower()
880
+ hf_version = _huggingface_version()
881
+ if hf_version:
882
+ tel.huggingface_version = hf_version
883
+ if settings._jupyter:
884
+ tel.env.jupyter = True
885
+ if settings._ipython:
886
+ tel.env.ipython = True
887
+ if settings._colab:
888
+ tel.env.colab = True
889
+ if settings._kaggle:
890
+ tel.env.kaggle = True
891
+ if settings._windows:
892
+ tel.env.windows = True
893
+
894
+ if settings.launch:
895
+ tel.feature.launch = True
896
+
897
+ for module_name in telemetry.list_telemetry_imports(only_imported=True):
898
+ setattr(tel.imports_init, module_name, True)
899
+
900
+ if os.environ.get("PEX"):
901
+ tel.env.pex = True
902
+
903
+ if settings._aws_lambda:
904
+ tel.env.aws_lambda = True
905
+
906
+ if settings.x_flow_control_disabled:
907
+ tel.feature.flow_control_disabled = True
908
+ if settings.x_flow_control_custom:
909
+ tel.feature.flow_control_custom = True
910
+ if settings._shared:
911
+ wandb.termwarn(
912
+ "The `shared` mode feature is experimental and may change. "
913
+ "Please contact support@wandb.com for guidance and to report any issues."
914
+ )
915
+ tel.feature.shared_mode = True
916
+
917
+ if settings.x_label:
918
+ tel.feature.user_provided_label = True
919
+
920
+ if wandb.env.dcgm_profiling_enabled():
921
+ tel.feature.dcgm_profiling_enabled = True
922
+
923
+ if not settings.label_disable:
924
+ if self.notebook:
925
+ run._label_probe_notebook(self.notebook)
926
+ else:
927
+ run._label_probe_main()
928
+
929
+ for deprecated_feature, msg in self.deprecated_features_used.items():
930
+ deprecate(
931
+ field_name=getattr(Deprecated, deprecated_feature),
932
+ warning_message=msg,
933
+ run=run,
934
+ )
935
+
936
+ self._logger.info("updated telemetry")
937
+
938
+ run._set_library(self._wl)
939
+ run._set_backend(backend)
940
+ run._set_teardown_hooks(self._teardown_hooks)
941
+
942
+ assert backend.interface
943
+ backend.interface.publish_header()
944
+
945
+ # Using GitRepo() blocks & can be slow, depending on user's current git setup.
946
+ # We don't want to block run initialization/start request, so populate run's git
947
+ # info beforehand.
948
+ if not (settings.disable_git or settings.x_disable_machine_info):
949
+ run._populate_git_info()
950
+
951
+ if settings._offline and settings.resume:
952
+ wandb.termwarn(
953
+ "`resume` will be ignored since W&B syncing is set to `offline`. "
954
+ f"Starting a new run with run id {run.id}."
955
+ )
956
+ error: wandb.Error | None = None
957
+
958
+ timeout = settings.init_timeout
959
+
960
+ self._logger.info(
961
+ f"communicating run to backend with {timeout} second timeout",
962
+ )
963
+
964
+ run_init_handle = backend.interface.deliver_run(run)
965
+
966
+ async def display_init_message() -> None:
967
+ assert backend.interface
968
+
969
+ with progress.progress_printer(
970
+ run_printer,
971
+ default_text="Waiting for wandb.init()...",
972
+ ) as progress_printer:
973
+ await progress.loop_printing_operation_stats(
974
+ progress_printer,
975
+ backend.interface,
976
+ )
977
+
978
+ try:
979
+ result = wait_with_progress(
980
+ run_init_handle,
981
+ timeout=timeout,
982
+ display_progress=display_init_message,
983
+ )
984
+
985
+ except TimeoutError:
986
+ run_init_handle.cancel(backend.interface)
987
+
988
+ # This may either be an issue with the W&B server (a CommError)
989
+ # or a bug in the SDK (an Error). We cannot distinguish between
990
+ # the two causes here.
991
+ raise CommError(
992
+ f"Run initialization has timed out after {timeout} sec."
993
+ " Please try increasing the timeout with the `init_timeout`"
994
+ " setting: `wandb.init(settings=wandb.Settings(init_timeout=120))`."
995
+ )
996
+
997
+ assert result.run_result
998
+
999
+ if error := ProtobufErrorHandler.to_exception(result.run_result.error):
1000
+ raise error
1001
+
1002
+ if not result.run_result.HasField("run"):
1003
+ raise Error("Assertion failed: run_result is missing the run field")
1004
+
1005
+ if result.run_result.run.resumed:
1006
+ self._logger.info("run resumed")
1007
+ with telemetry.context(run=run) as tel:
1008
+ tel.feature.resumed = result.run_result.run.resumed
1009
+ run._set_run_obj(result.run_result.run)
1010
+
1011
+ self._logger.info("starting run threads in backend")
1012
+ # initiate run (stats and metadata probing)
1013
+
1014
+ if service:
1015
+ assert settings.run_id
1016
+ service.inform_start(
1017
+ settings=settings.to_proto(),
1018
+ run_id=settings.run_id,
1019
+ )
1020
+
1021
+ assert backend.interface
1022
+
1023
+ run_start_handle = backend.interface.deliver_run_start(run)
1024
+ try:
1025
+ # TODO: add progress to let user know we are doing something
1026
+ run_start_handle.wait_or(timeout=30)
1027
+ except TimeoutError:
1028
+ pass
1029
+
1030
+ assert self._wl is not None
1031
+ self.run = run
1032
+
1033
+ run._handle_launch_artifact_overrides()
1034
+ if (
1035
+ settings.launch
1036
+ and settings.launch_config_path
1037
+ and os.path.exists(settings.launch_config_path)
1038
+ ):
1039
+ run.save(settings.launch_config_path)
1040
+ # put artifacts in run config here
1041
+ # since doing so earlier will cause an error
1042
+ # as the run is not upserted
1043
+ for k, v in config.artifacts.items():
1044
+ run.config.update({k: v}, allow_val_change=True)
1045
+ job_artifact = run._launch_artifact_mapping.get(
1046
+ wandb.util.LAUNCH_JOB_ARTIFACT_SLOT_NAME
1047
+ )
1048
+ if job_artifact:
1049
+ run.use_artifact(job_artifact)
1050
+
1051
+ self.backend = backend
1052
+
1053
+ if settings.reinit != "create_new":
1054
+ _set_global_run(run)
1055
+
1056
+ run._on_start()
1057
+ self._logger.info("run started, returning control to user process")
1058
+ return run
1059
+
1060
+
1061
+ def _attach(
1062
+ attach_id: str | None = None,
1063
+ run_id: str | None = None,
1064
+ *,
1065
+ run: Run | None = None,
1066
+ ) -> Run | None:
1067
+ """Attach to a run currently executing in another process/thread.
1068
+
1069
+ Args:
1070
+ attach_id: (str, optional) The id of the run or an attach identifier
1071
+ that maps to a run.
1072
+ run_id: (str, optional) The id of the run to attach to.
1073
+ run: (Run, optional) The run instance to attach
1074
+ """
1075
+ attach_id = attach_id or run_id
1076
+ if not ((attach_id is None) ^ (run is None)):
1077
+ raise UsageError("Either (`attach_id` or `run_id`) or `run` must be specified")
1078
+
1079
+ attach_id = attach_id or (run._attach_id if run else None)
1080
+
1081
+ if attach_id is None:
1082
+ raise UsageError(
1083
+ "Either `attach_id` or `run_id` must be specified or `run` must have `_attach_id`"
1084
+ )
1085
+ wandb._assert_is_user_process() # type: ignore
1086
+
1087
+ _wl = wandb_setup.singleton()
1088
+ logger = _wl._get_logger()
1089
+
1090
+ service = _wl.ensure_service()
1091
+
1092
+ try:
1093
+ attach_settings = service.inform_attach(attach_id=attach_id)
1094
+ except Exception as e:
1095
+ raise UsageError(f"Unable to attach to run {attach_id}") from e
1096
+
1097
+ settings = _wl.settings.model_copy()
1098
+ settings.update_from_dict(
1099
+ {
1100
+ "run_id": attach_id,
1101
+ "x_start_time": attach_settings.x_start_time.value,
1102
+ "mode": attach_settings.mode.value,
1103
+ }
1104
+ )
1105
+
1106
+ # TODO: consolidate this codepath with wandb.init()
1107
+ backend = Backend(settings=settings, service=service)
1108
+ backend.ensure_launched()
1109
+ logger.info("attach backend started and connected")
1110
+
1111
+ if run is None:
1112
+ run = Run(settings=settings)
1113
+ else:
1114
+ run._init(settings=settings)
1115
+ run._set_library(_wl)
1116
+ run._set_backend(backend)
1117
+ assert backend.interface
1118
+
1119
+ attach_handle = backend.interface.deliver_attach(attach_id)
1120
+ try:
1121
+ # TODO: add progress to let user know we are doing something
1122
+ attach_result = attach_handle.wait_or(timeout=30)
1123
+ except TimeoutError:
1124
+ raise UsageError("Timeout attaching to run")
1125
+
1126
+ attach_response = attach_result.response.attach_response
1127
+ if attach_response.error and attach_response.error.message:
1128
+ raise UsageError(f"Failed to attach to run: {attach_response.error.message}")
1129
+
1130
+ run._set_run_obj(attach_response.run)
1131
+ _set_global_run(run)
1132
+ run._on_attach()
1133
+ return run
1134
+
1135
+
1136
+ def _set_global_run(run: Run) -> None:
1137
+ """Set `wandb.run` and point some top-level functions to its methods.
1138
+
1139
+ Args:
1140
+ run: The run to make global.
1141
+ """
1142
+ module.set_global(
1143
+ run=run,
1144
+ config=run.config,
1145
+ log=run.log,
1146
+ summary=run.summary,
1147
+ save=run.save,
1148
+ use_artifact=run.use_artifact,
1149
+ log_artifact=run.log_artifact,
1150
+ define_metric=run.define_metric,
1151
+ alert=run.alert,
1152
+ watch=run.watch,
1153
+ unwatch=run.unwatch,
1154
+ mark_preempting=run.mark_preempting,
1155
+ log_model=run.log_model,
1156
+ use_model=run.use_model,
1157
+ link_model=run.link_model,
1158
+ )
1159
+
1160
+
1161
+ def _monkeypatch_openai_gym() -> None:
1162
+ """Patch OpenAI gym to log to the global `wandb.run`."""
1163
+ if len(wandb.patched["gym"]) > 0:
1164
+ return
1165
+
1166
+ from wandb.integration import gym
1167
+
1168
+ gym.monitor()
1169
+
1170
+
1171
+ def _monkeypatch_tensorboard() -> None:
1172
+ """Patch TensorBoard to log to the global `wandb.run`."""
1173
+ if len(wandb.patched["tensorboard"]) > 0:
1174
+ return
1175
+
1176
+ from wandb.integration import tensorboard as tb_module
1177
+
1178
+ tb_module.patch()
1179
+
1180
+
1181
+ def try_create_root_dir(settings: Settings) -> None:
1182
+ """Try to create the root directory specified in settings.
1183
+
1184
+ If creation fails due to permissions or other errors,
1185
+ falls back to using the system temp directory.
1186
+
1187
+ Args:
1188
+ settings: The runs settings containing root_dir configuration.
1189
+ This function may update the root_dir to a temporary directory
1190
+ if the parent directory is not writable.
1191
+ """
1192
+ fallback_to_temp_dir = False
1193
+
1194
+ try:
1195
+ os.makedirs(settings.root_dir, exist_ok=True)
1196
+ except OSError:
1197
+ wandb.termwarn(
1198
+ f"Unable to create root directory {settings.root_dir}",
1199
+ repeat=False,
1200
+ )
1201
+ fallback_to_temp_dir = True
1202
+ else:
1203
+ if not os.access(settings.root_dir, os.W_OK | os.R_OK):
1204
+ wandb.termwarn(
1205
+ f"Path {settings.root_dir} wasn't read/writable",
1206
+ repeat=False,
1207
+ )
1208
+ fallback_to_temp_dir = True
1209
+
1210
+ if not fallback_to_temp_dir:
1211
+ return
1212
+
1213
+ tmp_dir = tempfile.gettempdir()
1214
+ if not os.access(tmp_dir, os.W_OK | os.R_OK):
1215
+ raise ValueError(
1216
+ f"System temp directory ({tmp_dir}) is not writable/readable, "
1217
+ "please set the `dir` argument in `wandb.init()` to a writable/readable directory."
1218
+ )
1219
+
1220
+ settings.root_dir = tmp_dir
1221
+ wandb.termwarn(
1222
+ f"Falling back to temporary directory {tmp_dir}.",
1223
+ repeat=False,
1224
+ )
1225
+ os.makedirs(settings.root_dir, exist_ok=True)
1226
+
1227
+
1228
+ def init( # noqa: C901
1229
+ entity: str | None = None,
1230
+ project: str | None = None,
1231
+ dir: StrPath | None = None,
1232
+ id: str | None = None,
1233
+ name: str | None = None,
1234
+ notes: str | None = None,
1235
+ tags: Sequence[str] | None = None,
1236
+ config: dict[str, Any] | str | None = None,
1237
+ config_exclude_keys: list[str] | None = None,
1238
+ config_include_keys: list[str] | None = None,
1239
+ allow_val_change: bool | None = None,
1240
+ group: str | None = None,
1241
+ job_type: str | None = None,
1242
+ mode: Literal["online", "offline", "disabled", "shared"] | None = None,
1243
+ force: bool | None = None,
1244
+ anonymous: Literal["never", "allow", "must"] | None = None,
1245
+ reinit: (
1246
+ bool
1247
+ | Literal[
1248
+ None,
1249
+ "default",
1250
+ "return_previous",
1251
+ "finish_previous",
1252
+ "create_new",
1253
+ ]
1254
+ ) = None,
1255
+ resume: bool | Literal["allow", "never", "must", "auto"] | None = None,
1256
+ resume_from: str | None = None,
1257
+ fork_from: str | None = None,
1258
+ save_code: bool | None = None,
1259
+ tensorboard: bool | None = None,
1260
+ sync_tensorboard: bool | None = None,
1261
+ monitor_gym: bool | None = None,
1262
+ settings: Settings | dict[str, Any] | None = None,
1263
+ ) -> Run:
1264
+ r"""Start a new run to track and log to W&B.
1265
+
1266
+ In an ML training pipeline, you could add `wandb.init()` to the beginning of
1267
+ your training script as well as your evaluation script, and each piece would
1268
+ be tracked as a run in W&B.
1269
+
1270
+ `wandb.init()` spawns a new background process to log data to a run, and it
1271
+ also syncs data to https://wandb.ai by default, so you can see your results
1272
+ in real-time. When you're done logging data, call `wandb.Run.finish()` to end the run.
1273
+ If you don't call `run.finish()`, the run will end when your script exits.
1274
+
1275
+ Run IDs must not contain any of the following special characters `/ \ # ? % :`
1276
+
1277
+ Args:
1278
+ entity: The username or team name the runs are logged to.
1279
+ The entity must already exist, so ensure you create your account
1280
+ or team in the UI before starting to log runs. If not specified, the
1281
+ run will default your default entity. To change the default entity,
1282
+ go to your settings and update the
1283
+ "Default location to create new projects" under "Default team".
1284
+ project: The name of the project under which this run will be logged.
1285
+ If not specified, we use a heuristic to infer the project name based
1286
+ on the system, such as checking the git root or the current program
1287
+ file. If we can't infer the project name, the project will default to
1288
+ `"uncategorized"`.
1289
+ dir: The absolute path to the directory where experiment logs and
1290
+ metadata files are stored. If not specified, this defaults
1291
+ to the `./wandb` directory. Note that this does not affect the
1292
+ location where artifacts are stored when calling `download()`.
1293
+ id: A unique identifier for this run, used for resuming. It must be unique
1294
+ within the project and cannot be reused once a run is deleted. For
1295
+ a short descriptive name, use the `name` field,
1296
+ or for saving hyperparameters to compare across runs, use `config`.
1297
+ name: A short display name for this run, which appears in the UI to help
1298
+ you identify it. By default, we generate a random two-word name
1299
+ allowing easy cross-reference runs from table to charts. Keeping these
1300
+ run names brief enhances readability in chart legends and tables. For
1301
+ saving hyperparameters, we recommend using the `config` field.
1302
+ notes: A detailed description of the run, similar to a commit message in
1303
+ Git. Use this argument to capture any context or details that may
1304
+ help you recall the purpose or setup of this run in the future.
1305
+ tags: A list of tags to label this run in the UI. Tags are helpful for
1306
+ organizing runs or adding temporary identifiers like "baseline" or
1307
+ "production." You can easily add, remove tags, or filter by tags in
1308
+ the UI.
1309
+ If resuming a run, the tags provided here will replace any existing
1310
+ tags. To add tags to a resumed run without overwriting the current
1311
+ tags, use `run.tags += ("new_tag",)` after calling `run = wandb.init()`.
1312
+ config: Sets `wandb.config`, a dictionary-like object for storing input
1313
+ parameters to your run, such as model hyperparameters or data
1314
+ preprocessing settings.
1315
+ The config appears in the UI in an overview page, allowing you to
1316
+ group, filter, and sort runs based on these parameters.
1317
+ Keys should not contain periods (`.`), and values should be
1318
+ smaller than 10 MB.
1319
+ If a dictionary, `argparse.Namespace`, or `absl.flags.FLAGS` is
1320
+ provided, the key-value pairs will be loaded directly into
1321
+ `wandb.config`.
1322
+ If a string is provided, it is interpreted as a path to a YAML file,
1323
+ from which configuration values will be loaded into `wandb.config`.
1324
+ config_exclude_keys: A list of specific keys to exclude from `wandb.config`.
1325
+ config_include_keys: A list of specific keys to include in `wandb.config`.
1326
+ allow_val_change: Controls whether config values can be modified after their
1327
+ initial set. By default, an exception is raised if a config value is
1328
+ overwritten. For tracking variables that change during training, such as
1329
+ a learning rate, consider using `wandb.log()` instead. By default, this
1330
+ is `False` in scripts and `True` in Notebook environments.
1331
+ group: Specify a group name to organize individual runs as part of a larger
1332
+ experiment. This is useful for cases like cross-validation or running
1333
+ multiple jobs that train and evaluate a model on different test sets.
1334
+ Grouping allows you to manage related runs collectively in the UI,
1335
+ making it easy to toggle and review results as a unified experiment.
1336
+ job_type: Specify the type of run, especially helpful when organizing runs
1337
+ within a group as part of a larger experiment. For example, in a group,
1338
+ you might label runs with job types such as "train" and "eval".
1339
+ Defining job types enables you to easily filter and group similar runs
1340
+ in the UI, facilitating direct comparisons.
1341
+ mode: Specifies how run data is managed, with the following options:
1342
+ - `"online"` (default): Enables live syncing with W&B when a network
1343
+ connection is available, with real-time updates to visualizations.
1344
+ - `"offline"`: Suitable for air-gapped or offline environments; data
1345
+ is saved locally and can be synced later. Ensure the run folder
1346
+ is preserved to enable future syncing.
1347
+ - `"disabled"`: Disables all W&B functionality, making the run’s methods
1348
+ no-ops. Typically used in testing to bypass W&B operations.
1349
+ - `"shared"`: (This is an experimental feature). Allows multiple processes,
1350
+ possibly on different machines, to simultaneously log to the same run.
1351
+ In this approach you use a primary node and one or more worker nodes
1352
+ to log data to the same run. Within the primary node you
1353
+ initialize a run. For each worker node, initialize a run
1354
+ using the run ID used by the primary node.
1355
+ force: Determines if a W&B login is required to run the script. If `True`,
1356
+ the user must be logged in to W&B; otherwise, the script will not
1357
+ proceed. If `False` (default), the script can proceed without a login,
1358
+ switching to offline mode if the user is not logged in.
1359
+ anonymous: Specifies the level of control over anonymous data logging.
1360
+ Available options are:
1361
+ - `"never"` (default): Requires you to link your W&B account before
1362
+ tracking the run. This prevents unintentional creation of anonymous
1363
+ runs by ensuring each run is associated with an account.
1364
+ - `"allow"`: Enables a logged-in user to track runs with their account,
1365
+ but also allows someone running the script without a W&B account
1366
+ to view the charts and data in the UI.
1367
+ - `"must"`: Forces the run to be logged to an anonymous account, even
1368
+ if the user is logged in.
1369
+ reinit: Shorthand for the "reinit" setting. Determines the behavior of
1370
+ `wandb.init()` when a run is active.
1371
+ resume: Controls the behavior when resuming a run with the specified `id`.
1372
+ Available options are:
1373
+ - `"allow"`: If a run with the specified `id` exists, it will resume
1374
+ from the last step; otherwise, a new run will be created.
1375
+ - `"never"`: If a run with the specified `id` exists, an error will
1376
+ be raised. If no such run is found, a new run will be created.
1377
+ - `"must"`: If a run with the specified `id` exists, it will resume
1378
+ from the last step. If no run is found, an error will be raised.
1379
+ - `"auto"`: Automatically resumes the previous run if it crashed on
1380
+ this machine; otherwise, starts a new run.
1381
+ - `True`: Deprecated. Use `"auto"` instead.
1382
+ - `False`: Deprecated. Use the default behavior (leaving `resume`
1383
+ unset) to always start a new run.
1384
+ If `resume` is set, `fork_from` and `resume_from` cannot be
1385
+ used. When `resume` is unset, the system will always start a new run.
1386
+ resume_from: Specifies a moment in a previous run to resume a run from,
1387
+ using the format `{run_id}?_step={step}`. This allows users to truncate
1388
+ the history logged to a run at an intermediate step and resume logging
1389
+ from that step. The target run must be in the same project.
1390
+ If an `id` argument is also provided, the `resume_from` argument will
1391
+ take precedence.
1392
+ `resume`, `resume_from` and `fork_from` cannot be used together, only
1393
+ one of them can be used at a time.
1394
+ Note that this feature is in beta and may change in the future.
1395
+ fork_from: Specifies a point in a previous run from which to fork a new
1396
+ run, using the format `{id}?_step={step}`. This creates a new run that
1397
+ resumes logging from the specified step in the target run’s history.
1398
+ The target run must be part of the current project.
1399
+ If an `id` argument is also provided, it must be different from the
1400
+ `fork_from` argument, an error will be raised if they are the same.
1401
+ `resume`, `resume_from` and `fork_from` cannot be used together, only
1402
+ one of them can be used at a time.
1403
+ Note that this feature is in beta and may change in the future.
1404
+ save_code: Enables saving the main script or notebook to W&B, aiding in
1405
+ experiment reproducibility and allowing code comparisons across runs in
1406
+ the UI. By default, this is disabled, but you can change the default to
1407
+ enable on your settings page.
1408
+ tensorboard: Deprecated. Use `sync_tensorboard` instead.
1409
+ sync_tensorboard: Enables automatic syncing of W&B logs from TensorBoard
1410
+ or TensorBoardX, saving relevant event files for viewing in the W&B UI.
1411
+ saving relevant event files for viewing in the W&B UI. (Default: `False`)
1412
+ monitor_gym: Enables automatic logging of videos of the environment when
1413
+ using OpenAI Gym.
1414
+ settings: Specifies a dictionary or `wandb.Settings` object with advanced
1415
+ settings for the run.
1416
+
1417
+ Returns:
1418
+ A `Run` object.
1419
+
1420
+ Raises:
1421
+ Error: If some unknown or internal error happened during the run
1422
+ initialization.
1423
+ AuthenticationError: If the user failed to provide valid credentials.
1424
+ CommError: If there was a problem communicating with the WandB server.
1425
+ UsageError: If the user provided invalid arguments.
1426
+ KeyboardInterrupt: If user interrupts the run.
1427
+
1428
+ Examples:
1429
+ `wandb.init()` returns a `Run` object. Use the run object to log data,
1430
+ save artifacts, and manage the run lifecycle.
1431
+
1432
+ ```python
1433
+ import wandb
1434
+
1435
+ config = {"lr": 0.01, "batch_size": 32}
1436
+ with wandb.init(config=config) as run:
1437
+ # Log accuracy and loss to the run
1438
+ acc = 0.95 # Example accuracy
1439
+ loss = 0.05 # Example loss
1440
+ run.log({"accuracy": acc, "loss": loss})
1441
+ ```
1442
+ """
1443
+ wandb._assert_is_user_process() # type: ignore
1444
+
1445
+ init_telemetry = telemetry.TelemetryRecord()
1446
+
1447
+ init_settings = Settings()
1448
+ if isinstance(settings, dict):
1449
+ init_settings = Settings(**settings)
1450
+ elif isinstance(settings, Settings):
1451
+ init_settings = settings
1452
+
1453
+ # Explicit function arguments take precedence over settings
1454
+ if job_type is not None:
1455
+ init_settings.run_job_type = job_type
1456
+ if dir is not None:
1457
+ init_settings.root_dir = dir # type: ignore
1458
+ if project is not None:
1459
+ init_settings.project = project
1460
+ if entity is not None:
1461
+ init_settings.entity = entity
1462
+ if reinit is not None:
1463
+ init_settings.reinit = reinit
1464
+ if tags is not None:
1465
+ init_settings.run_tags = tuple(tags)
1466
+ if group is not None:
1467
+ init_settings.run_group = group
1468
+ if name is not None:
1469
+ init_settings.run_name = name
1470
+ if notes is not None:
1471
+ init_settings.run_notes = notes
1472
+ if anonymous is not None:
1473
+ init_settings.anonymous = anonymous # type: ignore
1474
+ if mode is not None:
1475
+ init_settings.mode = mode # type: ignore
1476
+ if resume is not None:
1477
+ init_settings.resume = resume # type: ignore
1478
+ if force is not None:
1479
+ init_settings.force = force
1480
+ # TODO: deprecate "tensorboard" in favor of "sync_tensorboard"
1481
+ if tensorboard is not None:
1482
+ init_settings.sync_tensorboard = tensorboard
1483
+ if sync_tensorboard is not None:
1484
+ init_settings.sync_tensorboard = sync_tensorboard
1485
+ if save_code is not None:
1486
+ init_settings.save_code = save_code
1487
+ if id is not None:
1488
+ init_settings.run_id = id
1489
+ if fork_from is not None:
1490
+ init_settings.fork_from = fork_from # type: ignore
1491
+ if resume_from is not None:
1492
+ init_settings.resume_from = resume_from # type: ignore
1493
+
1494
+ if config is not None:
1495
+ init_telemetry.feature.set_init_config = True
1496
+
1497
+ wl: wandb_setup._WandbSetup | None = None
1498
+
1499
+ try:
1500
+ wl = wandb_setup.singleton()
1501
+
1502
+ wi = _WandbInit(wl, init_telemetry)
1503
+
1504
+ wi.maybe_login(init_settings)
1505
+ run_settings, show_warnings = wi.make_run_settings(init_settings)
1506
+
1507
+ if isinstance(run_settings.reinit, bool):
1508
+ wi.deprecated_features_used["run__reinit_bool"] = (
1509
+ "Using a boolean value for 'reinit' is deprecated."
1510
+ " Use 'return_previous' or 'finish_previous' instead."
1511
+ )
1512
+
1513
+ if run_settings.run_id is not None:
1514
+ init_telemetry.feature.set_init_id = True
1515
+ if run_settings.run_name is not None:
1516
+ init_telemetry.feature.set_init_name = True
1517
+ if run_settings.run_tags is not None:
1518
+ init_telemetry.feature.set_init_tags = True
1519
+ if run_settings._offline:
1520
+ init_telemetry.feature.offline = True
1521
+ if run_settings.fork_from is not None:
1522
+ init_telemetry.feature.fork_mode = True
1523
+ if run_settings.resume_from is not None:
1524
+ init_telemetry.feature.rewind_mode = True
1525
+
1526
+ wi.set_run_id(run_settings)
1527
+ run_printer = printer.new_printer(run_settings)
1528
+ show_warnings(run_printer)
1529
+
1530
+ with contextlib.ExitStack() as exit_stack:
1531
+ exit_stack.enter_context(wb_logging.log_to_run(run_settings.run_id))
1532
+
1533
+ run_config = wi.make_run_config(
1534
+ settings=run_settings,
1535
+ config=config,
1536
+ config_exclude_keys=config_exclude_keys,
1537
+ config_include_keys=config_include_keys,
1538
+ )
1539
+
1540
+ if run_settings._noop:
1541
+ return wi.make_disabled_run(run_config)
1542
+
1543
+ try_create_root_dir(run_settings)
1544
+ exit_stack.enter_context(wi.setup_run_log_directory(run_settings))
1545
+
1546
+ if run_settings._jupyter:
1547
+ wi.monkeypatch_ipython(run_settings)
1548
+
1549
+ if monitor_gym:
1550
+ _monkeypatch_openai_gym()
1551
+
1552
+ if wandb.patched["tensorboard"]:
1553
+ # NOTE: The user may have called the patch function directly.
1554
+ init_telemetry.feature.tensorboard_patch = True
1555
+ if run_settings.sync_tensorboard:
1556
+ _monkeypatch_tensorboard()
1557
+ init_telemetry.feature.tensorboard_sync = True
1558
+
1559
+ if run_settings.x_server_side_derived_summary:
1560
+ init_telemetry.feature.server_side_derived_summary = True
1561
+
1562
+ run = wi.init(run_settings, run_config, run_printer)
1563
+
1564
+ # Set up automatic Weave integration if Weave is installed
1565
+ weave.setup(run_settings.entity, run_settings.project)
1566
+
1567
+ return run
1568
+
1569
+ except KeyboardInterrupt as e:
1570
+ if wl:
1571
+ wl._get_logger().warning("interrupted", exc_info=e)
1572
+
1573
+ raise
1574
+
1575
+ except Exception as e:
1576
+ if wl:
1577
+ wl._get_logger().exception("error in wandb.init()", exc_info=e)
1578
+
1579
+ # Need to build delay into this sentry capture because our exit hooks
1580
+ # mess with sentry's ability to send out errors before the program ends.
1581
+ wandb._sentry.reraise(e)