wandb 0.18.1__py3-none-macosx_11_0_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (826) hide show
  1. package_readme.md +89 -0
  2. wandb/__init__.py +245 -0
  3. wandb/__init__.pyi +1084 -0
  4. wandb/__main__.py +3 -0
  5. wandb/_globals.py +19 -0
  6. wandb/agents/__init__.py +0 -0
  7. wandb/agents/pyagent.py +363 -0
  8. wandb/analytics/__init__.py +3 -0
  9. wandb/analytics/sentry.py +266 -0
  10. wandb/apis/__init__.py +48 -0
  11. wandb/apis/attrs.py +40 -0
  12. wandb/apis/importers/__init__.py +1 -0
  13. wandb/apis/importers/internals/internal.py +385 -0
  14. wandb/apis/importers/internals/protocols.py +99 -0
  15. wandb/apis/importers/internals/util.py +78 -0
  16. wandb/apis/importers/mlflow.py +254 -0
  17. wandb/apis/importers/validation.py +108 -0
  18. wandb/apis/importers/wandb.py +1603 -0
  19. wandb/apis/internal.py +229 -0
  20. wandb/apis/normalize.py +89 -0
  21. wandb/apis/paginator.py +81 -0
  22. wandb/apis/public/__init__.py +34 -0
  23. wandb/apis/public/api.py +1179 -0
  24. wandb/apis/public/artifacts.py +1086 -0
  25. wandb/apis/public/const.py +4 -0
  26. wandb/apis/public/files.py +195 -0
  27. wandb/apis/public/history.py +149 -0
  28. wandb/apis/public/jobs.py +651 -0
  29. wandb/apis/public/projects.py +154 -0
  30. wandb/apis/public/query_generator.py +166 -0
  31. wandb/apis/public/reports.py +469 -0
  32. wandb/apis/public/runs.py +903 -0
  33. wandb/apis/public/sweeps.py +240 -0
  34. wandb/apis/public/teams.py +198 -0
  35. wandb/apis/public/users.py +136 -0
  36. wandb/apis/reports/__init__.py +1 -0
  37. wandb/apis/reports/v1/__init__.py +8 -0
  38. wandb/apis/reports/v2/__init__.py +8 -0
  39. wandb/apis/workspaces/__init__.py +8 -0
  40. wandb/beta/workflows.py +288 -0
  41. wandb/bin/wandb-core +0 -0
  42. wandb/cli/__init__.py +0 -0
  43. wandb/cli/cli.py +3007 -0
  44. wandb/data_types.py +63 -0
  45. wandb/docker/__init__.py +342 -0
  46. wandb/docker/auth.py +436 -0
  47. wandb/docker/wandb-entrypoint.sh +33 -0
  48. wandb/docker/www_authenticate.py +94 -0
  49. wandb/env.py +514 -0
  50. wandb/errors/__init__.py +46 -0
  51. wandb/errors/term.py +103 -0
  52. wandb/errors/util.py +57 -0
  53. wandb/filesync/__init__.py +0 -0
  54. wandb/filesync/dir_watcher.py +403 -0
  55. wandb/filesync/stats.py +100 -0
  56. wandb/filesync/step_checksum.py +142 -0
  57. wandb/filesync/step_prepare.py +179 -0
  58. wandb/filesync/step_upload.py +290 -0
  59. wandb/filesync/upload_job.py +142 -0
  60. wandb/integration/__init__.py +0 -0
  61. wandb/integration/catboost/__init__.py +5 -0
  62. wandb/integration/catboost/catboost.py +178 -0
  63. wandb/integration/cohere/__init__.py +3 -0
  64. wandb/integration/cohere/cohere.py +21 -0
  65. wandb/integration/cohere/resolver.py +347 -0
  66. wandb/integration/diffusers/__init__.py +3 -0
  67. wandb/integration/diffusers/autologger.py +76 -0
  68. wandb/integration/diffusers/pipeline_resolver.py +50 -0
  69. wandb/integration/diffusers/resolvers/__init__.py +9 -0
  70. wandb/integration/diffusers/resolvers/multimodal.py +882 -0
  71. wandb/integration/diffusers/resolvers/utils.py +102 -0
  72. wandb/integration/fastai/__init__.py +249 -0
  73. wandb/integration/gym/__init__.py +105 -0
  74. wandb/integration/huggingface/__init__.py +3 -0
  75. wandb/integration/huggingface/huggingface.py +18 -0
  76. wandb/integration/huggingface/resolver.py +213 -0
  77. wandb/integration/keras/__init__.py +11 -0
  78. wandb/integration/keras/callbacks/__init__.py +5 -0
  79. wandb/integration/keras/callbacks/metrics_logger.py +136 -0
  80. wandb/integration/keras/callbacks/model_checkpoint.py +195 -0
  81. wandb/integration/keras/callbacks/tables_builder.py +226 -0
  82. wandb/integration/keras/keras.py +1091 -0
  83. wandb/integration/kfp/__init__.py +6 -0
  84. wandb/integration/kfp/helpers.py +28 -0
  85. wandb/integration/kfp/kfp_patch.py +324 -0
  86. wandb/integration/kfp/wandb_logging.py +182 -0
  87. wandb/integration/langchain/__init__.py +3 -0
  88. wandb/integration/langchain/wandb_tracer.py +48 -0
  89. wandb/integration/lightgbm/__init__.py +239 -0
  90. wandb/integration/lightning/__init__.py +0 -0
  91. wandb/integration/lightning/fabric/__init__.py +3 -0
  92. wandb/integration/lightning/fabric/logger.py +762 -0
  93. wandb/integration/magic.py +556 -0
  94. wandb/integration/metaflow/__init__.py +3 -0
  95. wandb/integration/metaflow/metaflow.py +383 -0
  96. wandb/integration/openai/__init__.py +3 -0
  97. wandb/integration/openai/fine_tuning.py +480 -0
  98. wandb/integration/openai/openai.py +22 -0
  99. wandb/integration/openai/resolver.py +240 -0
  100. wandb/integration/prodigy/__init__.py +3 -0
  101. wandb/integration/prodigy/prodigy.py +299 -0
  102. wandb/integration/sacred/__init__.py +117 -0
  103. wandb/integration/sagemaker/__init__.py +12 -0
  104. wandb/integration/sagemaker/auth.py +28 -0
  105. wandb/integration/sagemaker/config.py +49 -0
  106. wandb/integration/sagemaker/files.py +3 -0
  107. wandb/integration/sagemaker/resources.py +34 -0
  108. wandb/integration/sb3/__init__.py +3 -0
  109. wandb/integration/sb3/sb3.py +153 -0
  110. wandb/integration/sklearn/__init__.py +37 -0
  111. wandb/integration/sklearn/calculate/__init__.py +32 -0
  112. wandb/integration/sklearn/calculate/calibration_curves.py +125 -0
  113. wandb/integration/sklearn/calculate/class_proportions.py +68 -0
  114. wandb/integration/sklearn/calculate/confusion_matrix.py +93 -0
  115. wandb/integration/sklearn/calculate/decision_boundaries.py +40 -0
  116. wandb/integration/sklearn/calculate/elbow_curve.py +55 -0
  117. wandb/integration/sklearn/calculate/feature_importances.py +67 -0
  118. wandb/integration/sklearn/calculate/learning_curve.py +64 -0
  119. wandb/integration/sklearn/calculate/outlier_candidates.py +69 -0
  120. wandb/integration/sklearn/calculate/residuals.py +86 -0
  121. wandb/integration/sklearn/calculate/silhouette.py +118 -0
  122. wandb/integration/sklearn/calculate/summary_metrics.py +62 -0
  123. wandb/integration/sklearn/plot/__init__.py +35 -0
  124. wandb/integration/sklearn/plot/classifier.py +329 -0
  125. wandb/integration/sklearn/plot/clusterer.py +146 -0
  126. wandb/integration/sklearn/plot/regressor.py +121 -0
  127. wandb/integration/sklearn/plot/shared.py +91 -0
  128. wandb/integration/sklearn/utils.py +183 -0
  129. wandb/integration/tensorboard/__init__.py +10 -0
  130. wandb/integration/tensorboard/log.py +355 -0
  131. wandb/integration/tensorboard/monkeypatch.py +185 -0
  132. wandb/integration/tensorflow/__init__.py +5 -0
  133. wandb/integration/tensorflow/estimator_hook.py +54 -0
  134. wandb/integration/torch/__init__.py +0 -0
  135. wandb/integration/torch/wandb_torch.py +554 -0
  136. wandb/integration/ultralytics/__init__.py +11 -0
  137. wandb/integration/ultralytics/bbox_utils.py +208 -0
  138. wandb/integration/ultralytics/callback.py +524 -0
  139. wandb/integration/ultralytics/classification_utils.py +83 -0
  140. wandb/integration/ultralytics/mask_utils.py +202 -0
  141. wandb/integration/ultralytics/pose_utils.py +103 -0
  142. wandb/integration/xgboost/__init__.py +11 -0
  143. wandb/integration/xgboost/xgboost.py +189 -0
  144. wandb/integration/yolov8/__init__.py +0 -0
  145. wandb/integration/yolov8/yolov8.py +284 -0
  146. wandb/jupyter.py +515 -0
  147. wandb/magic.py +3 -0
  148. wandb/mpmain/__init__.py +0 -0
  149. wandb/mpmain/__main__.py +1 -0
  150. wandb/old/__init__.py +0 -0
  151. wandb/old/core.py +131 -0
  152. wandb/old/settings.py +173 -0
  153. wandb/old/summary.py +440 -0
  154. wandb/plot/__init__.py +19 -0
  155. wandb/plot/bar.py +42 -0
  156. wandb/plot/confusion_matrix.py +99 -0
  157. wandb/plot/histogram.py +36 -0
  158. wandb/plot/line.py +40 -0
  159. wandb/plot/line_series.py +88 -0
  160. wandb/plot/pr_curve.py +136 -0
  161. wandb/plot/roc_curve.py +118 -0
  162. wandb/plot/scatter.py +32 -0
  163. wandb/plot/utils.py +183 -0
  164. wandb/proto/__init__.py +0 -0
  165. wandb/proto/v3/__init__.py +0 -0
  166. wandb/proto/v3/wandb_base_pb2.py +55 -0
  167. wandb/proto/v3/wandb_internal_pb2.py +1608 -0
  168. wandb/proto/v3/wandb_server_pb2.py +208 -0
  169. wandb/proto/v3/wandb_settings_pb2.py +112 -0
  170. wandb/proto/v3/wandb_telemetry_pb2.py +106 -0
  171. wandb/proto/v4/__init__.py +0 -0
  172. wandb/proto/v4/wandb_base_pb2.py +30 -0
  173. wandb/proto/v4/wandb_internal_pb2.py +360 -0
  174. wandb/proto/v4/wandb_server_pb2.py +63 -0
  175. wandb/proto/v4/wandb_settings_pb2.py +45 -0
  176. wandb/proto/v4/wandb_telemetry_pb2.py +41 -0
  177. wandb/proto/v5/wandb_base_pb2.py +31 -0
  178. wandb/proto/v5/wandb_internal_pb2.py +361 -0
  179. wandb/proto/v5/wandb_server_pb2.py +64 -0
  180. wandb/proto/v5/wandb_settings_pb2.py +46 -0
  181. wandb/proto/v5/wandb_telemetry_pb2.py +42 -0
  182. wandb/proto/wandb_base_pb2.py +10 -0
  183. wandb/proto/wandb_deprecated.py +53 -0
  184. wandb/proto/wandb_generate_deprecated.py +34 -0
  185. wandb/proto/wandb_generate_proto.py +49 -0
  186. wandb/proto/wandb_internal_pb2.py +16 -0
  187. wandb/proto/wandb_server_pb2.py +10 -0
  188. wandb/proto/wandb_settings_pb2.py +10 -0
  189. wandb/proto/wandb_telemetry_pb2.py +10 -0
  190. wandb/py.typed +0 -0
  191. wandb/sdk/__init__.py +37 -0
  192. wandb/sdk/artifacts/__init__.py +0 -0
  193. wandb/sdk/artifacts/_validators.py +45 -0
  194. wandb/sdk/artifacts/artifact.py +2415 -0
  195. wandb/sdk/artifacts/artifact_download_logger.py +43 -0
  196. wandb/sdk/artifacts/artifact_file_cache.py +251 -0
  197. wandb/sdk/artifacts/artifact_instance_cache.py +15 -0
  198. wandb/sdk/artifacts/artifact_manifest.py +72 -0
  199. wandb/sdk/artifacts/artifact_manifest_entry.py +247 -0
  200. wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
  201. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +90 -0
  202. wandb/sdk/artifacts/artifact_saver.py +267 -0
  203. wandb/sdk/artifacts/artifact_state.py +11 -0
  204. wandb/sdk/artifacts/artifact_ttl.py +7 -0
  205. wandb/sdk/artifacts/exceptions.py +56 -0
  206. wandb/sdk/artifacts/staging.py +25 -0
  207. wandb/sdk/artifacts/storage_handler.py +60 -0
  208. wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
  209. wandb/sdk/artifacts/storage_handlers/azure_handler.py +206 -0
  210. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +226 -0
  211. wandb/sdk/artifacts/storage_handlers/http_handler.py +113 -0
  212. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +139 -0
  213. wandb/sdk/artifacts/storage_handlers/multi_handler.py +54 -0
  214. wandb/sdk/artifacts/storage_handlers/s3_handler.py +300 -0
  215. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +70 -0
  216. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +133 -0
  217. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +72 -0
  218. wandb/sdk/artifacts/storage_layout.py +6 -0
  219. wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
  220. wandb/sdk/artifacts/storage_policies/register.py +1 -0
  221. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +376 -0
  222. wandb/sdk/artifacts/storage_policy.py +72 -0
  223. wandb/sdk/backend/__init__.py +0 -0
  224. wandb/sdk/backend/backend.py +240 -0
  225. wandb/sdk/data_types/__init__.py +0 -0
  226. wandb/sdk/data_types/_dtypes.py +914 -0
  227. wandb/sdk/data_types/_private.py +10 -0
  228. wandb/sdk/data_types/audio.py +165 -0
  229. wandb/sdk/data_types/base_types/__init__.py +0 -0
  230. wandb/sdk/data_types/base_types/json_metadata.py +55 -0
  231. wandb/sdk/data_types/base_types/media.py +315 -0
  232. wandb/sdk/data_types/base_types/wb_value.py +274 -0
  233. wandb/sdk/data_types/bokeh.py +70 -0
  234. wandb/sdk/data_types/graph.py +405 -0
  235. wandb/sdk/data_types/helper_types/__init__.py +0 -0
  236. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +295 -0
  237. wandb/sdk/data_types/helper_types/classes.py +159 -0
  238. wandb/sdk/data_types/helper_types/image_mask.py +235 -0
  239. wandb/sdk/data_types/histogram.py +96 -0
  240. wandb/sdk/data_types/html.py +115 -0
  241. wandb/sdk/data_types/image.py +845 -0
  242. wandb/sdk/data_types/molecule.py +241 -0
  243. wandb/sdk/data_types/object_3d.py +474 -0
  244. wandb/sdk/data_types/plotly.py +82 -0
  245. wandb/sdk/data_types/saved_model.py +446 -0
  246. wandb/sdk/data_types/table.py +1204 -0
  247. wandb/sdk/data_types/trace_tree.py +438 -0
  248. wandb/sdk/data_types/utils.py +229 -0
  249. wandb/sdk/data_types/video.py +247 -0
  250. wandb/sdk/integration_utils/__init__.py +0 -0
  251. wandb/sdk/integration_utils/auto_logging.py +239 -0
  252. wandb/sdk/integration_utils/data_logging.py +475 -0
  253. wandb/sdk/interface/__init__.py +0 -0
  254. wandb/sdk/interface/constants.py +4 -0
  255. wandb/sdk/interface/interface.py +996 -0
  256. wandb/sdk/interface/interface_queue.py +59 -0
  257. wandb/sdk/interface/interface_relay.py +53 -0
  258. wandb/sdk/interface/interface_shared.py +549 -0
  259. wandb/sdk/interface/interface_sock.py +61 -0
  260. wandb/sdk/interface/message_future.py +27 -0
  261. wandb/sdk/interface/message_future_poll.py +50 -0
  262. wandb/sdk/interface/router.py +118 -0
  263. wandb/sdk/interface/router_queue.py +44 -0
  264. wandb/sdk/interface/router_relay.py +39 -0
  265. wandb/sdk/interface/router_sock.py +36 -0
  266. wandb/sdk/interface/summary_record.py +67 -0
  267. wandb/sdk/internal/__init__.py +0 -0
  268. wandb/sdk/internal/context.py +89 -0
  269. wandb/sdk/internal/datastore.py +297 -0
  270. wandb/sdk/internal/file_pusher.py +181 -0
  271. wandb/sdk/internal/file_stream.py +695 -0
  272. wandb/sdk/internal/flow_control.py +263 -0
  273. wandb/sdk/internal/handler.py +911 -0
  274. wandb/sdk/internal/internal.py +417 -0
  275. wandb/sdk/internal/internal_api.py +4287 -0
  276. wandb/sdk/internal/internal_util.py +100 -0
  277. wandb/sdk/internal/job_builder.py +629 -0
  278. wandb/sdk/internal/profiler.py +78 -0
  279. wandb/sdk/internal/progress.py +83 -0
  280. wandb/sdk/internal/run.py +25 -0
  281. wandb/sdk/internal/sample.py +70 -0
  282. wandb/sdk/internal/sender.py +1729 -0
  283. wandb/sdk/internal/sender_config.py +197 -0
  284. wandb/sdk/internal/settings_static.py +90 -0
  285. wandb/sdk/internal/system/__init__.py +0 -0
  286. wandb/sdk/internal/system/assets/__init__.py +27 -0
  287. wandb/sdk/internal/system/assets/aggregators.py +37 -0
  288. wandb/sdk/internal/system/assets/asset_registry.py +20 -0
  289. wandb/sdk/internal/system/assets/cpu.py +163 -0
  290. wandb/sdk/internal/system/assets/disk.py +210 -0
  291. wandb/sdk/internal/system/assets/gpu.py +416 -0
  292. wandb/sdk/internal/system/assets/gpu_amd.py +239 -0
  293. wandb/sdk/internal/system/assets/gpu_apple.py +177 -0
  294. wandb/sdk/internal/system/assets/interfaces.py +207 -0
  295. wandb/sdk/internal/system/assets/ipu.py +177 -0
  296. wandb/sdk/internal/system/assets/memory.py +166 -0
  297. wandb/sdk/internal/system/assets/network.py +125 -0
  298. wandb/sdk/internal/system/assets/open_metrics.py +299 -0
  299. wandb/sdk/internal/system/assets/tpu.py +154 -0
  300. wandb/sdk/internal/system/assets/trainium.py +399 -0
  301. wandb/sdk/internal/system/env_probe_helpers.py +13 -0
  302. wandb/sdk/internal/system/system_info.py +249 -0
  303. wandb/sdk/internal/system/system_monitor.py +229 -0
  304. wandb/sdk/internal/tb_watcher.py +518 -0
  305. wandb/sdk/internal/thread_local_settings.py +18 -0
  306. wandb/sdk/internal/update.py +113 -0
  307. wandb/sdk/internal/writer.py +206 -0
  308. wandb/sdk/launch/__init__.py +14 -0
  309. wandb/sdk/launch/_launch.py +330 -0
  310. wandb/sdk/launch/_launch_add.py +255 -0
  311. wandb/sdk/launch/_project_spec.py +566 -0
  312. wandb/sdk/launch/agent/__init__.py +5 -0
  313. wandb/sdk/launch/agent/agent.py +924 -0
  314. wandb/sdk/launch/agent/config.py +296 -0
  315. wandb/sdk/launch/agent/job_status_tracker.py +53 -0
  316. wandb/sdk/launch/agent/run_queue_item_file_saver.py +45 -0
  317. wandb/sdk/launch/builder/__init__.py +0 -0
  318. wandb/sdk/launch/builder/abstract.py +156 -0
  319. wandb/sdk/launch/builder/build.py +297 -0
  320. wandb/sdk/launch/builder/context_manager.py +235 -0
  321. wandb/sdk/launch/builder/docker_builder.py +177 -0
  322. wandb/sdk/launch/builder/kaniko_builder.py +595 -0
  323. wandb/sdk/launch/builder/noop.py +58 -0
  324. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +188 -0
  325. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  326. wandb/sdk/launch/create_job.py +528 -0
  327. wandb/sdk/launch/environment/abstract.py +29 -0
  328. wandb/sdk/launch/environment/aws_environment.py +322 -0
  329. wandb/sdk/launch/environment/azure_environment.py +105 -0
  330. wandb/sdk/launch/environment/gcp_environment.py +335 -0
  331. wandb/sdk/launch/environment/local_environment.py +66 -0
  332. wandb/sdk/launch/errors.py +19 -0
  333. wandb/sdk/launch/git_reference.py +109 -0
  334. wandb/sdk/launch/inputs/files.py +148 -0
  335. wandb/sdk/launch/inputs/internal.py +315 -0
  336. wandb/sdk/launch/inputs/manage.py +113 -0
  337. wandb/sdk/launch/inputs/schema.py +39 -0
  338. wandb/sdk/launch/loader.py +249 -0
  339. wandb/sdk/launch/registry/abstract.py +48 -0
  340. wandb/sdk/launch/registry/anon.py +29 -0
  341. wandb/sdk/launch/registry/azure_container_registry.py +124 -0
  342. wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
  343. wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
  344. wandb/sdk/launch/registry/local_registry.py +67 -0
  345. wandb/sdk/launch/runner/__init__.py +0 -0
  346. wandb/sdk/launch/runner/abstract.py +195 -0
  347. wandb/sdk/launch/runner/kubernetes_monitor.py +474 -0
  348. wandb/sdk/launch/runner/kubernetes_runner.py +963 -0
  349. wandb/sdk/launch/runner/local_container.py +301 -0
  350. wandb/sdk/launch/runner/local_process.py +78 -0
  351. wandb/sdk/launch/runner/sagemaker_runner.py +426 -0
  352. wandb/sdk/launch/runner/vertex_runner.py +230 -0
  353. wandb/sdk/launch/sweeps/__init__.py +39 -0
  354. wandb/sdk/launch/sweeps/scheduler.py +742 -0
  355. wandb/sdk/launch/sweeps/scheduler_sweep.py +91 -0
  356. wandb/sdk/launch/sweeps/utils.py +316 -0
  357. wandb/sdk/launch/utils.py +746 -0
  358. wandb/sdk/launch/wandb_reference.py +138 -0
  359. wandb/sdk/lib/__init__.py +5 -0
  360. wandb/sdk/lib/_settings_toposort_generate.py +159 -0
  361. wandb/sdk/lib/_settings_toposort_generated.py +249 -0
  362. wandb/sdk/lib/_wburls_generate.py +25 -0
  363. wandb/sdk/lib/_wburls_generated.py +22 -0
  364. wandb/sdk/lib/apikey.py +273 -0
  365. wandb/sdk/lib/capped_dict.py +26 -0
  366. wandb/sdk/lib/config_util.py +101 -0
  367. wandb/sdk/lib/credentials.py +141 -0
  368. wandb/sdk/lib/deprecate.py +42 -0
  369. wandb/sdk/lib/disabled.py +29 -0
  370. wandb/sdk/lib/exit_hooks.py +54 -0
  371. wandb/sdk/lib/file_stream_utils.py +118 -0
  372. wandb/sdk/lib/filenames.py +64 -0
  373. wandb/sdk/lib/filesystem.py +372 -0
  374. wandb/sdk/lib/fsm.py +174 -0
  375. wandb/sdk/lib/gitlib.py +239 -0
  376. wandb/sdk/lib/gql_request.py +65 -0
  377. wandb/sdk/lib/handler_util.py +21 -0
  378. wandb/sdk/lib/hashutil.py +62 -0
  379. wandb/sdk/lib/import_hooks.py +275 -0
  380. wandb/sdk/lib/ipython.py +146 -0
  381. wandb/sdk/lib/json_util.py +80 -0
  382. wandb/sdk/lib/lazyloader.py +63 -0
  383. wandb/sdk/lib/mailbox.py +460 -0
  384. wandb/sdk/lib/module.py +69 -0
  385. wandb/sdk/lib/paths.py +106 -0
  386. wandb/sdk/lib/preinit.py +42 -0
  387. wandb/sdk/lib/printer.py +313 -0
  388. wandb/sdk/lib/proto_util.py +90 -0
  389. wandb/sdk/lib/redirect.py +845 -0
  390. wandb/sdk/lib/reporting.py +99 -0
  391. wandb/sdk/lib/retry.py +289 -0
  392. wandb/sdk/lib/run_moment.py +78 -0
  393. wandb/sdk/lib/runid.py +12 -0
  394. wandb/sdk/lib/server.py +52 -0
  395. wandb/sdk/lib/sock_client.py +291 -0
  396. wandb/sdk/lib/sparkline.py +45 -0
  397. wandb/sdk/lib/telemetry.py +100 -0
  398. wandb/sdk/lib/timed_input.py +133 -0
  399. wandb/sdk/lib/timer.py +19 -0
  400. wandb/sdk/lib/tracelog.py +255 -0
  401. wandb/sdk/lib/viz.py +123 -0
  402. wandb/sdk/lib/wburls.py +46 -0
  403. wandb/sdk/service/__init__.py +0 -0
  404. wandb/sdk/service/_startup_debug.py +22 -0
  405. wandb/sdk/service/port_file.py +53 -0
  406. wandb/sdk/service/server.py +119 -0
  407. wandb/sdk/service/server_sock.py +276 -0
  408. wandb/sdk/service/service.py +264 -0
  409. wandb/sdk/service/service_base.py +50 -0
  410. wandb/sdk/service/service_sock.py +70 -0
  411. wandb/sdk/service/streams.py +417 -0
  412. wandb/sdk/verify/__init__.py +0 -0
  413. wandb/sdk/verify/verify.py +501 -0
  414. wandb/sdk/wandb_alerts.py +12 -0
  415. wandb/sdk/wandb_config.py +322 -0
  416. wandb/sdk/wandb_helper.py +54 -0
  417. wandb/sdk/wandb_init.py +1256 -0
  418. wandb/sdk/wandb_login.py +349 -0
  419. wandb/sdk/wandb_manager.py +232 -0
  420. wandb/sdk/wandb_metric.py +110 -0
  421. wandb/sdk/wandb_require.py +97 -0
  422. wandb/sdk/wandb_require_helpers.py +44 -0
  423. wandb/sdk/wandb_run.py +4231 -0
  424. wandb/sdk/wandb_settings.py +1999 -0
  425. wandb/sdk/wandb_setup.py +400 -0
  426. wandb/sdk/wandb_summary.py +150 -0
  427. wandb/sdk/wandb_sweep.py +119 -0
  428. wandb/sdk/wandb_sync.py +75 -0
  429. wandb/sdk/wandb_watch.py +128 -0
  430. wandb/sklearn.py +35 -0
  431. wandb/sync/__init__.py +3 -0
  432. wandb/sync/sync.py +443 -0
  433. wandb/trigger.py +29 -0
  434. wandb/util.py +1949 -0
  435. wandb/vendor/__init__.py +0 -0
  436. wandb/vendor/gql-0.2.0/setup.py +40 -0
  437. wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
  438. wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
  439. wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
  440. wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
  441. wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
  442. wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
  443. wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
  444. wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
  445. wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
  446. wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
  447. wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
  448. wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
  449. wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
  450. wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
  451. wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
  452. wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
  453. wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
  454. wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
  455. wandb/vendor/graphql-core-1.1/setup.py +86 -0
  456. wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
  457. wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
  458. wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
  459. wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
  460. wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
  461. wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
  462. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
  463. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
  464. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
  465. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
  466. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
  467. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
  468. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
  469. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
  470. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
  471. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
  472. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
  473. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
  474. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
  475. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
  476. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
  477. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
  478. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
  479. wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
  480. wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
  481. wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
  482. wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
  483. wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
  484. wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
  485. wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
  486. wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
  487. wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
  488. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
  489. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
  490. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
  491. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
  492. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
  493. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
  494. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
  495. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
  496. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
  497. wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
  498. wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
  499. wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
  500. wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
  501. wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
  502. wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
  503. wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
  504. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
  505. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
  506. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
  507. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
  508. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
  509. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
  510. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
  511. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
  512. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
  513. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
  514. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
  515. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
  516. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
  517. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
  518. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
  519. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
  520. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
  521. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
  522. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
  523. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
  524. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
  525. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
  526. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
  527. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
  528. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
  529. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
  530. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
  531. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
  532. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
  533. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
  534. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
  535. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
  536. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
  537. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
  538. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
  539. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
  540. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
  541. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
  542. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
  543. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
  544. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
  545. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
  546. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
  547. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
  548. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
  549. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
  550. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
  551. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
  552. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
  553. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
  554. wandb/vendor/promise-2.3.0/conftest.py +30 -0
  555. wandb/vendor/promise-2.3.0/setup.py +64 -0
  556. wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
  557. wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
  558. wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
  559. wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
  560. wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
  561. wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
  562. wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
  563. wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
  564. wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
  565. wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
  566. wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
  567. wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
  568. wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
  569. wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
  570. wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
  571. wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
  572. wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
  573. wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
  574. wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
  575. wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
  576. wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
  577. wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
  578. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
  579. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
  580. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
  581. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
  582. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
  583. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
  584. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
  585. wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
  586. wandb/vendor/pygments/__init__.py +90 -0
  587. wandb/vendor/pygments/cmdline.py +568 -0
  588. wandb/vendor/pygments/console.py +74 -0
  589. wandb/vendor/pygments/filter.py +74 -0
  590. wandb/vendor/pygments/filters/__init__.py +350 -0
  591. wandb/vendor/pygments/formatter.py +95 -0
  592. wandb/vendor/pygments/formatters/__init__.py +153 -0
  593. wandb/vendor/pygments/formatters/_mapping.py +85 -0
  594. wandb/vendor/pygments/formatters/bbcode.py +109 -0
  595. wandb/vendor/pygments/formatters/html.py +851 -0
  596. wandb/vendor/pygments/formatters/img.py +600 -0
  597. wandb/vendor/pygments/formatters/irc.py +182 -0
  598. wandb/vendor/pygments/formatters/latex.py +482 -0
  599. wandb/vendor/pygments/formatters/other.py +160 -0
  600. wandb/vendor/pygments/formatters/rtf.py +147 -0
  601. wandb/vendor/pygments/formatters/svg.py +153 -0
  602. wandb/vendor/pygments/formatters/terminal.py +136 -0
  603. wandb/vendor/pygments/formatters/terminal256.py +309 -0
  604. wandb/vendor/pygments/lexer.py +871 -0
  605. wandb/vendor/pygments/lexers/__init__.py +329 -0
  606. wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
  607. wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
  608. wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
  609. wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
  610. wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
  611. wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
  612. wandb/vendor/pygments/lexers/_mapping.py +500 -0
  613. wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
  614. wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
  615. wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
  616. wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
  617. wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
  618. wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
  619. wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
  620. wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
  621. wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
  622. wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
  623. wandb/vendor/pygments/lexers/actionscript.py +240 -0
  624. wandb/vendor/pygments/lexers/agile.py +24 -0
  625. wandb/vendor/pygments/lexers/algebra.py +221 -0
  626. wandb/vendor/pygments/lexers/ambient.py +76 -0
  627. wandb/vendor/pygments/lexers/ampl.py +87 -0
  628. wandb/vendor/pygments/lexers/apl.py +101 -0
  629. wandb/vendor/pygments/lexers/archetype.py +318 -0
  630. wandb/vendor/pygments/lexers/asm.py +641 -0
  631. wandb/vendor/pygments/lexers/automation.py +374 -0
  632. wandb/vendor/pygments/lexers/basic.py +500 -0
  633. wandb/vendor/pygments/lexers/bibtex.py +160 -0
  634. wandb/vendor/pygments/lexers/business.py +612 -0
  635. wandb/vendor/pygments/lexers/c_cpp.py +252 -0
  636. wandb/vendor/pygments/lexers/c_like.py +541 -0
  637. wandb/vendor/pygments/lexers/capnproto.py +78 -0
  638. wandb/vendor/pygments/lexers/chapel.py +102 -0
  639. wandb/vendor/pygments/lexers/clean.py +288 -0
  640. wandb/vendor/pygments/lexers/compiled.py +34 -0
  641. wandb/vendor/pygments/lexers/configs.py +833 -0
  642. wandb/vendor/pygments/lexers/console.py +114 -0
  643. wandb/vendor/pygments/lexers/crystal.py +393 -0
  644. wandb/vendor/pygments/lexers/csound.py +366 -0
  645. wandb/vendor/pygments/lexers/css.py +689 -0
  646. wandb/vendor/pygments/lexers/d.py +251 -0
  647. wandb/vendor/pygments/lexers/dalvik.py +125 -0
  648. wandb/vendor/pygments/lexers/data.py +555 -0
  649. wandb/vendor/pygments/lexers/diff.py +165 -0
  650. wandb/vendor/pygments/lexers/dotnet.py +691 -0
  651. wandb/vendor/pygments/lexers/dsls.py +878 -0
  652. wandb/vendor/pygments/lexers/dylan.py +289 -0
  653. wandb/vendor/pygments/lexers/ecl.py +125 -0
  654. wandb/vendor/pygments/lexers/eiffel.py +65 -0
  655. wandb/vendor/pygments/lexers/elm.py +121 -0
  656. wandb/vendor/pygments/lexers/erlang.py +533 -0
  657. wandb/vendor/pygments/lexers/esoteric.py +277 -0
  658. wandb/vendor/pygments/lexers/ezhil.py +69 -0
  659. wandb/vendor/pygments/lexers/factor.py +344 -0
  660. wandb/vendor/pygments/lexers/fantom.py +250 -0
  661. wandb/vendor/pygments/lexers/felix.py +273 -0
  662. wandb/vendor/pygments/lexers/forth.py +177 -0
  663. wandb/vendor/pygments/lexers/fortran.py +205 -0
  664. wandb/vendor/pygments/lexers/foxpro.py +428 -0
  665. wandb/vendor/pygments/lexers/functional.py +21 -0
  666. wandb/vendor/pygments/lexers/go.py +101 -0
  667. wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
  668. wandb/vendor/pygments/lexers/graph.py +80 -0
  669. wandb/vendor/pygments/lexers/graphics.py +553 -0
  670. wandb/vendor/pygments/lexers/haskell.py +843 -0
  671. wandb/vendor/pygments/lexers/haxe.py +936 -0
  672. wandb/vendor/pygments/lexers/hdl.py +382 -0
  673. wandb/vendor/pygments/lexers/hexdump.py +103 -0
  674. wandb/vendor/pygments/lexers/html.py +602 -0
  675. wandb/vendor/pygments/lexers/idl.py +270 -0
  676. wandb/vendor/pygments/lexers/igor.py +288 -0
  677. wandb/vendor/pygments/lexers/inferno.py +96 -0
  678. wandb/vendor/pygments/lexers/installers.py +322 -0
  679. wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
  680. wandb/vendor/pygments/lexers/iolang.py +63 -0
  681. wandb/vendor/pygments/lexers/j.py +146 -0
  682. wandb/vendor/pygments/lexers/javascript.py +1525 -0
  683. wandb/vendor/pygments/lexers/julia.py +333 -0
  684. wandb/vendor/pygments/lexers/jvm.py +1573 -0
  685. wandb/vendor/pygments/lexers/lisp.py +2621 -0
  686. wandb/vendor/pygments/lexers/make.py +202 -0
  687. wandb/vendor/pygments/lexers/markup.py +595 -0
  688. wandb/vendor/pygments/lexers/math.py +21 -0
  689. wandb/vendor/pygments/lexers/matlab.py +663 -0
  690. wandb/vendor/pygments/lexers/ml.py +769 -0
  691. wandb/vendor/pygments/lexers/modeling.py +358 -0
  692. wandb/vendor/pygments/lexers/modula2.py +1561 -0
  693. wandb/vendor/pygments/lexers/monte.py +204 -0
  694. wandb/vendor/pygments/lexers/ncl.py +894 -0
  695. wandb/vendor/pygments/lexers/nimrod.py +159 -0
  696. wandb/vendor/pygments/lexers/nit.py +64 -0
  697. wandb/vendor/pygments/lexers/nix.py +136 -0
  698. wandb/vendor/pygments/lexers/oberon.py +105 -0
  699. wandb/vendor/pygments/lexers/objective.py +504 -0
  700. wandb/vendor/pygments/lexers/ooc.py +85 -0
  701. wandb/vendor/pygments/lexers/other.py +41 -0
  702. wandb/vendor/pygments/lexers/parasail.py +79 -0
  703. wandb/vendor/pygments/lexers/parsers.py +835 -0
  704. wandb/vendor/pygments/lexers/pascal.py +644 -0
  705. wandb/vendor/pygments/lexers/pawn.py +199 -0
  706. wandb/vendor/pygments/lexers/perl.py +620 -0
  707. wandb/vendor/pygments/lexers/php.py +267 -0
  708. wandb/vendor/pygments/lexers/praat.py +294 -0
  709. wandb/vendor/pygments/lexers/prolog.py +306 -0
  710. wandb/vendor/pygments/lexers/python.py +939 -0
  711. wandb/vendor/pygments/lexers/qvt.py +152 -0
  712. wandb/vendor/pygments/lexers/r.py +453 -0
  713. wandb/vendor/pygments/lexers/rdf.py +270 -0
  714. wandb/vendor/pygments/lexers/rebol.py +431 -0
  715. wandb/vendor/pygments/lexers/resource.py +85 -0
  716. wandb/vendor/pygments/lexers/rnc.py +67 -0
  717. wandb/vendor/pygments/lexers/roboconf.py +82 -0
  718. wandb/vendor/pygments/lexers/robotframework.py +560 -0
  719. wandb/vendor/pygments/lexers/ruby.py +519 -0
  720. wandb/vendor/pygments/lexers/rust.py +220 -0
  721. wandb/vendor/pygments/lexers/sas.py +228 -0
  722. wandb/vendor/pygments/lexers/scripting.py +1222 -0
  723. wandb/vendor/pygments/lexers/shell.py +794 -0
  724. wandb/vendor/pygments/lexers/smalltalk.py +195 -0
  725. wandb/vendor/pygments/lexers/smv.py +79 -0
  726. wandb/vendor/pygments/lexers/snobol.py +83 -0
  727. wandb/vendor/pygments/lexers/special.py +103 -0
  728. wandb/vendor/pygments/lexers/sql.py +681 -0
  729. wandb/vendor/pygments/lexers/stata.py +108 -0
  730. wandb/vendor/pygments/lexers/supercollider.py +90 -0
  731. wandb/vendor/pygments/lexers/tcl.py +145 -0
  732. wandb/vendor/pygments/lexers/templates.py +2283 -0
  733. wandb/vendor/pygments/lexers/testing.py +207 -0
  734. wandb/vendor/pygments/lexers/text.py +25 -0
  735. wandb/vendor/pygments/lexers/textedit.py +169 -0
  736. wandb/vendor/pygments/lexers/textfmts.py +297 -0
  737. wandb/vendor/pygments/lexers/theorem.py +458 -0
  738. wandb/vendor/pygments/lexers/trafficscript.py +54 -0
  739. wandb/vendor/pygments/lexers/typoscript.py +226 -0
  740. wandb/vendor/pygments/lexers/urbi.py +133 -0
  741. wandb/vendor/pygments/lexers/varnish.py +190 -0
  742. wandb/vendor/pygments/lexers/verification.py +111 -0
  743. wandb/vendor/pygments/lexers/web.py +24 -0
  744. wandb/vendor/pygments/lexers/webmisc.py +988 -0
  745. wandb/vendor/pygments/lexers/whiley.py +116 -0
  746. wandb/vendor/pygments/lexers/x10.py +69 -0
  747. wandb/vendor/pygments/modeline.py +44 -0
  748. wandb/vendor/pygments/plugin.py +68 -0
  749. wandb/vendor/pygments/regexopt.py +92 -0
  750. wandb/vendor/pygments/scanner.py +105 -0
  751. wandb/vendor/pygments/sphinxext.py +158 -0
  752. wandb/vendor/pygments/style.py +155 -0
  753. wandb/vendor/pygments/styles/__init__.py +80 -0
  754. wandb/vendor/pygments/styles/abap.py +29 -0
  755. wandb/vendor/pygments/styles/algol.py +63 -0
  756. wandb/vendor/pygments/styles/algol_nu.py +63 -0
  757. wandb/vendor/pygments/styles/arduino.py +98 -0
  758. wandb/vendor/pygments/styles/autumn.py +65 -0
  759. wandb/vendor/pygments/styles/borland.py +51 -0
  760. wandb/vendor/pygments/styles/bw.py +49 -0
  761. wandb/vendor/pygments/styles/colorful.py +81 -0
  762. wandb/vendor/pygments/styles/default.py +73 -0
  763. wandb/vendor/pygments/styles/emacs.py +72 -0
  764. wandb/vendor/pygments/styles/friendly.py +72 -0
  765. wandb/vendor/pygments/styles/fruity.py +42 -0
  766. wandb/vendor/pygments/styles/igor.py +29 -0
  767. wandb/vendor/pygments/styles/lovelace.py +97 -0
  768. wandb/vendor/pygments/styles/manni.py +75 -0
  769. wandb/vendor/pygments/styles/monokai.py +106 -0
  770. wandb/vendor/pygments/styles/murphy.py +80 -0
  771. wandb/vendor/pygments/styles/native.py +65 -0
  772. wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
  773. wandb/vendor/pygments/styles/paraiso_light.py +125 -0
  774. wandb/vendor/pygments/styles/pastie.py +75 -0
  775. wandb/vendor/pygments/styles/perldoc.py +69 -0
  776. wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
  777. wandb/vendor/pygments/styles/rrt.py +33 -0
  778. wandb/vendor/pygments/styles/sas.py +44 -0
  779. wandb/vendor/pygments/styles/stata.py +40 -0
  780. wandb/vendor/pygments/styles/tango.py +141 -0
  781. wandb/vendor/pygments/styles/trac.py +63 -0
  782. wandb/vendor/pygments/styles/vim.py +63 -0
  783. wandb/vendor/pygments/styles/vs.py +38 -0
  784. wandb/vendor/pygments/styles/xcode.py +51 -0
  785. wandb/vendor/pygments/token.py +213 -0
  786. wandb/vendor/pygments/unistring.py +217 -0
  787. wandb/vendor/pygments/util.py +388 -0
  788. wandb/vendor/pynvml/__init__.py +0 -0
  789. wandb/vendor/pynvml/pynvml.py +4779 -0
  790. wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
  791. wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
  792. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
  793. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
  794. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
  795. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
  796. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
  797. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
  798. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
  799. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
  800. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
  801. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
  802. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
  803. wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
  804. wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
  805. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
  806. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
  807. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
  808. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
  809. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
  810. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
  811. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
  812. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
  813. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
  814. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
  815. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
  816. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
  817. wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
  818. wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
  819. wandb/wandb_agent.py +588 -0
  820. wandb/wandb_controller.py +721 -0
  821. wandb/wandb_run.py +9 -0
  822. wandb-0.18.1.dist-info/METADATA +212 -0
  823. wandb-0.18.1.dist-info/RECORD +826 -0
  824. wandb-0.18.1.dist-info/WHEEL +4 -0
  825. wandb-0.18.1.dist-info/entry_points.txt +3 -0
  826. wandb-0.18.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1999 @@
