wandb 0.16.6__py3-none-any.whl → 0.17.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. package_readme.md +95 -0
  2. wandb/__init__.py +2 -3
  3. wandb/agents/pyagent.py +0 -1
  4. wandb/analytics/sentry.py +2 -1
  5. wandb/apis/importers/internals/internal.py +0 -1
  6. wandb/apis/importers/internals/protocols.py +30 -56
  7. wandb/apis/importers/mlflow.py +13 -26
  8. wandb/apis/importers/wandb.py +8 -14
  9. wandb/apis/internal.py +0 -3
  10. wandb/apis/public/api.py +55 -3
  11. wandb/apis/public/artifacts.py +1 -0
  12. wandb/apis/public/files.py +1 -0
  13. wandb/apis/public/history.py +1 -0
  14. wandb/apis/public/jobs.py +17 -4
  15. wandb/apis/public/projects.py +1 -0
  16. wandb/apis/public/reports.py +1 -0
  17. wandb/apis/public/runs.py +15 -17
  18. wandb/apis/public/sweeps.py +1 -0
  19. wandb/apis/public/teams.py +1 -0
  20. wandb/apis/public/users.py +1 -0
  21. wandb/apis/reports/v1/_blocks.py +3 -7
  22. wandb/apis/reports/v2/gql.py +1 -0
  23. wandb/apis/reports/v2/interface.py +3 -4
  24. wandb/apis/reports/v2/internal.py +5 -8
  25. wandb/cli/cli.py +92 -22
  26. wandb/data_types.py +9 -6
  27. wandb/docker/__init__.py +1 -1
  28. wandb/env.py +38 -8
  29. wandb/errors/__init__.py +5 -0
  30. wandb/errors/term.py +10 -2
  31. wandb/filesync/step_checksum.py +1 -4
  32. wandb/filesync/step_prepare.py +4 -24
  33. wandb/filesync/step_upload.py +4 -106
  34. wandb/filesync/upload_job.py +0 -76
  35. wandb/integration/catboost/catboost.py +1 -1
  36. wandb/integration/fastai/__init__.py +1 -0
  37. wandb/integration/huggingface/resolver.py +2 -2
  38. wandb/integration/keras/__init__.py +1 -0
  39. wandb/integration/keras/callbacks/metrics_logger.py +1 -1
  40. wandb/integration/keras/keras.py +7 -7
  41. wandb/integration/langchain/wandb_tracer.py +1 -0
  42. wandb/integration/lightning/fabric/logger.py +1 -3
  43. wandb/integration/metaflow/metaflow.py +41 -6
  44. wandb/integration/openai/fine_tuning.py +3 -3
  45. wandb/integration/prodigy/prodigy.py +1 -1
  46. wandb/old/summary.py +1 -1
  47. wandb/plot/confusion_matrix.py +1 -1
  48. wandb/plot/pr_curve.py +2 -1
  49. wandb/plot/roc_curve.py +2 -1
  50. wandb/{plots → plot}/utils.py +13 -25
  51. wandb/proto/v3/wandb_internal_pb2.py +364 -332
  52. wandb/proto/v3/wandb_settings_pb2.py +2 -2
  53. wandb/proto/v3/wandb_telemetry_pb2.py +10 -10
  54. wandb/proto/v4/wandb_internal_pb2.py +322 -316
  55. wandb/proto/v4/wandb_settings_pb2.py +2 -2
  56. wandb/proto/v4/wandb_telemetry_pb2.py +10 -10
  57. wandb/proto/wandb_deprecated.py +7 -1
  58. wandb/proto/wandb_internal_codegen.py +3 -29
  59. wandb/sdk/artifacts/artifact.py +26 -11
  60. wandb/sdk/artifacts/artifact_download_logger.py +1 -0
  61. wandb/sdk/artifacts/artifact_file_cache.py +18 -4
  62. wandb/sdk/artifacts/artifact_instance_cache.py +1 -0
  63. wandb/sdk/artifacts/artifact_manifest.py +1 -0
  64. wandb/sdk/artifacts/artifact_manifest_entry.py +7 -3
  65. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +1 -0
  66. wandb/sdk/artifacts/artifact_saver.py +2 -8
  67. wandb/sdk/artifacts/artifact_state.py +1 -0
  68. wandb/sdk/artifacts/artifact_ttl.py +1 -0
  69. wandb/sdk/artifacts/exceptions.py +1 -0
  70. wandb/sdk/artifacts/storage_handlers/azure_handler.py +1 -0
  71. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +13 -18
  72. wandb/sdk/artifacts/storage_handlers/http_handler.py +1 -0
  73. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +1 -0
  74. wandb/sdk/artifacts/storage_handlers/multi_handler.py +1 -0
  75. wandb/sdk/artifacts/storage_handlers/s3_handler.py +5 -3
  76. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +1 -0
  77. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +1 -0
  78. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +1 -0
  79. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +3 -42
  80. wandb/sdk/artifacts/storage_policy.py +2 -12
  81. wandb/sdk/data_types/_dtypes.py +8 -8
  82. wandb/sdk/data_types/base_types/media.py +3 -6
  83. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +3 -1
  84. wandb/sdk/data_types/image.py +1 -1
  85. wandb/sdk/data_types/video.py +1 -1
  86. wandb/sdk/integration_utils/auto_logging.py +5 -6
  87. wandb/sdk/integration_utils/data_logging.py +10 -6
  88. wandb/sdk/interface/interface.py +68 -32
  89. wandb/sdk/interface/interface_shared.py +7 -13
  90. wandb/sdk/internal/datastore.py +1 -1
  91. wandb/sdk/internal/file_pusher.py +2 -5
  92. wandb/sdk/internal/file_stream.py +5 -18
  93. wandb/sdk/internal/handler.py +18 -2
  94. wandb/sdk/internal/internal.py +0 -1
  95. wandb/sdk/internal/internal_api.py +1 -129
  96. wandb/sdk/internal/internal_util.py +0 -1
  97. wandb/sdk/internal/job_builder.py +159 -45
  98. wandb/sdk/internal/profiler.py +1 -0
  99. wandb/sdk/internal/progress.py +0 -28
  100. wandb/sdk/internal/run.py +1 -0
  101. wandb/sdk/internal/sender.py +1 -2
  102. wandb/sdk/internal/system/assets/gpu_amd.py +44 -44
  103. wandb/sdk/internal/system/assets/gpu_apple.py +56 -11
  104. wandb/sdk/internal/system/assets/interfaces.py +6 -8
  105. wandb/sdk/internal/system/assets/open_metrics.py +2 -2
  106. wandb/sdk/internal/system/assets/trainium.py +1 -3
  107. wandb/sdk/launch/__init__.py +9 -1
  108. wandb/sdk/launch/_launch.py +4 -24
  109. wandb/sdk/launch/_launch_add.py +1 -3
  110. wandb/sdk/launch/_project_spec.py +186 -224
  111. wandb/sdk/launch/agent/agent.py +37 -13
  112. wandb/sdk/launch/agent/config.py +72 -14
  113. wandb/sdk/launch/builder/abstract.py +69 -1
  114. wandb/sdk/launch/builder/build.py +156 -555
  115. wandb/sdk/launch/builder/context_manager.py +235 -0
  116. wandb/sdk/launch/builder/docker_builder.py +8 -23
  117. wandb/sdk/launch/builder/kaniko_builder.py +12 -25
  118. wandb/sdk/launch/builder/noop.py +1 -0
  119. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  120. wandb/sdk/launch/create_job.py +47 -37
  121. wandb/sdk/launch/environment/abstract.py +1 -0
  122. wandb/sdk/launch/environment/gcp_environment.py +1 -0
  123. wandb/sdk/launch/environment/local_environment.py +1 -0
  124. wandb/sdk/launch/inputs/files.py +148 -0
  125. wandb/sdk/launch/inputs/internal.py +217 -0
  126. wandb/sdk/launch/inputs/manage.py +95 -0
  127. wandb/sdk/launch/loader.py +1 -0
  128. wandb/sdk/launch/registry/abstract.py +1 -0
  129. wandb/sdk/launch/registry/azure_container_registry.py +1 -0
  130. wandb/sdk/launch/registry/elastic_container_registry.py +1 -0
  131. wandb/sdk/launch/registry/google_artifact_registry.py +2 -1
  132. wandb/sdk/launch/registry/local_registry.py +1 -0
  133. wandb/sdk/launch/runner/abstract.py +1 -0
  134. wandb/sdk/launch/runner/kubernetes_monitor.py +1 -0
  135. wandb/sdk/launch/runner/kubernetes_runner.py +9 -10
  136. wandb/sdk/launch/runner/local_container.py +2 -3
  137. wandb/sdk/launch/runner/local_process.py +8 -29
  138. wandb/sdk/launch/runner/sagemaker_runner.py +21 -20
  139. wandb/sdk/launch/runner/vertex_runner.py +8 -7
  140. wandb/sdk/launch/sweeps/scheduler.py +4 -3
  141. wandb/sdk/launch/sweeps/scheduler_sweep.py +2 -1
  142. wandb/sdk/launch/sweeps/utils.py +3 -3
  143. wandb/sdk/launch/utils.py +15 -140
  144. wandb/sdk/lib/_settings_toposort_generated.py +0 -5
  145. wandb/sdk/lib/fsm.py +8 -12
  146. wandb/sdk/lib/gitlib.py +4 -4
  147. wandb/sdk/lib/import_hooks.py +1 -1
  148. wandb/sdk/lib/lazyloader.py +0 -1
  149. wandb/sdk/lib/proto_util.py +23 -2
  150. wandb/sdk/lib/redirect.py +19 -14
  151. wandb/sdk/lib/retry.py +3 -2
  152. wandb/sdk/lib/tracelog.py +1 -1
  153. wandb/sdk/service/service.py +19 -16
  154. wandb/sdk/verify/verify.py +2 -1
  155. wandb/sdk/wandb_init.py +14 -55
  156. wandb/sdk/wandb_manager.py +2 -2
  157. wandb/sdk/wandb_require.py +5 -0
  158. wandb/sdk/wandb_run.py +114 -56
  159. wandb/sdk/wandb_settings.py +0 -48
  160. wandb/sdk/wandb_setup.py +1 -1
  161. wandb/sklearn/__init__.py +1 -0
  162. wandb/sklearn/plot/__init__.py +1 -0
  163. wandb/sklearn/plot/classifier.py +11 -12
  164. wandb/sklearn/plot/clusterer.py +2 -1
  165. wandb/sklearn/plot/regressor.py +1 -0
  166. wandb/sklearn/plot/shared.py +1 -0
  167. wandb/sklearn/utils.py +1 -0
  168. wandb/testing/relay.py +4 -4
  169. wandb/trigger.py +1 -0
  170. wandb/util.py +67 -54
  171. wandb/wandb_controller.py +2 -3
  172. wandb/wandb_torch.py +1 -2
  173. {wandb-0.16.6.dist-info → wandb-0.17.0.dist-info}/METADATA +67 -70
  174. {wandb-0.16.6.dist-info → wandb-0.17.0.dist-info}/RECORD +177 -187
  175. {wandb-0.16.6.dist-info → wandb-0.17.0.dist-info}/WHEEL +1 -2
  176. wandb/bin/apple_gpu_stats +0 -0
  177. wandb/catboost/__init__.py +0 -9
  178. wandb/fastai/__init__.py +0 -9
  179. wandb/keras/__init__.py +0 -18
  180. wandb/lightgbm/__init__.py +0 -9
  181. wandb/plots/__init__.py +0 -6
  182. wandb/plots/explain_text.py +0 -36
  183. wandb/plots/heatmap.py +0 -81
  184. wandb/plots/named_entity.py +0 -43
  185. wandb/plots/part_of_speech.py +0 -50
  186. wandb/plots/plot_definitions.py +0 -768
  187. wandb/plots/precision_recall.py +0 -121
  188. wandb/plots/roc.py +0 -103
  189. wandb/sacred/__init__.py +0 -3
  190. wandb/xgboost/__init__.py +0 -9
  191. wandb-0.16.6.dist-info/top_level.txt +0 -1
  192. {wandb-0.16.6.dist-info → wandb-0.17.0.dist-info}/entry_points.txt +0 -0
  193. {wandb-0.16.6.dist-info → wandb-0.17.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,5 +1,4 @@
1
1
  import ast
2
- import asyncio
3
2
  import base64
4
3
  import datetime
5
4
  import functools
@@ -49,7 +48,7 @@ from ..lib import retry
49
48
  from ..lib.filenames import DIFF_FNAME, METADATA_FNAME
50
49
  from ..lib.gitlib import GitRepo
51
50
  from . import context
52
- from .progress import AsyncProgress, Progress
51
+ from .progress import Progress
53
52
 
54
53
  logger = logging.getLogger(__name__)
55
54
 
@@ -121,13 +120,6 @@ if TYPE_CHECKING:
121
120
  SweepState = Literal["RUNNING", "PAUSED", "CANCELED", "FINISHED"]
122
121
  Number = Union[int, float]
123
122
 
124
- # This funny if/else construction is the simplest thing I've found that
125
- # works at runtime, satisfies Mypy, and gives autocomplete in VSCode:
126
- if TYPE_CHECKING:
127
- import httpx
128
- else:
129
- httpx = util.get_module("httpx")
130
-
131
123
  # class _MappingSupportsCopy(Protocol):
132
124
  # def copy(self) -> "_MappingSupportsCopy": ...
133
125
  # def keys(self) -> Iterable: ...
@@ -161,23 +153,6 @@ def check_httpclient_logger_handler() -> None:
161
153
  httpclient_logger.addHandler(root_logger.handlers[0])
162
154
 
163
155
 
164
- def check_httpx_exc_retriable(exc: Exception) -> bool:
165
- retriable_codes = (308, 408, 409, 429, 500, 502, 503, 504)
166
- return (
167
- isinstance(exc, (httpx.TimeoutException, httpx.NetworkError))
168
- or (
169
- isinstance(exc, httpx.HTTPStatusError)
170
- and exc.response.status_code in retriable_codes
171
- )
172
- or (
173
- isinstance(exc, httpx.HTTPStatusError)
174
- and exc.response.status_code == 400
175
- and "x-amz-meta-md5" in exc.request.headers
176
- and "RequestTimeout" in str(exc.response.content)
177
- )
178
- )
179
-
180
-
181
156
  class _ThreadLocalData(threading.local):
182
157
  context: Optional[context.Context]
183
158
 
@@ -286,10 +261,6 @@ class Api:
286
261
  )