1
+ import collections.abc
2
+ import configparser
3
+ import enum
4
+ import getpass
5
+ import json
6
+ import logging
7
+ import multiprocessing
8
+ import os
9
+ import platform
10
+ import re
11
+ import shutil
12
+ import socket
13
+ import sys
14
+ import tempfile
15
+ import time
16
+ from dataclasses import dataclass
17
+ from datetime import datetime
18
+ from distutils.util import strtobool
19
+ from functools import reduce
20
+ from typing import (
21
+ Any,
22
+ Callable,
23
+ Dict,
24
+ FrozenSet,
25
+ ItemsView,
26
+ Iterable,
27
+ Mapping,
28
+ Optional,
29
+ Sequence,
30
+ Set,
31
+ Tuple,
32
+ Union,
33
+ no_type_check,
34
+ )
35
+ from urllib.parse import quote, unquote, urlencode, urlparse, urlsplit
36
+
37
+ from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue, Int32Value, StringValue
38
+
39
+ import wandb
40
+ import wandb.env
41
+ from wandb import util
42
+ from wandb.apis.internal import Api
43
+ from wandb.errors import UsageError
44
+ from wandb.proto import wandb_settings_pb2
45
+ from wandb.sdk.internal.system.env_probe_helpers import is_aws_lambda
46
+ from wandb.sdk.lib import credentials, filesystem
47
+ from wandb.sdk.lib._settings_toposort_generated import SETTINGS_TOPOLOGICALLY_SORTED
48
+ from wandb.sdk.lib.run_moment import RunMoment
49
+ from wandb.sdk.wandb_setup import _EarlyLogger
50
+
51
+ from .lib import apikey
52
+ from .lib.gitlib import GitRepo
53
+ from .lib.ipython import _get_python_type
54
+ from .lib.runid import generate_id
55
+
56
+ if sys.version_info >= (3, 8):
57
+ from typing import get_args, get_origin, get_type_hints
58
+ else:
59
+ from typing_extensions import get_args, get_origin, get_type_hints
60
+
61
+
62
+ class SettingsPreprocessingError(UsageError):
63
+ """Raised when the value supplied to a wandb.Settings() setting does not pass preprocessing."""
64
+
65
+
66
+ class SettingsValidationError(UsageError):
67
+ """Raised when the value supplied to a wandb.Settings() setting does not pass validation."""
68
+
69
+
70
+ class SettingsUnexpectedArgsError(UsageError):
71
+ """Raised when unexpected arguments are passed to wandb.Settings()."""
72
+
73
+
74
+ def _get_wandb_dir(root_dir: str) -> str:
75
+ """Get the full path to the wandb directory.
76
+
77
+ The setting exposed to users as `dir=` or `WANDB_DIR` is the `root_dir`.
78
+ We add the `__stage_dir__` to it to get the full `wandb_dir`
79
+ """
80
+ # We use the hidden version if it already exists, otherwise non-hidden.
81
+ if os.path.exists(os.path.join(root_dir, ".wandb")):
82
+ __stage_dir__ = ".wandb" + os.sep
83
+ else:
84
+ __stage_dir__ = "wandb" + os.sep
85
+
86
+ path = os.path.join(root_dir, __stage_dir__)
87
+ if not os.access(root_dir or ".", os.W_OK):
88
+ wandb.termwarn(
89
+ f"Path {path} wasn't writable, using system temp directory.",
90
+ repeat=False,
91
+ )
92
+ path = os.path.join(tempfile.gettempdir(), __stage_dir__ or ("wandb" + os.sep))
93
+
94
+ return os.path.expanduser(path)
95
+
96
+
97
+ def _str_as_bool(val: Union[str, bool]) -> bool:
98
+ """Parse a string as a bool."""
99
+ if isinstance(val, bool):
100
+ return val
101
+ try:
102
+ ret_val = bool(strtobool(str(val)))
103
+ return ret_val
104
+ except (AttributeError, ValueError):
105
+ pass
106
+
107
+ raise UsageError(f"Could not parse value {val} as a bool.")
108
+
109
+
110
+ def _str_as_json(val: Union[str, Dict[str, Any]]) -> Any:
111
+ """Parse a string as a json object."""
112
+ if not isinstance(val, str):
113
+ return val
114
+ try:
115
+ return json.loads(val)
116
+ except (AttributeError, ValueError):
117
+ pass
118
+
119
+ raise UsageError(f"Could not parse value {val} as JSON.")
120
+
121
+
122
+ def _str_as_tuple(val: Union[str, Sequence[str]]) -> Tuple[str, ...]:
123
+ """Parse a (potentially comma-separated) string as a tuple."""
124
+ if isinstance(val, str):
125
+ return tuple(val.split(","))
126
+ return tuple(val)
127
+
128
+
129
+ def _datetime_as_str(val: Union[datetime, str]) -> str:
130
+ """Parse a datetime object as a string."""
131
+ if isinstance(val, datetime):
132
+ return datetime.strftime(val, "%Y%m%d_%H%M%S")
133
+ return val
134
+
135
+
136
+ def _redact_dict(
137
+ d: Dict[str, Any],
138
+ unsafe_keys: Union[Set[str], FrozenSet[str]] = frozenset({"api_key"}),
139
+ redact_str: str = "***REDACTED***",
140
+ ) -> Dict[str, Any]:
141
+ """Redact a dict of unsafe values specified by their key."""
142
+ if not d or unsafe_keys.isdisjoint(d):
143
+ return d
144
+ safe_dict = d.copy()
145
+ safe_dict.update({k: redact_str for k in unsafe_keys.intersection(d)})
146
+ return safe_dict
147
+
148
+
149
+ def _get_program() -> Optional[str]:
150
+ program = os.getenv(wandb.env.PROGRAM)
151
+ if program is not None:
152
+ return program
153
+ try:
154
+ import __main__
155
+
156
+ if __main__.__spec__ is None:
157
+ return __main__.__file__
158
+ # likely run as `python -m ...`
159
+ return f"-m {__main__.__spec__.name}"
160
+ except (ImportError, AttributeError):
161
+ return None
162
+
163
+
164
+ def _runmoment_preprocessor(val: Any) -> Optional[RunMoment]:
165
+ if isinstance(val, RunMoment) or val is None:
166
+ return val
167
+ elif isinstance(val, str):
168
+ return RunMoment.from_uri(val)
169
+ raise UsageError(f"Could not parse value {val} as a RunMoment.")
170
+
171
+
172
+ def _get_program_relpath(
173
+ program: str, root: Optional[str] = None, _logger: Optional[_EarlyLogger] = None
174
+ ) -> Optional[str]:
175
+ if not program:
176
+ if _logger is not None:
177
+ _logger.warning("Empty program passed to get_program_relpath")
178
+ return None
179
+
180
+ root = root or os.getcwd()
181
+ if not root:
182
+ return None
183
+
184
+ full_path_to_program = os.path.join(
185
+ root, os.path.relpath(os.getcwd(), root), program
186
+ )
187
+ if os.path.exists(full_path_to_program):
188
+ relative_path = os.path.relpath(full_path_to_program, start=root)
189
+ if "../" in relative_path:
190
+ if _logger is not None:
191
+ _logger.warning(f"Could not save program above cwd: {program}")
192
+ return None
193
+ return relative_path
194
+
195
+ if _logger is not None:
196
+ _logger.warning(f"Could not find program at {program}")
197
+ return None
198
+
199
+
200
+ def is_instance_recursive(obj: Any, type_hint: Any) -> bool: # noqa: C901
201
+ if type_hint is Any:
202
+ return True
203
+
204
+ origin = get_origin(type_hint)
205
+ args = get_args(type_hint)
206
+
207
+ if origin is None:
208
+ return isinstance(obj, type_hint)
209
+
210
+ if origin is Union:
211
+ return any(is_instance_recursive(obj, arg) for arg in args)
212
+
213
+ if issubclass(origin, collections.abc.Mapping):
214
+ if not isinstance(obj, collections.abc.Mapping):
215
+ return False
216
+ key_type, value_type = args
217
+
218
+ for key, value in obj.items():
219
+ if not is_instance_recursive(key, key_type) or not is_instance_recursive(
220
+ value, value_type
221
+ ):
222
+ return False
223
+
224
+ return True
225
+
226
+ if issubclass(origin, collections.abc.Sequence):
227
+ if not isinstance(obj, collections.abc.Sequence) or isinstance(
228
+ obj, (str, bytes, bytearray)
229
+ ):
230
+ return False
231
+
232
+ if len(args) == 1 and args[0] != ...:
233
+ (item_type,) = args
234
+ for item in obj:
235
+ if not is_instance_recursive(item, item_type):
236
+ return False
237
+ elif len(args) == 2 and args[-1] == ...:
238
+ item_type = args[0]
239
+ for item in obj:
240
+ if not is_instance_recursive(item, item_type):
241
+ return False
242
+ elif len(args) == len(obj):
243
+ for item, item_type in zip(obj, args):
244
+ if not is_instance_recursive(item, item_type):
245
+ return False
246
+ else:
247
+ return False
248
+
249
+ return True
250
+
251
+ if issubclass(origin, collections.abc.Set):
252
+ if not isinstance(obj, collections.abc.Set):
253
+ return False
254
+
255
+ (item_type,) = args
256
+ for item in obj:
257
+ if not is_instance_recursive(item, item_type):
258
+ return False
259
+
260
+ return True
261
+
262
+ return False
263
+
264
+
265
+ @enum.unique
266
+ class Source(enum.IntEnum):
267
+ OVERRIDE: int = 0
268
+ BASE: int = 1 # todo: audit this
269
+ ORG: int = 2
270
+ ENTITY: int = 3
271
+ PROJECT: int = 4
272
+ USER: int = 5
273
+ SYSTEM: int = 6
274
+ WORKSPACE: int = 7
275
+ ENV: int = 8
276
+ SETUP: int = 9
277
+ LOGIN: int = 10
278
+ INIT: int = 11
279
+ SETTINGS: int = 12
280
+ ARGS: int = 13
281
+ RUN: int = 14
282
+
283
+
284
+ ConsoleValue = {
285
+ "auto",
286
+ "off",
287
+ "wrap",
288
+ "redirect",
289
+ # internal console states
290
+ "wrap_raw",
291
+ "wrap_emu",
292
+ }
293
+
294
+
295
+ @dataclass()
296
+ class SettingsData:
297
+ """Settings for the W&B SDK."""
298
+
299
+ _args: Sequence[str]
300
+ _aws_lambda: bool
301
+ _cli_only_mode: bool # Avoid running any code specific for runs
302
+ _code_path_local: str
303
+ _colab: bool
304
+ # _config_dict: Config
305
+ _cuda: str
306
+ _disable_meta: bool # Do not collect system metadata
307
+ _disable_service: (
308
+ bool # Disable wandb-service, spin up internal process the old way
309
+ )
310
+ _disable_setproctitle: bool # Do not use setproctitle on internal process
311
+ _disable_stats: bool # Do not collect system metrics
312
+ _disable_update_check: bool # Disable version check
313
+ _disable_viewer: bool # Prevent early viewer query
314
+ _disable_machine_info: bool # Disable automatic machine info collection
315
+ _executable: str
316
+ _extra_http_headers: Mapping[str, str]
317
+ _file_stream_max_bytes: int # max size for filestream requests in core
318
+ # file stream retry client configuration
319
+ _file_stream_retry_max: int # max number of retries
320
+ _file_stream_retry_wait_min_seconds: float # min wait time between retries
321
+ _file_stream_retry_wait_max_seconds: float # max wait time between retries
322
+ _file_stream_timeout_seconds: float # timeout for individual HTTP requests
323
+ # file transfer retry client configuration
324
+ _file_transfer_retry_max: int
325
+ _file_transfer_retry_wait_min_seconds: float
326
+ _file_transfer_retry_wait_max_seconds: float
327
+ _file_transfer_timeout_seconds: float
328
+ _flow_control_custom: bool
329
+ _flow_control_disabled: bool
330
+ # graphql retry client configuration
331
+ _graphql_retry_max: int
332
+ _graphql_retry_wait_min_seconds: float
333
+ _graphql_retry_wait_max_seconds: float
334
+ _graphql_timeout_seconds: float
335
+ _internal_check_process: float
336
+ _internal_queue_timeout: float
337
+ _ipython: bool
338
+ _jupyter: bool
339
+ _jupyter_name: str
340
+ _jupyter_path: str
341
+ _jupyter_root: str
342
+ _kaggle: bool
343
+ _live_policy_rate_limit: int
344
+ _live_policy_wait_time: int
345
+ _log_level: int
346
+ _network_buffer: int
347
+ _noop: bool
348
+ _notebook: bool
349
+ _offline: bool
350
+ _sync: bool
351
+ _os: str
352
+ _platform: str
353
+ _proxies: Mapping[
354
+ str, str
355
+ ] # custom proxy servers for the requests to W&B [scheme -> url]
356
+ _python: str
357
+ _runqueue_item_id: str
358
+ _require_legacy_service: bool
359
+ _save_requirements: bool
360
+ _service_transport: str
361
+ _service_wait: float
362
+ _shared: bool
363
+ _start_datetime: str
364
+ _start_time: float
365
+ _stats_pid: int # (internal) base pid for system stats
366
+ _stats_sampling_interval: float # sampling interval for system stats
367
+ _stats_sample_rate_seconds: float # badly-named sampling interval, deprecated
368
+ _stats_samples_to_average: (
369
+ int # number of samples to average before reporting, deprecated
370
+ )
371
+ _stats_join_assets: (
372
+ bool # join metrics from different assets before sending to backend
373
+ )
374
+ _stats_neuron_monitor_config_path: (
375
+ str # path to place config file for neuron-monitor (AWS Trainium)
376
+ )
377
+ _stats_open_metrics_endpoints: Mapping[str, str] # open metrics endpoint names/urls
378
+ # open metrics filters in one of the two formats:
379
+ # - {"metric regex pattern, including endpoint name as prefix": {"label": "label value regex pattern"}}
380
+ # - ("metric regex pattern 1", "metric regex pattern 2", ...)
381
+ _stats_open_metrics_filters: Union[Sequence[str], Mapping[str, Mapping[str, str]]]
382
+ _stats_disk_paths: Sequence[str] # paths to monitor disk usage
383
+ _stats_buffer_size: int # number of consolidated samples to buffer before flushing, available in run obj
384
+ _tmp_code_dir: str
385
+ _tracelog: str
386
+ _unsaved_keys: Sequence[str]
387
+ _windows: bool
388
+ allow_val_change: bool
389
+ anonymous: str
390
+ api_key: str
391
+ azure_account_url_to_access_key: Dict[str, str]
392
+ base_url: str # The base url for the wandb api
393
+ code_dir: str
394
+ colab_url: str
395
+ config_paths: Sequence[str]
396
+ console: str
397
+ console_multipart: bool # whether to produce multipart console log files
398
+ credentials_file: str # file path to write access tokens
399
+ deployment: str
400
+ disable_code: bool
401
+ disable_git: bool
402
+ disable_hints: bool
403
+ disable_job_creation: bool
404
+ disabled: bool # Alias for mode=dryrun, not supported yet
405
+ docker: str
406
+ email: str
407
+ entity: str
408
+ files_dir: str
409
+ force: bool
410
+ fork_from: RunMoment
411
+ resume_from: RunMoment
412
+ git_commit: str
413
+ git_remote: str
414
+ git_remote_url: str
415
+ git_root: str
416
+ heartbeat_seconds: int
417
+ host: str
418
+ http_proxy: str # proxy server for the http requests to W&B
419
+ https_proxy: str # proxy server for the https requests to W&B
420
+ identity_token_file: str # file path to supply a jwt for authentication
421
+ ignore_globs: Tuple[str]
422
+ init_timeout: float
423
+ is_local: bool
424
+ job_name: str
425
+ job_source: str
426
+ label_disable: bool
427
+ launch: bool
428
+ launch_config_path: str
429
+ log_dir: str
430
+ log_internal: str
431
+ log_symlink_internal: str
432
+ log_symlink_user: str
433
+ log_user: str
434
+ login_timeout: float
435
+ # magic: Union[str, bool, dict] # never used in code, deprecated
436
+ mode: str
437
+ notebook_name: str
438
+ program: str
439
+ program_abspath: str
440
+ program_relpath: str
441
+ project: str
442
+ project_url: str
443
+ quiet: bool
444
+ reinit: bool
445
+ relogin: bool
446
+ # todo: add a preprocessing step to convert this to string
447
+ resume: Union[str, bool]
448
+ resume_fname: str
449
+ resumed: bool # indication from the server about the state of the run (different from resume - user provided flag)
450
+ root_dir: str
451
+ run_group: str
452
+ run_id: str
453
+ run_job_type: str
454
+ run_mode: str
455
+ run_name: str
456
+ run_notes: str
457
+ run_tags: Tuple[str]
458
+ run_url: str
459
+ sagemaker_disable: bool
460
+ save_code: bool
461
+ settings_system: str
462
+ settings_workspace: str
463
+ show_colors: bool
464
+ show_emoji: bool
465
+ show_errors: bool
466
+ show_info: bool
467
+ show_warnings: bool
468
+ silent: bool
469
+ start_method: str
470
+ strict: bool
471
+ summary_errors: int
472
+ summary_timeout: int
473
+ summary_warnings: int
474
+ sweep_id: str
475
+ sweep_param_path: str
476
+ sweep_url: str
477
+ symlink: bool
478
+ sync_dir: str
479
+ sync_file: str
480
+ sync_symlink_latest: str
481
+ table_raise_on_max_row_limit_exceeded: bool
482
+ timespec: str
483
+ tmp_dir: str
484
+ username: str
485
+ wandb_dir: str
486
+
487
+
488
+ class Property:
489
+ """A class to represent attributes (individual settings) of the Settings object.
490
+
491
+ - Encapsulates the logic of how to preprocess and validate values of settings
492
+ throughout the lifetime of a class instance.
493
+ - Allows for runtime modification of settings with hooks, e.g. in the case when
494
+ a setting depends on another setting.
495
+ - The update() method is used to update the value of a setting.
496
+ - The `is_policy` attribute determines the source priority when updating the property value.
497
+ E.g. if `is_policy` is True, the smallest `Source` value takes precedence.
498
+ """
499
+
500
+ def __init__( # pylint: disable=unused-argument
501
+ self,
502
+ name: str,
503
+ value: Optional[Any] = None,
504
+ preprocessor: Union[Callable, Sequence[Callable], None] = None,
505
+ # validators allow programming by contract
506
+ validator: Union[Callable, Sequence[Callable], None] = None,
507
+ # runtime converter (hook): properties can be e.g. tied to other properties
508
+ hook: Union[Callable, Sequence[Callable], None] = None,
509
+ # always apply hook even if value is None. can be used to replace @property's
510
+ auto_hook: bool = False,
511
+ is_policy: bool = False,
512
+ frozen: bool = False,
513
+ source: int = Source.BASE,
514
+ **kwargs: Any,
515
+ ):
516
+ self.name = name
517
+ self._preprocessor = preprocessor
518
+ self._validator = validator
519
+ self._hook = hook
520
+ self._auto_hook = auto_hook
521
+ self._is_policy = is_policy
522
+ self._source = source
523
+
524
+ # preprocess and validate value
525
+ self._value = self._validate(self._preprocess(value))
526
+
527
+ self.__frozen = frozen
528
+
529
+ @property
530
+ def value(self) -> Any:
531
+ """Apply the runtime modifier(s) (if any) and return the value."""
532
+ _value = self._value
533
+ if (_value is not None or self._auto_hook) and self._hook is not None:
534
+ _hook = [self._hook] if callable(self._hook) else self._hook
535
+ for h in _hook:
536
+ _value = h(_value)
537
+ return _value
538
+
539
+ @property
540
+ def is_policy(self) -> bool:
541
+ return self._is_policy
542
+
543
+ @property
544
+ def source(self) -> int:
545
+ return self._source
546
+
547
+ def _preprocess(self, value: Any) -> Any:
548
+ if value is not None and self._preprocessor is not None:
549
+ _preprocessor = (
550
+ [self._preprocessor]
551
+ if callable(self._preprocessor)
552
+ else self._preprocessor
553
+ )
554
+ for p in _preprocessor:
555
+ try:
556
+ value = p(value)
557
+ except Exception:
558
+ raise SettingsPreprocessingError(
559
+ f"Unable to preprocess value for property {self.name}: {value}."
560
+ )
561
+ return value
562
+
563
+ def _validate(self, value: Any) -> Any:
564
+ if value is not None and self._validator is not None:
565
+ _validator = (
566
+ [self._validator] if callable(self._validator) else self._validator
567
+ )
568
+ for v in _validator:
569
+ if not v(value):
570
+ # failed validation will likely cause a downstream error
571
+ # when trying to convert to protobuf, so we raise a hard error
572
+ raise SettingsValidationError(
573
+ f"Invalid value for property {self.name}: {value}."
574
+ )
575
+ return value
576
+
577
+ def update(self, value: Any, source: int = Source.OVERRIDE) -> None:
578
+ """Update the value of the property."""
579
+ if self.__frozen:
580
+ raise TypeError("Property object is frozen")
581
+ # - always update value if source == Source.OVERRIDE
582
+ # - if not previously overridden:
583
+ # - update value if source is lower than or equal to current source and property is policy
584
+ # - update value if source is higher than or equal to current source and property is not policy
585
+ if (
586
+ (source == Source.OVERRIDE)
587
+ or (
588
+ self._is_policy
589
+ and self._source != Source.OVERRIDE
590
+ and source <= self._source
591
+ )
592
+ or (
593
+ not self._is_policy
594
+ and self._source != Source.OVERRIDE
595
+ and source >= self._source
596
+ )
597
+ ):
598
+ # self.__dict__["_value"] = self._validate(self._preprocess(value))
599
+ self._value = self._validate(self._preprocess(value))
600
+ self._source = source
601
+
602
+ def __setattr__(self, key: str, value: Any) -> None:
603
+ if "_Property__frozen" in self.__dict__ and self.__frozen:
604
+ raise TypeError(f"Property object {self.name} is frozen")
605
+ if key == "value":
606
+ raise AttributeError("Use update() to update property value")
607
+ self.__dict__[key] = value
608
+
609
+ def __str__(self) -> str:
610
+ return f"{self.value!r}" if isinstance(self.value, str) else f"{self.value}"
611
+
612
+ def __repr__(self) -> str:
613
+ return (
614
+ f"<Property {self.name}: value={self.value} "
615
+ f"_value={self._value} source={self._source} is_policy={self._is_policy}>"
616
+ )
617
+ # return f"<Property {self.name}: value={self.value}>"
618
+ # return self.__dict__.__repr__()
619
+
620
+
621
+ class Settings(SettingsData):
622
+ """Settings for the W&B SDK."""
623
+
624
+ def _default_props(self) -> Dict[str, Dict[str, Any]]:
625
+ """Initialize instance attributes (individual settings) as Property objects.
626
+
627
+ Helper method that is used in `__init__` together with the class attributes.
628
+ Note that key names must be the same as the class attribute names.
629
+ """
630
+ props: Dict[str, Dict[str, Any]] = dict(
631
+ _aws_lambda={
632
+ "hook": lambda _: is_aws_lambda(),
633
+ "auto_hook": True,
634
+ },
635
+ _code_path_local={
636
+ "hook": lambda _: _get_program_relpath(self.program),
637
+ "auto_hook": True,
638
+ },
639
+ _colab={
640
+ "hook": lambda _: "google.colab" in sys.modules,
641
+ "auto_hook": True,
642
+ },
643
+ _disable_machine_info={
644
+ "value": False,
645
+ "preprocessor": _str_as_bool,
646
+ },
647
+ _disable_meta={
648
+ "value": False,
649
+ "preprocessor": _str_as_bool,
650
+ "hook": lambda x: self._disable_machine_info or x,
651
+ },
652
+ _disable_service={
653
+ "value": False,
654
+ "preprocessor": self._process_disable_service,
655
+ "is_policy": True,
656
+ },
657
+ _disable_setproctitle={"value": False, "preprocessor": _str_as_bool},
658
+ _disable_stats={
659
+ "value": False,
660
+ "preprocessor": _str_as_bool,
661
+ "hook": lambda x: self._disable_machine_info or x,
662
+ },
663
+ _disable_update_check={"preprocessor": _str_as_bool},
664
+ _disable_viewer={"preprocessor": _str_as_bool},
665
+ _extra_http_headers={"preprocessor": _str_as_json},
666
+ _file_stream_max_bytes={"preprocessor": int},
667
+ _file_stream_retry_max={"preprocessor": int},
668
+ _file_stream_retry_wait_min_seconds={"preprocessor": float},
669
+ _file_stream_retry_wait_max_seconds={"preprocessor": float},
670
+ _file_stream_timeout_seconds={"preprocessor": float},
671
+ _file_transfer_retry_max={"preprocessor": int},
672
+ _file_transfer_retry_wait_min_seconds={"preprocessor": float},
673
+ _file_transfer_retry_wait_max_seconds={"preprocessor": float},
674
+ _file_transfer_timeout_seconds={"preprocessor": float},
675
+ _flow_control_disabled={
676
+ "hook": lambda _: self._network_buffer == 0,
677
+ "auto_hook": True,
678
+ },
679
+ _flow_control_custom={
680
+ "hook": lambda _: bool(self._network_buffer),
681
+ "auto_hook": True,
682
+ },
683
+ _graphql_retry_max={"preprocessor": int},
684
+ _graphql_retry_wait_min_seconds={"preprocessor": float},
685
+ _graphql_retry_wait_max_seconds={"preprocessor": float},
686
+ _graphql_timeout_seconds={"preprocessor": float},
687
+ _internal_check_process={"value": 8, "preprocessor": float},
688
+ _internal_queue_timeout={"value": 2, "preprocessor": float},
689
+ _ipython={
690
+ "hook": lambda _: _get_python_type() == "ipython",
691
+ "auto_hook": True,
692
+ },
693
+ _jupyter={
694
+ "hook": lambda _: _get_python_type() == "jupyter",
695
+ "auto_hook": True,
696
+ },
697
+ _kaggle={"hook": lambda _: util._is_likely_kaggle(), "auto_hook": True},
698
+ _log_level={"value": logging.DEBUG},
699
+ _network_buffer={"preprocessor": int},
700
+ _noop={"hook": lambda _: self.mode == "disabled", "auto_hook": True},
701
+ _notebook={
702
+ "hook": lambda _: self._ipython
703
+ or self._jupyter
704
+ or self._colab
705
+ or self._kaggle,
706
+ "auto_hook": True,
707
+ },
708
+ _offline={
709
+ "hook": (
710
+ lambda _: True
711
+ if self.disabled or (self.mode in ("dryrun", "offline"))
712
+ else False
713
+ ),
714
+ "auto_hook": True,
715
+ },
716
+ _platform={"value": util.get_platform_name()},
717
+ _proxies={
718
+ # TODO: deprecate and ask the user to use http_proxy and https_proxy instead
719
+ "preprocessor": _str_as_json,
720
+ },
721
+ _require_legacy_service={"value": False, "preprocessor": _str_as_bool},
722
+ _save_requirements={"value": True, "preprocessor": _str_as_bool},
723
+ _service_wait={
724
+ "value": 30,
725
+ "preprocessor": float,
726
+ "validator": self._validate__service_wait,
727
+ },
728
+ _shared={
729
+ "hook": lambda _: self.mode == "shared",
730
+ "auto_hook": True,
731
+ },
732
+ _start_datetime={"preprocessor": _datetime_as_str},
733
+ _stats_sampling_interval={
734
+ "value": 10.0,
735
+ "preprocessor": float,
736
+ "validator": self._validate__stats_sampling_interval,
737
+ },
738
+ _stats_sample_rate_seconds={
739
+ "value": 2.0,
740
+ "preprocessor": float,
741
+ "validator": self._validate__stats_sample_rate_seconds,
742
+ },
743
+ _stats_samples_to_average={
744
+ "value": 15,
745
+ "preprocessor": int,
746
+ "validator": self._validate__stats_samples_to_average,
747
+ },
748
+ _stats_join_assets={"value": True, "preprocessor": _str_as_bool},
749
+ _stats_neuron_monitor_config_path={
750
+ "hook": lambda x: self._path_convert(x),
751
+ },
752
+ _stats_open_metrics_endpoints={
753
+ "preprocessor": _str_as_json,
754
+ },
755
+ _stats_open_metrics_filters={
756
+ # capture all metrics on all endpoints by default
757
+ "value": (".*",),
758
+ "preprocessor": _str_as_json,
759
+ },
760
+ _stats_disk_paths={
761
+ "value": ("/",),
762
+ "preprocessor": _str_as_json,
763
+ },
764
+ _stats_buffer_size={
765
+ "value": 0,
766
+ "preprocessor": int,
767
+ },
768
+ _sync={"value": False},
769
+ _tmp_code_dir={
770
+ "value": "code",
771
+ "hook": lambda x: self._path_convert(self.tmp_dir, x),
772
+ },
773
+ _windows={
774
+ "hook": lambda _: platform.system() == "Windows",
775
+ "auto_hook": True,
776
+ },
777
+ anonymous={"validator": self._validate_anonymous},
778
+ api_key={"validator": self._validate_api_key},
779
+ base_url={
780
+ "value": "https://api.wandb.ai",
781
+ "preprocessor": lambda x: str(x).strip().rstrip("/"),
782
+ "validator": self._validate_base_url,
783
+ },
784
+ colab_url={
785
+ "hook": lambda _: self._get_colab_url(),
786
+ "auto_hook": True,
787
+ },
788
+ config_paths={"preprocessor": _str_as_tuple},
789
+ console={
790
+ "value": "auto",
791
+ "validator": self._validate_console,
792
+ "hook": lambda x: self._convert_console(x),
793
+ "auto_hook": True,
794
+ },
795
+ console_multipart={"value": False, "preprocessor": _str_as_bool},
796
+ credentials_file={
797
+ "value": str(credentials.DEFAULT_WANDB_CREDENTIALS_FILE),
798
+ "preprocessor": str,
799
+ },
800
+ deployment={
801
+ "hook": lambda _: "local" if self.is_local else "cloud",
802
+ "auto_hook": True,
803
+ },
804
+ disable_code={
805
+ "value": False,
806
+ "preprocessor": _str_as_bool,
807
+ "hook": lambda x: self._disable_machine_info or x,
808
+ },
809
+ disable_hints={"preprocessor": _str_as_bool},
810
+ disable_git={
811
+ "value": False,
812
+ "preprocessor": _str_as_bool,
813
+ "hook": lambda x: self._disable_machine_info or x,
814
+ },
815
+ disable_job_creation={
816
+ "value": False,
817
+ "preprocessor": _str_as_bool,
818
+ "hook": lambda x: self._disable_machine_info or x,
819
+ },
820
+ disabled={"value": False, "preprocessor": _str_as_bool},
821
+ files_dir={
822
+ "value": "files",
823
+ "hook": lambda x: self._path_convert(
824
+ self.wandb_dir, f"{self.run_mode}-{self.timespec}-{self.run_id}", x
825
+ ),
826
+ },
827
+ force={"preprocessor": _str_as_bool},
828
+ fork_from={
829
+ "value": None,
830
+ "preprocessor": _runmoment_preprocessor,
831
+ },
832
+ resume_from={
833
+ "value": None,
834
+ "preprocessor": _runmoment_preprocessor,
835
+ },
836
+ git_remote={"value": "origin"},
837
+ heartbeat_seconds={"value": 30},
838
+ http_proxy={
839
+ "hook": lambda x: self._proxies and self._proxies.get("http") or x,
840
+ "auto_hook": True,
841
+ },
842
+ https_proxy={
843
+ "hook": lambda x: self._proxies and self._proxies.get("https") or x,
844
+ "auto_hook": True,
845
+ },
846
+ identity_token_file={"value": None, "preprocessor": str},
847
+ ignore_globs={
848
+ "value": tuple(),
849
+ "preprocessor": lambda x: tuple(x) if not isinstance(x, tuple) else x,
850
+ },
851
+ init_timeout={"value": 90, "preprocessor": lambda x: float(x)},
852
+ is_local={
853
+ "hook": (
854
+ lambda _: self.base_url != "https://api.wandb.ai"
855
+ if self.base_url is not None
856
+ else False
857
+ ),
858
+ "auto_hook": True,
859
+ },
860
+ job_name={"preprocessor": str},
861
+ job_source={"validator": self._validate_job_source},
862
+ label_disable={"preprocessor": _str_as_bool},
863
+ launch={"preprocessor": _str_as_bool},
864
+ log_dir={
865
+ "value": "logs",
866
+ "hook": lambda x: self._path_convert(
867
+ self.wandb_dir, f"{self.run_mode}-{self.timespec}-{self.run_id}", x
868
+ ),
869
+ },
870
+ log_internal={
871
+ "value": "debug-internal.log",
872
+ "hook": lambda x: self._path_convert(self.log_dir, x),
873
+ },
874
+ log_symlink_internal={
875
+ "value": "debug-internal.log",
876
+ "hook": lambda x: self._path_convert(self.wandb_dir, x),
877
+ },
878
+ log_symlink_user={
879
+ "value": "debug.log",
880
+ "hook": lambda x: self._path_convert(self.wandb_dir, x),
881
+ },
882
+ log_user={
883
+ "value": "debug.log",
884
+ "hook": lambda x: self._path_convert(self.log_dir, x),
885
+ },
886
+ login_timeout={"preprocessor": lambda x: float(x)},
887
+ mode={"value": "online", "validator": self._validate_mode},
888
+ program={
889
+ "hook": lambda x: self._get_program(x),
890
+ },
891
+ project={
892
+ "validator": self._validate_project,
893
+ },
894
+ project_url={"hook": lambda _: self._project_url(), "auto_hook": True},
895
+ quiet={"preprocessor": _str_as_bool},
896
+ reinit={"preprocessor": _str_as_bool},
897
+ relogin={"preprocessor": _str_as_bool},
898
+ # todo: hack to make to_proto() always happy
899
+ resume={"preprocessor": lambda x: None if x is False else x},
900
+ resume_fname={
901
+ "value": "wandb-resume.json",
902
+ "hook": lambda x: self._path_convert(self.wandb_dir, x),
903
+ },
904
+ resumed={"value": "False", "preprocessor": _str_as_bool},
905
+ root_dir={
906
+ "preprocessor": lambda x: str(x),
907
+ "value": os.path.abspath(os.getcwd()),
908
+ },
909
+ run_id={
910
+ "validator": self._validate_run_id,
911
+ },
912
+ run_mode={
913
+ "hook": lambda _: "offline-run" if self._offline else "run",
914
+ "auto_hook": True,
915
+ },
916
+ run_tags={
917
+ "preprocessor": lambda x: tuple(x) if not isinstance(x, tuple) else x,
918
+ },
919
+ run_url={"hook": lambda _: self._run_url(), "auto_hook": True},
920
+ sagemaker_disable={"preprocessor": _str_as_bool},
921
+ save_code={"preprocessor": _str_as_bool},
922
+ settings_system={
923
+ "value": os.path.join("~", ".config", "wandb", "settings"),
924
+ "hook": lambda x: self._path_convert(x),
925
+ },
926
+ settings_workspace={
927
+ "value": "settings",
928
+ "hook": lambda x: self._path_convert(self.wandb_dir, x),
929
+ },
930
+ show_colors={"preprocessor": _str_as_bool},
931
+ show_emoji={"preprocessor": _str_as_bool},
932
+ show_errors={"value": "True", "preprocessor": _str_as_bool},
933
+ show_info={"value": "True", "preprocessor": _str_as_bool},
934
+ show_warnings={"value": "True", "preprocessor": _str_as_bool},
935
+ silent={"value": "False", "preprocessor": _str_as_bool},
936
+ start_method={"validator": self._validate_start_method},
937
+ strict={"preprocessor": _str_as_bool},
938
+ summary_timeout={"value": 60, "preprocessor": lambda x: int(x)},
939
+ summary_warnings={
940
+ "value": 5,
941
+ "preprocessor": lambda x: int(x),
942
+ "is_policy": True,
943
+ },
944
+ sweep_url={"hook": lambda _: self._sweep_url(), "auto_hook": True},
945
+ symlink={"preprocessor": _str_as_bool},
946
+ sync_dir={
947
+ "hook": [
948
+ lambda _: self._path_convert(
949
+ self.wandb_dir, f"{self.run_mode}-{self.timespec}-{self.run_id}"
950
+ )
951
+ ],
952
+ "auto_hook": True,
953
+ },
954
+ sync_file={
955
+ "hook": lambda _: self._path_convert(
956
+ self.sync_dir, f"run-{self.run_id}.wandb"
957
+ ),
958
+ "auto_hook": True,
959
+ },
960
+ sync_symlink_latest={
961
+ "value": "latest-run",
962
+ "hook": lambda x: self._path_convert(self.wandb_dir, x),
963
+ },
964
+ table_raise_on_max_row_limit_exceeded={
965
+ "value": False,
966
+ "preprocessor": _str_as_bool,
967
+ },
968
+ timespec={
969
+ "hook": lambda _: self._start_datetime,
970
+ "auto_hook": True,
971
+ },
972
+ tmp_dir={
973
+ "value": "tmp",
974
+ "hook": lambda x: (
975
+ self._path_convert(
976
+ self.wandb_dir,
977
+ f"{self.run_mode}-{self.timespec}-{self.run_id}",
978
+ x,
979
+ )
980
+ or tempfile.gettempdir()
981
+ ),
982
+ },
983
+ wandb_dir={
984
+ "hook": lambda _: _get_wandb_dir(self.root_dir or ""),
985
+ "auto_hook": True,
986
+ },
987
+ )
988
+ return props
989
+
990
+ # helper methods for validating values
991
+ @staticmethod
992
+ def _validator_factory(hint: Any) -> Callable[[Any], bool]: # noqa: C901
993
+ """Return a factory for setting type validators."""
994
+
995
+ def helper(value: Any) -> bool:
996
+ try:
997
+ is_valid = is_instance_recursive(value, hint)
998
+ except Exception:
999
+ # instance check failed, but let's not crash and only print a warning
1000
+ is_valid = False
1001
+
1002
+ return is_valid
1003
+
1004
+ return helper
1005
+
1006
+ @staticmethod
1007
+ def _validate_mode(value: str) -> bool:
1008
+ choices: Set[str] = {"dryrun", "run", "offline", "online", "disabled", "shared"}
1009
+ if value not in choices:
1010
+ raise UsageError(f"Settings field `mode`: {value!r} not in {choices}")
1011
+ return True
1012
+
1013
+ @staticmethod
1014
+ def _validate_project(value: Optional[str]) -> bool:
1015
+ invalid_chars_list = list("/\\#?%:")
1016
+ if value is not None:
1017
+ if len(value) > 128:
1018
+ raise UsageError(
1019
+ f"Invalid project name {value!r}: exceeded 128 characters"
1020
+ )
1021
+ invalid_chars = {char for char in invalid_chars_list if char in value}
1022
+ if invalid_chars:
1023
+ raise UsageError(
1024
+ f"Invalid project name {value!r}: "
1025
+ f"cannot contain characters {','.join(invalid_chars_list)!r}, "
1026
+ f"found {','.join(invalid_chars)!r}"
1027
+ )
1028
+ return True
1029
+
1030
+ @staticmethod
1031
+ def _validate_start_method(value: str) -> bool:
1032
+ available_methods = ["thread"]
1033
+ if hasattr(multiprocessing, "get_all_start_methods"):
1034
+ available_methods += multiprocessing.get_all_start_methods()
1035
+ if value not in available_methods:
1036
+ raise UsageError(
1037
+ f"Settings field `start_method`: {value!r} not in {available_methods}"
1038
+ )
1039
+ return True
1040
+
1041
+ @staticmethod
1042
+ def _validate_console(value: str) -> bool:
1043
+ choices = ConsoleValue
1044
+ if value not in choices:
1045
+ # do not advertise internal console states
1046
+ choices -= {"wrap_emu", "wrap_raw"}
1047
+ raise UsageError(f"Settings field `console`: {value!r} not in {choices}")
1048
+ return True
1049
+
1050
+ @staticmethod
1051
+ def _validate_anonymous(value: str) -> bool:
1052
+ choices: Set[str] = {"allow", "must", "never", "false", "true"}
1053
+ if value not in choices:
1054
+ raise UsageError(f"Settings field `anonymous`: {value!r} not in {choices}")
1055
+ return True
1056
+
1057
+ @staticmethod
1058
+ def _validate_run_id(value: str) -> bool:
1059
+ # if len(value) > len(value.strip()):
1060
+ # raise UsageError("Run ID cannot start or end with whitespace")
1061
+ return bool(value.strip())
1062
+
1063
+ @staticmethod
1064
+ def _validate_api_key(value: str) -> bool:
1065
+ if len(value) > len(value.strip()):
1066
+ raise UsageError("API key cannot start or end with whitespace")
1067
+
1068
+ # todo: move this check to the post-init validation step
1069
+ # if value.startswith("local") and not self.is_local:
1070
+ # raise UsageError(
1071
+ # "Attempting to use a local API key to connect to https://api.wandb.ai"
1072
+ # )
1073
+ # todo: move here the logic from sdk/lib/apikey.py
1074
+
1075
+ return True
1076
+
1077
+ @staticmethod
1078
+ def _validate_base_url(value: Optional[str]) -> bool:
1079
+ """Validate the base url of the wandb server.
1080
+
1081
+ param value: URL to validate
1082
+
1083
+ Based on the Django URLValidator, but with a few additional checks.
1084
+
1085
+ Copyright (c) Django Software Foundation and individual contributors.
1086
+ All rights reserved.
1087
+
1088
+ Redistribution and use in source and binary forms, with or without modification,
1089
+ are permitted provided that the following conditions are met:
1090
+
1091
+ 1. Redistributions of source code must retain the above copyright notice,
1092
+ this list of conditions and the following disclaimer.
1093
+
1094
+ 2. Redistributions in binary form must reproduce the above copyright
1095
+ notice, this list of conditions and the following disclaimer in the
1096
+ documentation and/or other materials provided with the distribution.
1097
+
1098
+ 3. Neither the name of Django nor the names of its contributors may be used
1099
+ to endorse or promote products derived from this software without
1100
+ specific prior written permission.
1101
+
1102
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1103
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1104
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1105
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
1106
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1107
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1108
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1109
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1110
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1111
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1112
+ """
1113
+ if value is None:
1114
+ return True
1115
+
1116
+ ul = "\u00a1-\uffff" # Unicode letters range (must not be a raw string).
1117
+
1118
+ # IP patterns
1119
+ ipv4_re = (
1120
+ r"(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)"
1121
+ r"(?:\.(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)){3}"
1122
+ )
1123
+ ipv6_re = r"\[[0-9a-f:.]+\]" # (simple regex, validated later)
1124
+
1125
+ # Host patterns
1126
+ hostname_re = (
1127
+ r"[a-z" + ul + r"0-9](?:[a-z" + ul + r"0-9-]{0,61}[a-z" + ul + r"0-9])?"
1128
+ )
1129
+ # Max length for domain name labels is 63 characters per RFC 1034 sec. 3.1
1130
+ domain_re = r"(?:\.(?!-)[a-z" + ul + r"0-9-]{1,63}(?<!-))*"
1131
+ tld_re = (
1132
+ r"\." # dot
1133
+ r"(?!-)" # can't start with a dash
1134
+ r"(?:[a-z" + ul + "-]{2,63}" # domain label
1135
+ r"|xn--[a-z0-9]{1,59})" # or punycode label
1136
+ r"(?<!-)" # can't end with a dash
1137
+ r"\.?" # may have a trailing dot
1138
+ )
1139
+ # host_re = "(" + hostname_re + domain_re + tld_re + "|localhost)"
1140
+ # todo?: allow hostname to be just a hostname (no tld)?
1141
+ host_re = "(" + hostname_re + domain_re + f"({tld_re})?" + "|localhost)"
1142
+
1143
+ regex = re.compile(
1144
+ r"^(?:[a-z0-9.+-]*)://" # scheme is validated separately
1145
+ r"(?:[^\s:@/]+(?::[^\s:@/]*)?@)?" # user:pass authentication
1146
+ r"(?:" + ipv4_re + "|" + ipv6_re + "|" + host_re + ")"
1147
+ r"(?::[0-9]{1,5})?" # port
1148
+ r"(?:[/?#][^\s]*)?" # resource path
1149
+ r"\Z",
1150
+ re.IGNORECASE,
1151
+ )
1152
+ schemes = {"http", "https"}
1153
+ unsafe_chars = frozenset("\t\r\n")
1154
+
1155
+ scheme = value.split("://")[0].lower()
1156
+ split_url = urlsplit(value)
1157
+ parsed_url = urlparse(value)
1158
+
1159
+ if re.match(r".*wandb\.ai[^\.]*$", value) and "api." not in value:
1160
+ # user might guess app.wandb.ai or wandb.ai is the default cloud server
1161
+ raise UsageError(
1162
+ f"{value} is not a valid server address, did you mean https://api.wandb.ai?"
1163
+ )
1164
+ elif re.match(r".*wandb\.ai[^\.]*$", value) and scheme != "https":
1165
+ raise UsageError("http is not secure, please use https://api.wandb.ai")
1166
+ elif parsed_url.netloc == "":
1167
+ raise UsageError(f"Invalid URL: {value}")
1168
+ elif unsafe_chars.intersection(value):
1169
+ raise UsageError("URL cannot contain unsafe characters")
1170
+ elif scheme not in schemes:
1171
+ raise UsageError("URL must start with `http(s)://`")
1172
+ elif not regex.search(value):
1173
+ raise UsageError(f"{value} is not a valid server address")
1174
+ elif split_url.hostname is None or len(split_url.hostname) > 253:
1175
+ raise UsageError("hostname is invalid")
1176
+
1177
+ return True
1178
+
1179
+ @staticmethod
1180
+ def _process_disable_service(value: Union[str, bool]) -> bool:
1181
+ value = _str_as_bool(value)
1182
+ if value:
1183
+ wandb.termwarn(
1184
+ "Disabling the wandb service is deprecated as of version 0.18.0 and will be removed in future versions. ",
1185
+ repeat=False,
1186
+ )
1187
+ return value
1188
+
1189
+ @staticmethod
1190
+ def _validate__service_wait(value: float) -> bool:
1191
+ if value <= 0:
1192
+ raise UsageError("_service_wait must be a positive number")
1193
+ return True
1194
+
1195
+ @staticmethod
1196
+ def _validate__stats_sampling_interval(value: float) -> bool:
1197
+ if value < 0.1:
1198
+ raise UsageError("sampling interval must be >= 0.1 seconds")
1199
+ return True
1200
+
1201
+ @staticmethod
1202
+ def _validate__stats_sample_rate_seconds(value: float) -> bool:
1203
+ if value < 0.1:
1204
+ raise UsageError("_stats_sample_rate_seconds must be >= 0.1")
1205
+ return True
1206
+
1207
+ @staticmethod
1208
+ def _validate__stats_samples_to_average(value: int) -> bool:
1209
+ if value < 1 or value > 30:
1210
+ raise UsageError("_stats_samples_to_average must be between 1 and 30")
1211
+ return True
1212
+
1213
+ @staticmethod
1214
+ def _validate_job_source(value: str) -> bool:
1215
+ valid_sources = ["repo", "artifact", "image"]
1216
+ if value not in valid_sources:
1217
+ raise UsageError(
1218
+ f"Settings field `job_source`: {value!r} not in {valid_sources}"
1219
+ )
1220
+ return True
1221
+
1222
+ # other helper methods
1223
+ @staticmethod
1224
+ def _path_convert(*args: str) -> str:
1225
+ """Join path and apply os.path.expanduser to it."""
1226
+ return os.path.expanduser(os.path.join(*args))
1227
+
1228
+ def _convert_console(self, console: str) -> str:
1229
+ if console == "auto":
1230
+ if (
1231
+ self._jupyter
1232
+ or (self.start_method == "thread")
1233
+ or not self._disable_service
1234
+ or self._windows
1235
+ ):
1236
+ console = "wrap"
1237
+ else:
1238
+ console = "redirect"
1239
+ return console
1240
+
1241
+ def _get_colab_url(self) -> Optional[str]:
1242
+ if not self._colab:
1243
+ return None
1244
+ if self._jupyter_path and self._jupyter_path.startswith("fileId="):
1245
+ unescaped = unquote(self._jupyter_path)
1246
+ return "https://colab.research.google.com/notebook#" + unescaped
1247
+ return None
1248
+
1249
+ def _get_program(self, program: Optional[str]) -> Optional[str]:
1250
+ if program is not None and program != "<python with no main file>":
1251
+ return program
1252
+
1253
+ if not self._jupyter:
1254
+ return program
1255
+
1256
+ if self.notebook_name:
1257
+ return self.notebook_name
1258
+
1259
+ if not self._jupyter_path:
1260
+ return program
1261
+
1262
+ if self._jupyter_path.startswith("fileId="):
1263
+ return self._jupyter_name
1264
+ else:
1265
+ return self._jupyter_path
1266
+
1267
+ def _get_url_query_string(self) -> str:
1268
+ # TODO(settings) use `wandb_setting` (if self.anonymous != "true":)
1269
+ if Api().settings().get("anonymous") != "true":
1270
+ return ""
1271
+
1272
+ api_key = apikey.api_key(settings=self)
1273
+
1274
+ return f"?{urlencode({'apiKey': api_key})}"
1275
+
1276
+ def _project_url_base(self) -> str:
1277
+ if not all([self.entity, self.project]):
1278
+ return ""
1279
+
1280
+ app_url = wandb.util.app_url(self.base_url)
1281
+ return f"{app_url}/{quote(self.entity)}/{quote(self.project)}"
1282
+
1283
+ def _project_url(self) -> str:
1284
+ project_url = self._project_url_base()
1285
+ if not project_url:
1286
+ return ""
1287
+
1288
+ query = self._get_url_query_string()
1289
+
1290
+ return f"{project_url}{query}"
1291
+
1292
+ def _run_url(self) -> str:
1293
+ """Return the run url."""
1294
+ project_url = self._project_url_base()
1295
+ if not all([project_url, self.run_id]):
1296
+ return ""
1297
+
1298
+ query = self._get_url_query_string()
1299
+ return f"{project_url}/runs/{quote(self.run_id)}{query}"
1300
+
1301
+ def _set_run_start_time(self, source: int = Source.BASE) -> None:
1302
+ """Set the time stamps for the settings.
1303
+
1304
+ Called once the run is initialized.
1305
+ """
1306
+ time_stamp: float = time.time()
1307
+ datetime_now: datetime = datetime.fromtimestamp(time_stamp)
1308
+ datetime_now_str = _datetime_as_str(datetime_now)
1309
+ object.__setattr__(self, "_Settings_start_datetime", datetime_now_str)
1310
+ object.__setattr__(self, "_Settings_start_time", time_stamp)
1311
+ self.update(
1312
+ _start_datetime=datetime_now_str,
1313
+ _start_time=time_stamp,
1314
+ source=source,
1315
+ )
1316
+
1317
+ def _sweep_url(self) -> str:
1318
+ """Return the sweep url."""
1319
+ project_url = self._project_url_base()
1320
+ if not all([project_url, self.sweep_id]):
1321
+ return ""
1322
+
1323
+ query = self._get_url_query_string()
1324
+ return f"{project_url}/sweeps/{quote(self.sweep_id)}{query}"
1325
+
1326
+ def __init__(self, **kwargs: Any) -> None:
1327
+ self.__frozen: bool = False
1328
+ self.__initialized: bool = False
1329
+
1330
+ self.__modification_order = SETTINGS_TOPOLOGICALLY_SORTED
1331
+
1332
+ # Set default settings values
1333
+ # We start off with the class attributes and `default_props` dicts
1334
+ # and then create Property objects.
1335
+ # Once initialized, attributes are to only be updated using the `update` method
1336
+ default_props = self._default_props()
1337
+
1338
+ # Init instance attributes as Property objects.
1339
+ # Type hints of class attributes are used to generate a type validator function
1340
+ # for runtime checks for each attribute.
1341
+ # These are defaults, using Source.BASE for non-policy attributes and Source.RUN for policies.
1342
+ for prop, type_hint in get_type_hints(SettingsData).items():
1343
+ validators = [self._validator_factory(type_hint)]
1344
+
1345
+ if prop in default_props:
1346
+ validator = default_props[prop].pop("validator", [])
1347
+ # Property validator could be either Callable or Sequence[Callable]
1348
+ if callable(validator):
1349
+ validators.append(validator)
1350
+ elif isinstance(validator, Sequence):
1351
+ validators.extend(list(validator))
1352
+ object.__setattr__(
1353
+ self,
1354
+ prop,
1355
+ Property(
1356
+ name=prop,
1357
+ **default_props[prop],
1358
+ validator=validators,
1359
+ # todo: double-check this logic:
1360
+ source=Source.RUN
1361
+ if default_props[prop].get("is_policy", False)
1362
+ else Source.BASE,
1363
+ ),
1364
+ )
1365
+ else:
1366
+ object.__setattr__(
1367
+ self,
1368
+ prop,
1369
+ Property(
1370
+ name=prop,
1371
+ validator=validators,
1372
+ source=Source.BASE,
1373
+ ),
1374
+ )
1375
+
1376
+ # update overridden defaults from kwargs
1377
+ unexpected_arguments = [k for k in kwargs.keys() if k not in self.__dict__]
1378
+ # allow only explicitly defined arguments
1379
+ if unexpected_arguments:
1380
+ raise SettingsUnexpectedArgsError(
1381
+ f"Got unexpected arguments: {unexpected_arguments}. "
1382
+ )
1383
+
1384
+ # automatically inspect setting validators and runtime hooks and topologically sort them
1385
+ # so that we can safely update them. throw error if there are cycles.
1386
+ for prop in self.__modification_order:
1387
+ if prop in kwargs:
1388
+ source = Source.RUN if self.__dict__[prop].is_policy else Source.BASE
1389
+ self.update({prop: kwargs[prop]}, source=source)
1390
+ kwargs.pop(prop)
1391
+
1392
+ for k, v in kwargs.items():
1393
+ # todo: double-check this logic:
1394
+ source = Source.RUN if self.__dict__[k].is_policy else Source.BASE
1395
+ self.update({k: v}, source=source)
1396
+
1397
+ # setup private attributes
1398
+ object.__setattr__(self, "_Settings_start_datetime", None)
1399
+ object.__setattr__(self, "_Settings_start_time", None)
1400
+
1401
+ # done with init, use self.update() to update attributes from now on
1402
+ self.__initialized = True
1403
+
1404
+ # todo? freeze settings to prevent accidental changes
1405
+ # self.freeze()
1406
+
1407
+ def __str__(self) -> str:
1408
+ # get attributes that are instances of the Property class:
1409
+ representation = {
1410
+ k: v.value for k, v in self.__dict__.items() if isinstance(v, Property)
1411
+ }
1412
+ return f"<Settings {_redact_dict(representation)}>"
1413
+
1414
+ def __repr__(self) -> str:
1415
+ # private attributes
1416
+ private = {k: v for k, v in self.__dict__.items() if k.startswith("_Settings")}
1417
+ # get attributes that are instances of the Property class:
1418
+ attributes = {
1419
+ k: f"<Property value={v.value} source={v.source}>"
1420
+ for k, v in self.__dict__.items()
1421
+ if isinstance(v, Property)
1422
+ }
1423
+ representation = {**private, **attributes}
1424
+ return f"<Settings {representation}>"
1425
+
1426
+ def __copy__(self) -> "Settings":
1427
+ """Ensure that a copy of the settings object is a truly deep copy.
1428
+
1429
+ Note that the copied object will not be frozen todo? why is this needed?
1430
+ """
1431
+ # get attributes that are instances of the Property class:
1432
+ attributes = {k: v for k, v in self.__dict__.items() if isinstance(v, Property)}
1433
+ new = Settings()
1434
+ # update properties that have deps or are dependent on in the topologically-sorted order
1435
+ for prop in self.__modification_order:
1436
+ new.update({prop: attributes[prop]._value}, source=attributes[prop].source)
1437
+ attributes.pop(prop)
1438
+
1439
+ # update the remaining attributes
1440
+ for k, v in attributes.items():
1441
+ # make sure to use the raw property value (v._value),
1442
+ # not the potential result of runtime hooks applied to it (v.value)
1443
+ new.update({k: v._value}, source=v.source)
1444
+ new.unfreeze()
1445
+
1446
+ return new
1447
+
1448
+ def __deepcopy__(self, memo: dict) -> "Settings":
1449
+ return self.__copy__()
1450
+
1451
+ # attribute access methods
1452
+ @no_type_check # this is a hack to make mypy happy
1453
+ def __getattribute__(self, name: str) -> Any:
1454
+ """Expose `attribute.value` if `attribute` is a Property."""
1455
+ item = object.__getattribute__(self, name)
1456
+ if isinstance(item, Property):
1457
+ return item.value
1458
+ return item
1459
+
1460
+ def __setattr__(self, key: str, value: Any) -> None:
1461
+ if "_Settings__initialized" in self.__dict__ and self.__initialized:
1462
+ raise TypeError(f"Please use update() to update attribute `{key}` value")
1463
+ object.__setattr__(self, key, value)
1464
+
1465
+ def __iter__(self) -> Iterable:
1466
+ return iter(self.to_dict())
1467
+
1468
+ def copy(self) -> "Settings":
1469
+ return self.__copy__()
1470
+
1471
+ # implement the Mapping interface
1472
+ def keys(self) -> Iterable[str]:
1473
+ return self.to_dict().keys()
1474
+
1475
+ @no_type_check # this is a hack to make mypy happy
1476
+ def __getitem__(self, name: str) -> Any:
1477
+ """Expose attribute.value if attribute is a Property."""
1478
+ item = object.__getattribute__(self, name)
1479
+ if isinstance(item, Property):
1480
+ return item.value
1481
+ return item
1482
+
1483
+ def update(
1484
+ self,
1485
+ settings: Optional[Union[Dict[str, Any], "Settings"]] = None,
1486
+ source: int = Source.OVERRIDE,
1487
+ **kwargs: Any,
1488
+ ) -> None:
1489
+ """Update individual settings."""
1490
+ if "_Settings__frozen" in self.__dict__ and self.__frozen:
1491
+ raise TypeError("Settings object is frozen")
1492
+
1493
+ if isinstance(settings, Settings):
1494
+ # If a Settings object is passed, detect the settings that differ
1495
+ # from defaults, collect them into a dict, and apply them using `source`.
1496
+ # This comes up in `wandb.init(settings=wandb.Settings(...))` and
1497
+ # seems like the behavior that the user would expect when calling init that way.
1498
+ defaults = Settings()
1499
+ settings_dict = dict()
1500
+ for k, v in settings.__dict__.items():
1501
+ if isinstance(v, Property):
1502
+ if v._value != defaults.__dict__[k]._value:
1503
+ settings_dict[k] = v._value
1504
+ # replace with the generated dict
1505
+ settings = settings_dict
1506
+
1507
+ # add kwargs to settings
1508
+ settings = settings or dict()
1509
+ # explicit kwargs take precedence over settings
1510
+ settings = {**settings, **kwargs}
1511
+ unknown_properties = []
1512
+ for key in settings.keys():
1513
+ # only allow updating known Properties
1514
+ if key not in self.__dict__ or not isinstance(self.__dict__[key], Property):
1515
+ unknown_properties.append(key)
1516
+ if unknown_properties:
1517
+ raise KeyError(f"Unknown settings: {unknown_properties}")
1518
+ # only if all keys are valid, update them
1519
+
1520
+ # store settings to be updated in a dict to preserve stats on preprocessing and validation errors
1521
+ settings.copy()
1522
+
1523
+ # update properties that have deps or are dependent on in the topologically-sorted order
1524
+ for key in self.__modification_order:
1525
+ if key in settings:
1526
+ self.__dict__[key].update(settings.pop(key), source=source)
1527
+
1528
+ # update the remaining properties
1529
+ for key, value in settings.items():
1530
+ self.__dict__[key].update(value, source)
1531
+
1532
+ def items(self) -> ItemsView[str, Any]:
1533
+ return self.to_dict().items()
1534
+
1535
+ def get(self, key: str, default: Optional[Any] = None) -> Any:
1536
+ return self.to_dict().get(key, default)
1537
+
1538
+ def freeze(self) -> None:
1539
+ object.__setattr__(self, "_Settings__frozen", True)
1540
+
1541
+ def unfreeze(self) -> None:
1542
+ object.__setattr__(self, "_Settings__frozen", False)
1543
+
1544
+ def is_frozen(self) -> bool:
1545
+ return self.__frozen
1546
+
1547
+ def to_dict(self) -> Dict[str, Any]:
1548
+ """Return a dict representation of the settings."""
1549
+ # get attributes that are instances of the Property class:
1550
+ attributes = {
1551
+ k: v.value for k, v in self.__dict__.items() if isinstance(v, Property)
1552
+ }
1553
+ return attributes
1554
+
1555
+ def to_proto(self) -> wandb_settings_pb2.Settings:
1556
+ """Generate a protobuf representation of the settings."""
1557
+ from dataclasses import fields
1558
+
1559
+ settings = wandb_settings_pb2.Settings()
1560
+ for field in fields(SettingsData):
1561
+ k = field.name
1562
+ v = getattr(self, k)
1563
+ # special case for _stats_open_metrics_filters
1564
+ if k == "_stats_open_metrics_filters":
1565
+ if isinstance(v, (list, set, tuple)):
1566
+ setting = getattr(settings, k)
1567
+ setting.sequence.value.extend(v)
1568
+ elif isinstance(v, dict):
1569
+ setting = getattr(settings, k)
1570
+ for key, value in v.items():
1571
+ for kk, vv in value.items():
1572
+ setting.mapping.value[key].value[kk] = vv
1573
+ else:
1574
+ raise TypeError(f"Unsupported type {type(v)} for setting {k}")
1575
+ continue
1576
+
1577
+ if isinstance(v, bool):
1578
+ getattr(settings, k).CopyFrom(BoolValue(value=v))
1579
+ elif isinstance(v, int):
1580
+ getattr(settings, k).CopyFrom(Int32Value(value=v))
1581
+ elif isinstance(v, float):
1582
+ getattr(settings, k).CopyFrom(DoubleValue(value=v))
1583
+ elif isinstance(v, str):
1584
+ getattr(settings, k).CopyFrom(StringValue(value=v))
1585
+ elif isinstance(v, (list, set, tuple)):
1586
+ # we only support sequences of strings for now
1587
+ sequence = getattr(settings, k)
1588
+ sequence.value.extend(v)
1589
+ elif isinstance(v, dict):
1590
+ mapping = getattr(settings, k)
1591
+ for key, value in v.items():
1592
+ # we only support dicts with string values for now
1593
+ mapping.value[key] = value
1594
+ elif isinstance(v, RunMoment):
1595
+ getattr(settings, k).CopyFrom(
1596
+ wandb_settings_pb2.RunMoment(
1597
+ run=v.run,
1598
+ value=v.value,
1599
+ metric=v.metric,
1600
+ )
1601
+ )
1602
+ elif v is None:
1603
+ # None is the default value for all settings, so we don't need to set it,
1604
+ # i.e. None means that the value was not set.
1605
+ pass
1606
+ else:
1607
+ raise TypeError(f"Unsupported type {type(v)} for setting {k}")
1608
+ # TODO: store property sources in the protobuf so that we can reconstruct the
1609
+ # settings object from the protobuf
1610
+ return settings
1611
+
1612
+ # apply settings from different sources
1613
+ # TODO(dd): think about doing some|all of that at init
1614
+ def _apply_settings(
1615
+ self,
1616
+ settings: "Settings",
1617
+ _logger: Optional[_EarlyLogger] = None,
1618
+ ) -> None:
1619
+ """Apply settings from a Settings object."""
1620
+ if _logger is not None:
1621
+ _logger.info(f"Applying settings from {settings}")
1622
+ attributes = {
1623
+ k: v for k, v in settings.__dict__.items() if isinstance(v, Property)
1624
+ }
1625
+ # update properties that have deps or are dependent on in the topologically-sorted order
1626
+ for prop in self.__modification_order:
1627
+ self.update({prop: attributes[prop]._value}, source=attributes[prop].source)
1628
+ attributes.pop(prop)
1629
+ # update the remaining properties
1630
+ for k, v in attributes.items():
1631
+ # note that only the same/higher priority settings are propagated
1632
+ self.update({k: v._value}, source=v.source)
1633
+
1634
+ @staticmethod
1635
+ def _load_config_file(file_name: str, section: str = "default") -> dict:
1636
+ parser = configparser.ConfigParser()
1637
+ parser.add_section(section)
1638
+ parser.read(file_name)
1639
+ config: Dict[str, Any] = dict()
1640
+ for k in parser[section]:
1641
+ config[k] = parser[section][k]
1642
+ # TODO (cvp): we didn't do this in the old cli, but it seems necessary
1643
+ if k == "ignore_globs":
1644
+ config[k] = config[k].split(",")
1645
+ return config
1646
+
1647
+ def _apply_base(self, pid: int, _logger: Optional[_EarlyLogger] = None) -> None:
1648
+ if _logger is not None:
1649
+ _logger.info(f"Current SDK version is {wandb.__version__}")
1650
+ _logger.info(f"Configure stats pid to {pid}")
1651
+ self.update({"_stats_pid": pid}, source=Source.SETUP)
1652
+
1653
+ def _apply_config_files(self, _logger: Optional[_EarlyLogger] = None) -> None:
1654
+ # TODO(jhr): permit setting of config in system and workspace
1655
+ if self.settings_system is not None:
1656
+ if _logger is not None:
1657
+ _logger.info(f"Loading settings from {self.settings_system}")
1658
+ self.update(
1659
+ self._load_config_file(self.settings_system),
1660
+ source=Source.SYSTEM,
1661
+ )
1662
+ if self.settings_workspace is not None:
1663
+ if _logger is not None:
1664
+ _logger.info(f"Loading settings from {self.settings_workspace}")
1665
+ self.update(
1666
+ self._load_config_file(self.settings_workspace),
1667
+ source=Source.WORKSPACE,
1668
+ )
1669
+
1670
+ def _apply_env_vars(
1671
+ self,
1672
+ environ: Mapping[str, Any],
1673
+ _logger: Optional[_EarlyLogger] = None,
1674
+ ) -> None:
1675
+ env_prefix: str = "WANDB_"
1676
+ special_env_var_names = {
1677
+ "WANDB_TRACELOG": "_tracelog",
1678
+ "WANDB_DISABLE_SERVICE": "_disable_service",
1679
+ "WANDB_SERVICE_TRANSPORT": "_service_transport",
1680
+ "WANDB_DIR": "root_dir",
1681
+ "WANDB_NAME": "run_name",
1682
+ "WANDB_NOTES": "run_notes",
1683
+ "WANDB_TAGS": "run_tags",
1684
+ "WANDB_JOB_TYPE": "run_job_type",
1685
+ "WANDB_HTTP_TIMEOUT": "_graphql_timeout_seconds",
1686
+ "WANDB_FILE_PUSHER_TIMEOUT": "_file_transfer_timeout_seconds",
1687
+ "WANDB_USER_EMAIL": "email",
1688
+ }
1689
+ env = dict()
1690
+ for setting, value in environ.items():
1691
+ if not setting.startswith(env_prefix):
1692
+ continue
1693
+
1694
+ if setting in special_env_var_names:
1695
+ key = special_env_var_names[setting]
1696
+ else:
1697
+ # otherwise, strip the prefix and convert to lowercase
1698
+ key = setting[len(env_prefix) :].lower()
1699
+
1700
+ if key in self.__dict__:
1701
+ if key in ("ignore_globs", "run_tags"):
1702
+ value = value.split(",")
1703
+ env[key] = value
1704
+ elif _logger is not None:
1705
+ _logger.warning(f"Unknown environment variable: {setting}")
1706
+
1707
+ if _logger is not None:
1708
+ _logger.info(
1709
+ f"Loading settings from environment variables: {_redact_dict(env)}"
1710
+ )
1711
+ self.update(env, source=Source.ENV)
1712
+
1713
+ def _infer_settings_from_environment(
1714
+ self, _logger: Optional[_EarlyLogger] = None
1715
+ ) -> None:
1716
+ """Modify settings based on environment (for runs and cli)."""
1717
+ settings: Dict[str, Union[bool, str, Sequence, None]] = dict()
1718
+ # disable symlinks if on windows (requires admin or developer setup)
1719
+ settings["symlink"] = True
1720
+ if self._windows:
1721
+ settings["symlink"] = False
1722
+
1723
+ # TODO(jhr): this needs to be moved last in setting up settings ?
1724
+ # (dd): loading order does not matter as long as source is set correctly
1725
+
1726
+ # For code saving, only allow env var override if value from server is true, or
1727
+ # if no preference was specified.
1728
+ if (self.save_code is True or self.save_code is None) and (
1729
+ os.getenv(wandb.env.SAVE_CODE) is not None
1730
+ or os.getenv(wandb.env.DISABLE_CODE) is not None
1731
+ ):
1732
+ settings["save_code"] = wandb.env.should_save_code()
1733
+
1734
+ settings["disable_git"] = wandb.env.disable_git()
1735
+
1736
+ # Attempt to get notebook information if not already set by the user
1737
+ if self._jupyter and (self.notebook_name is None or self.notebook_name == ""):
1738
+ meta = wandb.jupyter.notebook_metadata(self.silent) # type: ignore
1739
+ settings["_jupyter_path"] = meta.get("path")
1740
+ settings["_jupyter_name"] = meta.get("name")
1741
+ settings["_jupyter_root"] = meta.get("root")
1742
+ elif (
1743
+ self._jupyter
1744
+ and self.notebook_name is not None
1745
+ and os.path.exists(self.notebook_name)
1746
+ ):
1747
+ settings["_jupyter_path"] = self.notebook_name
1748
+ settings["_jupyter_name"] = self.notebook_name
1749
+ settings["_jupyter_root"] = os.getcwd()
1750
+ elif self._jupyter:
1751
+ wandb.termwarn(
1752
+ "WANDB_NOTEBOOK_NAME should be a path to a notebook file, "
1753
+ f"couldn't find {self.notebook_name}.",
1754
+ )
1755
+
1756
+ # host and username are populated by apply_env_vars if corresponding env
1757
+ # vars exist -- but if they don't, we'll fill them in here
1758
+ if self.host is None:
1759
+ settings["host"] = socket.gethostname() # type: ignore
1760
+
1761
+ if self.username is None:
1762
+ try: # type: ignore
1763
+ settings["username"] = getpass.getuser()
1764
+ except KeyError:
1765
+ # getuser() could raise KeyError in restricted environments like
1766
+ # chroot jails or docker containers. Return user id in these cases.
1767
+ settings["username"] = str(os.getuid())
1768
+
1769
+ _executable = (
1770
+ self._executable
1771
+ or os.environ.get(wandb.env._EXECUTABLE)
1772
+ or sys.executable
1773
+ or shutil.which("python3")
1774
+ or "python3"
1775
+ )
1776
+ settings["_executable"] = _executable
1777
+
1778
+ settings["docker"] = wandb.env.get_docker(wandb.util.image_id_from_k8s())
1779
+
1780
+ # TODO: we should use the cuda library to collect this
1781
+ if os.path.exists("/usr/local/cuda/version.txt"):
1782
+ with open("/usr/local/cuda/version.txt") as f:
1783
+ settings["_cuda"] = f.read().split(" ")[-1].strip()
1784
+ if not self._jupyter:
1785
+ settings["_args"] = sys.argv[1:]
1786
+ settings["_os"] = platform.platform(aliased=True)
1787
+ settings["_python"] = platform.python_version()
1788
+
1789
+ if _logger is not None:
1790
+ _logger.info(
1791
+ f"Inferring settings from compute environment: {_redact_dict(settings)}"
1792
+ )
1793
+
1794
+ self.update(settings, source=Source.ENV)
1795
+
1796
+ def _infer_run_settings_from_environment(
1797
+ self,
1798
+ _logger: Optional[_EarlyLogger] = None,
1799
+ ) -> None:
1800
+ """Modify settings based on environment (for runs only)."""
1801
+ # If there's not already a program file, infer it now.
1802
+ settings: Dict[str, Union[bool, str, None]] = dict()
1803
+ program = self.program or _get_program()
1804
+ if program is not None:
1805
+ repo = GitRepo()
1806
+ root = repo.root or os.getcwd()
1807
+
1808
+ program_relpath = self.program_relpath or _get_program_relpath(
1809
+ program, repo.root, _logger=_logger
1810
+ )
1811
+ settings["program_relpath"] = program_relpath
1812
+ program_abspath = os.path.abspath(
1813
+ os.path.join(root, os.path.relpath(os.getcwd(), root), program)
1814
+ )
1815
+ if os.path.exists(program_abspath):
1816
+ settings["program_abspath"] = program_abspath
1817
+ else:
1818
+ program = "<python with no main file>"
1819
+
1820
+ settings["program"] = program
1821
+
1822
+ if _logger is not None:
1823
+ _logger.info(
1824
+ f"Inferring run settings from compute environment: {_redact_dict(settings)}"
1825
+ )
1826
+
1827
+ self.update(settings, source=Source.ENV)
1828
+
1829
+ def _apply_setup(
1830
+ self, setup_settings: Dict[str, Any], _logger: Optional[_EarlyLogger] = None
1831
+ ) -> None:
1832
+ if _logger:
1833
+ _logger.info(f"Applying setup settings: {_redact_dict(setup_settings)}")
1834
+ self.update(setup_settings, source=Source.SETUP)
1835
+
1836
+ def _apply_user(
1837
+ self, user_settings: Dict[str, Any], _logger: Optional[_EarlyLogger] = None
1838
+ ) -> None:
1839
+ if _logger:
1840
+ _logger.info(f"Applying user settings: {_redact_dict(user_settings)}")
1841
+ self.update(user_settings, source=Source.USER)
1842
+
1843
+ def _apply_init(self, init_settings: Dict[str, Union[str, int, None]]) -> None:
1844
+ # pop magic from init settings
1845
+ init_settings.pop("magic", None)
1846
+
1847
+ # prevent setting project, entity if in sweep
1848
+ # TODO(jhr): these should be locked elements in the future
1849
+ if self.sweep_id:
1850
+ for key in ("project", "entity", "id"):
1851
+ val = init_settings.pop(key, None)
1852
+ if val:
1853
+ wandb.termwarn(
1854
+ f"Ignored wandb.init() arg {key} when running a sweep."
1855
+ )
1856
+ if self.launch:
1857
+ if self.project is not None and init_settings.pop("project", None):
1858
+ wandb.termwarn(
1859
+ "Project is ignored when running from wandb launch context. "
1860
+ "Ignored wandb.init() arg project when running running from launch.",
1861
+ )
1862
+ for key in ("entity", "id"):
1863
+ # Init settings cannot override launch settings.
1864
+ if init_settings.pop(key, None):
1865
+ wandb.termwarn(
1866
+ "Project, entity and id are ignored when running from wandb launch context. "
1867
+ f"Ignored wandb.init() arg {key} when running running from launch.",
1868
+ )
1869
+
1870
+ # strip out items where value is None
1871
+ param_map = dict(
1872
+ name="run_name",
1873
+ id="run_id",
1874
+ tags="run_tags",
1875
+ group="run_group",
1876
+ job_type="run_job_type",
1877
+ notes="run_notes",
1878
+ dir="root_dir",
1879
+ sweep_id="sweep_id",
1880
+ )
1881
+ init_settings = {
1882
+ param_map.get(k, k): v for k, v in init_settings.items() if v is not None
1883
+ }
1884
+ # fun logic to convert the resume init arg
1885
+ if init_settings.get("resume"):
1886
+ if isinstance(init_settings["resume"], str):
1887
+ if init_settings["resume"] not in ("allow", "must", "never", "auto"):
1888
+ if init_settings.get("run_id") is None:
1889
+ # TODO: deprecate or don't support
1890
+ init_settings["run_id"] = init_settings["resume"]
1891
+ init_settings["resume"] = "allow"
1892
+ elif init_settings["resume"] is True:
1893
+ # todo: add deprecation warning, switch to literal strings for resume
1894
+ init_settings["resume"] = "auto"
1895
+
1896
+ # update settings
1897
+ self.update(init_settings, source=Source.INIT)
1898
+ self._handle_fork_logic()
1899
+ self._handle_rewind_logic()
1900
+ self._handle_resume_logic()
1901
+
1902
+ def _handle_fork_logic(self) -> None:
1903
+ if self.fork_from is None:
1904
+ return
1905
+
1906
+ if self.run_id is not None and (self.fork_from.run == self.run_id):
1907
+ raise ValueError(
1908
+ "Provided `run_id` is the same as the run to `fork_from`. "
1909
+ "Please provide a different `run_id` or remove the `run_id` argument. "
1910
+ "If you want to rewind the current run, please use `resume_from` instead."
1911
+ )
1912
+
1913
+ def _handle_rewind_logic(self) -> None:
1914
+ if self.resume_from is None:
1915
+ return
1916
+
1917
+ if self.run_id is not None and (self.resume_from.run != self.run_id):
1918
+ wandb.termwarn(
1919
+ "Both `run_id` and `resume_from` have been specified with different ids. "
1920
+ "`run_id` will be ignored."
1921
+ )
1922
+ self.update({"run_id": self.resume_from.run}, source=Source.INIT)
1923
+
1924
+ def _handle_resume_logic(self) -> None:
1925
+ # handle auto resume logic
1926
+ if self.resume == "auto":
1927
+ if os.path.exists(self.resume_fname):
1928
+ with open(self.resume_fname) as f:
1929
+ resume_run_id = json.load(f)["run_id"]
1930
+ if self.run_id is None:
1931
+ self.update({"run_id": resume_run_id}, source=Source.INIT) # type: ignore
1932
+ elif self.run_id != resume_run_id:
1933
+ wandb.termwarn(
1934
+ "Tried to auto resume run with "
1935
+ f"id {resume_run_id} but id {self.run_id} is set.",
1936
+ )
1937
+
1938
+ self.update({"run_id": self.run_id or generate_id()}, source=Source.INIT)
1939
+ # persist our run id in case of failure
1940
+ # check None for mypy
1941
+ if self.resume == "auto" and self.resume_fname is not None:
1942
+ filesystem.mkdir_exists_ok(self.wandb_dir)
1943
+ with open(self.resume_fname, "w") as f:
1944
+ f.write(json.dumps({"run_id": self.run_id}))
1945
+
1946
+ def _apply_login(
1947
+ self,
1948
+ login_settings: Dict[str, Any],
1949
+ _logger: Optional[_EarlyLogger] = None,
1950
+ ) -> None:
1951
+ key_map = {
1952
+ "key": "api_key",
1953
+ "host": "base_url",
1954
+ "timeout": "login_timeout",
1955
+ }
1956
+
1957
+ # Rename keys and keep only the non-None values.
1958
+ #
1959
+ # The input keys are parameters to wandb.login(), but we use different
1960
+ # names for some of them in Settings.
1961
+ login_settings = {
1962
+ key_map.get(key, key): value
1963
+ for key, value in login_settings.items()
1964
+ if value is not None
1965
+ }
1966
+
1967
+ if _logger:
1968
+ _logger.info(f"Applying login settings: {_redact_dict(login_settings)}")
1969
+
1970
+ self.update(
1971
+ login_settings,
1972
+ source=Source.LOGIN,
1973
+ )
1974
+
1975
+ def _apply_run_start(self, run_start_settings: Dict[str, Any]) -> None:
1976
+ # This dictionary maps from the "run message dict" to relevant fields in settings
1977
+ # Note: that config is missing
1978
+ param_map = {
1979
+ "run_id": "run_id",
1980
+ "entity": "entity",
1981
+ "project": "project",
1982
+ "run_group": "run_group",
1983
+ "job_type": "run_job_type",
1984
+ "display_name": "run_name",
1985
+ "notes": "run_notes",
1986
+ "tags": "run_tags",
1987
+ "sweep_id": "sweep_id",
1988
+ "host": "host",
1989
+ "resumed": "resumed",
1990
+ "git.remote_url": "git_remote_url",
1991
+ "git.commit": "git_commit",
1992
+ }
1993
+ run_settings = {
1994
+ name: reduce(lambda d, k: d.get(k, {}), attr.split("."), run_start_settings)
1995
+ for attr, name in param_map.items()
1996
+ }
1997
+ run_settings = {key: value for key, value in run_settings.items() if value}
1998
+ if run_settings:
1999
+ self.update(run_settings, source=Source.RUN)