287
262
  )
288
263
 
289
- # httpx is an optional dependency, so we lazily instantiate the client
290
- # only when we need it
291
- self._async_httpx_client: Optional[httpx.AsyncClient] = None
292
-
293
264
  self.retry_callback = retry_callback
294
265
  self._retry_gql = retry.Retry(
295
266
  self.execute,
@@ -2794,105 +2765,6 @@ class Api:
2794
2765
 
2795
2766
  return response
2796
2767
 
2797
- async def upload_file_async(
2798
- self,
2799
- url: str,
2800
- file: IO[bytes],
2801
- callback: Optional["ProgressFn"] = None,
2802
- extra_headers: Optional[Dict[str, str]] = None,
2803
- ) -> None:
2804
- """An async not-quite-equivalent version of `upload_file`.
2805
-
2806
- Differences from `upload_file`:
2807
- - This method doesn't implement Azure uploads. (The Azure SDK supports
2808
- async, but it's nontrivial to use it here.) If the upload looks like
2809
- it's destined for Azure, this method will delegate to the sync impl.
2810
- - Consequently, this method doesn't return the response object.
2811
- (Because it might fall back to the sync impl, it would sometimes
2812
- return a `requests.Response` and sometimes an `httpx.Response`.)
2813
- - This method doesn't wrap retryable errors in `TransientError`.
2814
- It leaves that determination to the caller.
2815
- """
2816
- check_httpclient_logger_handler()
2817
- must_delegate = False
2818
-
2819
- if httpx is None:
2820
- wandb.termwarn( # type: ignore[unreachable]
2821
- "async file-uploads require `pip install wandb[async]`; falling back to sync implementation",
2822
- repeat=False,
2823
- )
2824
- must_delegate = True
2825
-
2826
- if extra_headers is not None and "x-ms-blob-type" in extra_headers:
2827
- wandb.termwarn(
2828
- "async file-uploads don't support Azure; falling back to sync implementation",
2829
- repeat=False,
2830
- )
2831
- must_delegate = True
2832
-
2833
- if must_delegate:
2834
- await asyncio.get_event_loop().run_in_executor(
2835
- None,
2836
- lambda: self.upload_file_retry(
2837
- url=url,
2838
- file=file,
2839
- callback=callback,
2840
- extra_headers=extra_headers,
2841
- ),
2842
- )
2843
- return
2844
-
2845
- if self._async_httpx_client is None:
2846
- self._async_httpx_client = httpx.AsyncClient()
2847
-
2848
- progress = AsyncProgress(Progress(file, callback=callback))
2849
-
2850
- try:
2851
- response = await self._async_httpx_client.put(
2852
- url=url,
2853
- content=progress,
2854
- headers={
2855
- "Content-Length": str(len(progress)),
2856
- **(extra_headers if extra_headers is not None else {}),
2857
- },
2858
- )
2859
- response.raise_for_status()
2860
- except Exception as e:
2861
- progress.rewind()
2862
- logger.error(f"upload_file_async exception {url}: {e}")
2863
- if isinstance(e, httpx.RequestError):
2864
- logger.error(f"upload_file_async request headers: {e.request.headers}")
2865
- if isinstance(e, httpx.HTTPStatusError):
2866
- logger.error(f"upload_file_async response body: {e.response.content!r}")
2867
- raise
2868
-
2869
- async def upload_file_retry_async(
2870
- self,
2871
- url: str,
2872
- file: IO[bytes],
2873
- callback: Optional["ProgressFn"] = None,
2874
- extra_headers: Optional[Dict[str, str]] = None,
2875
- num_retries: int = 100,
2876
- ) -> None:
2877
- backoff = retry.FilteredBackoff(
2878
- filter=check_httpx_exc_retriable,
2879
- wrapped=retry.ExponentialBackoff(
2880
- initial_sleep=datetime.timedelta(seconds=1),
2881
- max_sleep=datetime.timedelta(seconds=60),
2882
- max_retries=num_retries,
2883
- timeout_at=datetime.datetime.now() + datetime.timedelta(days=7),
2884
- ),
2885
- )
2886
-
2887
- await retry.retry_async(
2888
- backoff=backoff,
2889
- fn=self.upload_file_async,
2890
- url=url,
2891
- file=file,
2892
- callback=callback,
2893
- extra_headers=extra_headers,
2894
- )
2895
-
2896
2768
  @normalize_exceptions
2897
2769
  def register_agent(
2898
2770
  self,
@@ -4,7 +4,6 @@ Collection of classes to support the internal process.
4
4
 
5
5
  """
6
6
 
7
-
8
7
  import logging
9
8
  import queue
10
9
  import sys
@@ -1,4 +1,5 @@
1
1
  """job builder."""
2
+
2
3
  import json
3
4
  import logging
4
5
  import os
@@ -31,6 +32,43 @@ JOB_ARTIFACT_TYPE = "job"
31
32
  LOG_LEVEL = Literal["log", "warn", "error"]
32
33
 
33
34
 
35
+ class Version:
36
+ def __init__(self, major: int, minor: int, patch: int):
37
+ self._major = major
38
+ self._minor = minor
39
+ self._patch = patch
40
+
41
+ def __repr__(self) -> str:
42
+ return f"{self._major}.{self._minor}.{self._patch}"
43
+
44
+ def __lt__(self, other: "Version") -> bool:
45
+ if self._major < other._major:
46
+ return True
47
+ elif self._major == other._major:
48
+ if self._minor < other._minor:
49
+ return True
50
+ elif self._minor == other._minor:
51
+ if self._patch < other._patch:
52
+ return True
53
+ return False
54
+
55
+ def __eq__(self, other: object) -> bool:
56
+ if not isinstance(other, Version):
57
+ return NotImplemented
58
+ return (
59
+ self._major == other._major
60
+ and self._minor == other._minor
61
+ and self._patch == other._patch
62
+ )
63
+
64
+
65
+ # Minimum supported wandb version for keys in the source dict of wandb-job.json
66
+ SOURCE_KEYS_MIN_SUPPORTED_VERSION = {
67
+ "dockerfile": Version(0, 17, 0),
68
+ "build_context": Version(0, 17, 0),
69
+ }
70
+
71
+
34
72
  class GitInfo(TypedDict):
35
73
  remote: str
36
74
  commit: str
@@ -40,12 +78,16 @@ class GitSourceDict(TypedDict):
40
78
  git: GitInfo
41
79
  entrypoint: List[str]
42
80
  notebook: bool
81
+ build_context: Optional[str]
82
+ dockerfile: Optional[str]
43
83
 
44
84
 
45
85
  class ArtifactSourceDict(TypedDict):
46
86
  artifact: str
47
87
  entrypoint: List[str]
48
88
  notebook: bool
89
+ build_context: Optional[str]
90
+ dockerfile: Optional[str]
49
91
 
50
92
 
51
93
  class ImageSourceDict(TypedDict):
@@ -72,6 +114,19 @@ class ArtifactInfoForJob(TypedDict):
72
114
  name: str
73
115
 
74
116
 
117
+ def get_min_supported_for_source_dict(
118
+ source: Union[GitSourceDict, ArtifactSourceDict, ImageSourceDict],
119
+ ) -> Optional[Version]:
120
+ """Get the minimum supported wandb version the source dict of wandb-job.json."""
121
+ min_seen = None
122
+ for key in source:
123
+ new_ver = SOURCE_KEYS_MIN_SUPPORTED_VERSION.get(key)
124
+ if new_ver:
125
+ if min_seen is None or new_ver < min_seen:
126
+ min_seen = new_ver
127
+ return min_seen
128
+
129
+
75
130
  class JobArtifact(Artifact):
76
131
  def __init__(self, name: str, *args: Any, **kwargs: Any):
77
132
  super().__init__(name, "placeholder", *args, **kwargs)
@@ -105,9 +160,9 @@ class JobBuilder:
105
160
  self._disable = settings.disable_job_creation
106
161
  self._partial_source = None
107
162
  self._aliases = []
108
- self._source_type: Optional[
109
- Literal["repo", "artifact", "image"]
110
- ] = settings.job_source # type: ignore[assignment]
163
+ self._source_type: Optional[Literal["repo", "artifact", "image"]] = (
164
+ settings.job_source # type: ignore[assignment]
165
+ )
111
166
  self._is_notebook_run = self._get_is_notebook_run()
112
167
  self._verbose = verbose
113
168
 
@@ -196,6 +251,8 @@ class JobBuilder:
196
251
  "git": {"remote": remote, "commit": commit},
197
252
  "entrypoint": entrypoint,
198
253
  "notebook": self._is_notebook_run,
254
+ "build_context": metadata.get("build_context"),
255
+ "dockerfile": metadata.get("dockerfile"),
199
256
  }
200
257
  name = self._make_job_name(f"{remote}_{program_relpath}")
201
258
 
@@ -246,6 +303,8 @@ class JobBuilder:
246
303
  "entrypoint": entrypoint,
247
304
  "notebook": self._is_notebook_run,
248
305
  "artifact": f"wandb-artifact://_id/{self._logged_code_artifact['id']}",
306
+ "build_context": metadata.get("build_context"),
307
+ "dockerfile": metadata.get("dockerfile"),
249
308
  }
250
309
  name = self._make_job_name(self._logged_code_artifact["name"])
251
310
 
@@ -275,7 +334,7 @@ class JobBuilder:
275
334
  return source, name
276
335
 
277
336
  def _make_job_name(self, input_str: str) -> str:
278
- """Use job name from settings if provided, else use programatic name."""
337
+ """Use job name from settings if provided, else use programmatic name."""
279
338
  if self._settings.job_name:
280
339
  return self._settings.job_name
281
340
 
@@ -292,17 +351,6 @@ class JobBuilder:
292
351
  if metadata.get("entrypoint"):
293
352
  entrypoint: List[str] = metadata["entrypoint"]
294
353
  return entrypoint
295
-
296
- # if entrypoint is not in metadata, then construct from python
297
- assert metadata.get("python")
298
-
299
- python = metadata["python"]
300
- if python.count(".") > 1:
301
- python = ".".join(python.split(".")[:2])
302
-
303
- entrypoint = [f"python{python}", program_relpath]
304
- return entrypoint
305
-
306
354
  # job is being built from a run
307
355
  entrypoint = [os.path.basename(sys.executable), program_relpath]
308
356
 
@@ -314,7 +362,73 @@ class JobBuilder:
314
362
  def _is_colab_run(self) -> bool:
315
363
  return hasattr(self._settings, "_colab") and bool(self._settings._colab)
316
364
 
317
- def build(self) -> Optional[Artifact]:
365
+ def _build_job_source(
366
+ self,
367
+ source_type: str,
368
+ program_relpath: Optional[str],
369
+ metadata: Dict[str, Any],
370
+ ) -> Tuple[
371
+ Union[GitSourceDict, ArtifactSourceDict, ImageSourceDict, None],
372
+ Optional[str],
373
+ ]:
374
+ """Construct a job source dict and name from the current run.
375
+
376
+ Arguments:
377
+ source_type (str): The type of source to build the job from. One of
378
+ "repo", "artifact", or "image".
379
+ """
380
+ source: Union[
381
+ GitSourceDict,
382
+ ArtifactSourceDict,
383
+ ImageSourceDict,
384
+ None,
385
+ ] = None
386
+
387
+ if source_type == "repo":
388
+ source, name = self._build_repo_job_source(
389
+ program_relpath or "",
390
+ metadata,
391
+ )
392
+ elif source_type == "artifact":
393
+ source, name = self._build_artifact_job_source(
394
+ program_relpath or "",
395
+ metadata,
396
+ )
397
+ elif source_type == "image" and self._has_image_job_ingredients(metadata):
398
+ source, name = self._build_image_job_source(metadata)
399
+ else:
400
+ source = None
401
+
402
+ if source is None:
403
+ if source_type:
404
+ self._log_if_verbose(
405
+ f"Source type is set to '{source_type}' but some required information is missing "
406
+ "from the environment. A job will not be created from this run. See "
407
+ "https://docs.wandb.ai/guides/launch/create-job",
408
+ "warn",
409
+ )
410
+ return None, None
411
+
412
+ return source, name
413
+
414
+ def build(
415
+ self,
416
+ build_context: Optional[str] = None,
417
+ dockerfile: Optional[str] = None,
418
+ ) -> Optional[Artifact]:
419
+ """Build a job artifact from the current run.
420
+
421
+ Arguments:
422
+ build_context (Optional[str]): Path within the job source code to
423
+ the image build context. Saved as part of the job for future
424
+ builds.
425
+ dockerfile (Optional[str]): Path within the build context the
426
+ Dockerfile. Saved as part of the job for future builds.
427
+
428
+ Returns:
429
+ Optional[Artifact]: The job artifact if it was successfully built,
430
+ otherwise None.
431
+ """
318
432
  _logger.info("Attempting to build job artifact")
319
433
  if not os.path.exists(
320
434
  os.path.join(self._settings.files_dir, REQUIREMENTS_FNAME)
@@ -331,6 +445,8 @@ class JobBuilder:
331
445
  "warn",
332
446
  )
333
447
  return None
448
+ metadata["dockerfile"] = dockerfile
449
+ metadata["build_context"] = build_context
334
450
 
335
451
  runtime: Optional[str] = metadata.get("python")
336
452
  # can't build a job without a python version
@@ -374,45 +490,39 @@ class JobBuilder:
374
490
  return None
375
491
 
376
492
  program_relpath = self._get_program_relpath(source_type, metadata)
377
- if source_type != "image" and not program_relpath:
493
+ if (
494
+ not metadata.get("_partial")
495
+ and source_type != "image"
496
+ and not program_relpath
497
+ ):
378
498
  self._log_if_verbose(
379
499
  "No program path found, not creating job artifact. See https://docs.wandb.ai/guides/launch/create-job",
380
500
  "warn",
381
501
  )
382
502
  return None
383
503
 
384
- source: Union[
385
- Optional[GitSourceDict],
386
- Optional[ArtifactSourceDict],
387
- Optional[ImageSourceDict],
388
- ] = None
389
-
390
- # make source dict
391
- if source_type == "repo":
392
- assert program_relpath
393
- source, name = self._build_repo_job_source(program_relpath, metadata)
394
- elif source_type == "artifact":
395
- assert program_relpath
396
- source, name = self._build_artifact_job_source(
397
- program_relpath, metadata
398
- )
399
- elif source_type == "image" and self._has_image_job_ingredients(metadata):
400
- source, name = self._build_image_job_source(metadata)
401
- else:
402
- source = None
403
-
504
+ source, name = self._build_job_source(
505
+ source_type,
506
+ program_relpath,
507
+ metadata,
508
+ )
404
509
  if source is None:
405
- if source_type:
406
- self._log_if_verbose(
407
- f"Source type is set to '{source_type}' but some required information is missing "
408
- "from the environment. A job will not be created from this run. See "
409
- "https://docs.wandb.ai/guides/launch/create-job",
410
- "warn",
411
- )
412
510
  return None
413
511
 
512
+ if build_context:
513
+ source["build_context"] = build_context # type: ignore[typeddict-item]
514
+ if dockerfile:
515
+ source["dockerfile"] = dockerfile # type: ignore[typeddict-item]
516
+
517
+ # Pop any keys that are initialized to None. The current TypedDict
518
+ # system for source dicts requires all keys to be present, but we
519
+ # don't want to include keys that are None in the final dict.
520
+ for key in list(source.keys()):
521
+ if source[key] is None: # type: ignore[literal-required]
522
+ source.pop(key) # type: ignore[literal-require,misc]
523
+
414
524
  source_info = {
415
- "_version": "v0",
525
+ "_version": str(get_min_supported_for_source_dict(source) or "v0"),
416
526
  "source_type": source_type,
417
527
  "source": source,
418
528
  "input_types": input_types,
@@ -530,6 +640,8 @@ def convert_use_artifact_to_job_source(
530
640
  },
531
641
  "entrypoint": entrypoint,
532
642
  "notebook": source_info.source.git.notebook,
643
+ "build_context": None,
644
+ "dockerfile": None,
533
645
  }
534
646
  source_info_dict.update({"source": git_source})
535
647
  elif source_info.source_type == "artifact":
@@ -538,6 +650,8 @@ def convert_use_artifact_to_job_source(
538
650
  "artifact": source_info.source.artifact.artifact,
539
651
  "entrypoint": entrypoint,
540
652
  "notebook": source_info.source.artifact.notebook,
653
+ "build_context": None,
654
+ "dockerfile": None,
541
655
  }
542
656
  source_info_dict.update({"source": artifact_source})
543
657
  elif source_info.source_type == "image":
@@ -1,4 +1,5 @@
1
1
  """Integration with pytorch profiler."""
2
+
2
3
  import os
3
4
 
4
5
  import wandb
@@ -81,31 +81,3 @@ class Progress:
81
81
  return self.len
82
82
 
83
83
  next = __next__
84
-
85
-
86
- class AsyncProgress:
87
- """Wrapper around Progress, to make it async iterable.
88
-
89
- httpx, for streaming uploads, requires the data source to be an async iterable.
90
- If we pass in a sync iterable (like a bare `Progress` instance), httpx will
91
- get confused, think we're trying to make a synchronous request, and raise.
92
- So we need this wrapper class to be an async iterable but *not* a sync iterable.
93
- """
94
-
95
- def __init__(self, progress: Progress) -> None:
96
- self._progress = progress
97
-
98
- def __aiter__(self):
99
- return self
100
-
101
- async def __anext__(self):
102
- try:
103
- return next(self._progress)
104
- except StopIteration:
105
- raise StopAsyncIteration
106
-
107
- def __len__(self):
108
- return len(self._progress)
109
-
110
- def rewind(self) -> None:
111
- self._progress.rewind()
wandb/sdk/internal/run.py CHANGED
@@ -4,6 +4,7 @@
4
4
  Semi-stubbed run for internal process use.
5
5
 
6
6
  """
7
+
7
8
  from wandb._globals import _datatypes_set_callback
8
9
 
9
10
  from .. import wandb_run
@@ -327,7 +327,6 @@ class SendManager:
327
327
  # ignore_globs=(),
328
328
  _sync=True,
329
329
  disable_job_creation=False,
330
- _async_upload_concurrency_limit=None,
331
330
  _file_stream_timeout_seconds=0,
332
331
  )
333
332
  record_q: Queue[Record] = queue.Queue()
@@ -910,7 +909,7 @@ class SendManager:
910
909
  is_wandb_init = self._run is None
911
910
 
912
911
  # save start time of a run
913
- self._start_time = run.start_time.ToMicroseconds() // 1e6
912
+ self._start_time = int(run.start_time.ToMicroseconds() // 1e6)
914
913
 
915
914
  # update telemetry
916
915
  if run.telemetry:
@@ -28,14 +28,6 @@ logger = logging.getLogger(__name__)
28
28
  ROCM_SMI_CMD: Final[str] = shutil.which("rocm-smi") or "/usr/bin/rocm-smi"
29
29
 
30
30
 
31
- def get_rocm_smi_stats() -> Dict[str, Any]:
32
- command = [str(ROCM_SMI_CMD), "-a", "--json"]
33
- output = subprocess.check_output(command, universal_newlines=True).strip()
34
- if "No AMD GPUs specified" in output:
35
- return {}
36
- return json.loads(output.split("\n")[0]) # type: ignore
37
-
38
-
39
31
  _StatsKeys = Literal[
40
32
  "gpu",
41
33
  "memoryAllocated",
@@ -49,6 +41,48 @@ _Stats = Dict[_StatsKeys, float]
49
41
  _InfoDict = Dict[str, Union[int, List[Dict[str, Any]]]]
50
42
 
51
43
 
44
+ def get_rocm_smi_stats() -> Dict[str, Any]:
45
+ command = [str(ROCM_SMI_CMD), "-a", "--json"]
46
+ output = subprocess.check_output(command, universal_newlines=True).strip()
47
+ if "No AMD GPUs specified" in output:
48
+ return {}
49
+ return json.loads(output.split("\n")[0]) # type: ignore
50
+
51
+
52
+ def parse_stats(stats: Dict[str, str]) -> _Stats:
53
+ """Parse stats from rocm-smi output."""
54
+ parsed_stats: _Stats = {}
55
+
56
+ try:
57
+ parsed_stats["gpu"] = float(stats.get("GPU use (%)")) # type: ignore
58
+ except (TypeError, ValueError):
59
+ logger.warning("Could not parse GPU usage as float")
60
+ try:
61
+ parsed_stats["memoryAllocated"] = float(stats.get("GPU memory use (%)")) # type: ignore
62
+ except (TypeError, ValueError):
63
+ logger.warning("Could not parse GPU memory allocation as float")
64
+ try:
65
+ parsed_stats["temp"] = float(stats.get("Temperature (Sensor memory) (C)")) # type: ignore
66
+ except (TypeError, ValueError):
67
+ logger.warning("Could not parse GPU temperature as float")
68
+ try:
69
+ parsed_stats["powerWatts"] = float(
70
+ stats.get("Average Graphics Package Power (W)") # type: ignore
71
+ )
72
+ except (TypeError, ValueError):
73
+ logger.warning("Could not parse GPU power as float")
74
+ try:
75
+ parsed_stats["powerPercent"] = (
76
+ float(stats.get("Average Graphics Package Power (W)")) # type: ignore
77
+ / float(stats.get("Max Graphics Package Power (W)")) # type: ignore
78
+ * 100
79
+ )
80
+ except (TypeError, ValueError):
81
+ logger.warning("Could not parse GPU average/max power as float")
82
+
83
+ return parsed_stats
84
+
85
+
52
86
  class GPUAMDStats:
53
87
  """Stats for AMD GPU devices."""
54
88
 
@@ -58,40 +92,6 @@ class GPUAMDStats:
58
92
  def __init__(self) -> None:
59
93
  self.samples = deque()
60
94
 
61
- @staticmethod
62
- def parse_stats(stats: Dict[str, str]) -> _Stats:
63
- """Parse stats from rocm-smi output."""
64
- parsed_stats: _Stats = {}
65
-
66
- try:
67
- parsed_stats["gpu"] = float(stats.get("GPU use (%)")) # type: ignore
68
- except (TypeError, ValueError):
69
- logger.warning("Could not parse GPU usage as float")
70
- try:
71
- parsed_stats["memoryAllocated"] = float(stats.get("GPU memory use (%)")) # type: ignore
72
- except (TypeError, ValueError):
73
- logger.warning("Could not parse GPU memory allocation as float")
74
- try:
75
- parsed_stats["temp"] = float(stats.get("Temperature (Sensor memory) (C)")) # type: ignore
76
- except (TypeError, ValueError):
77
- logger.warning("Could not parse GPU temperature as float")
78
- try:
79
- parsed_stats["powerWatts"] = float(
80
- stats.get("Average Graphics Package Power (W)") # type: ignore
81
- )
82
- except (TypeError, ValueError):
83
- logger.warning("Could not parse GPU power as float")
84
- try:
85
- parsed_stats["powerPercent"] = (
86
- float(stats.get("Average Graphics Package Power (W)")) # type: ignore
87
- / float(stats.get("Max Graphics Package Power (W)")) # type: ignore
88
- * 100
89
- )
90
- except (TypeError, ValueError):
91
- logger.warning("Could not parse GPU average/max power as float")
92
-
93
- return parsed_stats
94
-
95
95
  def sample(self) -> None:
96
96
  try:
97
97
  raw_stats = get_rocm_smi_stats()
@@ -103,7 +103,7 @@ class GPUAMDStats:
103
103
 
104
104
  for card_key in card_keys:
105
105
  card_stats = raw_stats[card_key]
106
- stats = self.parse_stats(card_stats)
106
+ stats = parse_stats(card_stats)
107
107
  if stats:
108
108
  cards.append(stats)
109
109
 
@@ -183,7 +183,7 @@ class GPUAMD:
183
183
 
184
184
  can_read_rocm_smi = False
185
185
  try:
186
- if get_rocm_smi_stats():
186
+ if parse_stats(get_rocm_smi_stats()):
187
187
  can_read_rocm_smi = True
188
188
  except Exception:
189
189
  pass