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,4 +1,5 @@
1
1
  """Implementation of the GCP environment for wandb launch."""
2
+
2
3
  import logging
3
4
  import os
4
5
  import subprocess
@@ -1,4 +1,5 @@
1
1
  """Dummy local environment implementation. This is the default environment."""
2
+
2
3
  from typing import Any, Dict, Union
3
4
 
4
5
  from wandb.sdk.launch.errors import LaunchError
@@ -0,0 +1,148 @@
1
+ import json
2
+ import os
3
+ from typing import Any, Dict
4
+
5
+ import yaml
6
+
7
+ from ..errors import LaunchError
8
+
9
+ FILE_OVERRIDE_ENV_VAR = "WANDB_LAUNCH_FILE_OVERRIDES"
10
+
11
+
12
+ class FileOverrides:
13
+ """Singleton that read file overrides json from environment variables."""
14
+
15
+ _instance = None
16
+
17
+ def __new__(cls):
18
+ if cls._instance is None:
19
+ cls._instance = object.__new__(cls)
20
+ cls._instance.overrides = {}
21
+ cls._instance.load()
22
+ return cls._instance
23
+
24
+ def load(self) -> None:
25
+ """Load overrides from an environment variable."""
26
+ overrides = os.environ.get(FILE_OVERRIDE_ENV_VAR)
27
+ if overrides is None:
28
+ if f"{FILE_OVERRIDE_ENV_VAR}_0" in os.environ:
29
+ overrides = ""
30
+ idx = 0
31
+ while f"{FILE_OVERRIDE_ENV_VAR}_{idx}" in os.environ:
32
+ overrides += os.environ[f"{FILE_OVERRIDE_ENV_VAR}_{idx}"]
33
+ idx += 1
34
+ if overrides:
35
+ try:
36
+ contents = json.loads(overrides)
37
+ if not isinstance(contents, dict):
38
+ raise LaunchError(f"Invalid JSON in {FILE_OVERRIDE_ENV_VAR}")
39
+ self.overrides = contents
40
+ except json.JSONDecodeError:
41
+ raise LaunchError(f"Invalid JSON in {FILE_OVERRIDE_ENV_VAR}")
42
+
43
+
44
+ def config_path_is_valid(path: str) -> None:
45
+ """Validate a config file path.
46
+
47
+ This function checks if a given config file path is valid. A valid path
48
+ should meet the following criteria:
49
+
50
+ - The path must be expressed as a relative path without any upwards path
51
+ traversal, e.g. `../config.json`.
52
+ - The file specified by the path must exist.
53
+ - The file must have a supported extension (`.json`, `.yaml`, or `.yml`).
54
+
55
+ Args:
56
+ path (str): The path to validate.
57
+
58
+ Raises:
59
+ LaunchError: If the path is not valid.
60
+ """
61
+ if os.path.isabs(path):
62
+ raise LaunchError(
63
+ f"Invalid config path: {path}. Please provide a relative path."
64
+ )
65
+ if ".." in path:
66
+ raise LaunchError(
67
+ f"Invalid config path: {path}. Please provide a relative path "
68
+ "without any upward path traversal, e.g. `../config.json`."
69
+ )
70
+ path = os.path.normpath(path)
71
+ if not os.path.exists(path):
72
+ raise LaunchError(f"Invalid config path: {path}. File does not exist.")
73
+ if not any(path.endswith(ext) for ext in [".json", ".yaml", ".yml"]):
74
+ raise LaunchError(
75
+ f"Invalid config path: {path}. Only JSON and YAML files are supported."
76
+ )
77
+
78
+
79
+ def override_file(path: str) -> None:
80
+ """Check for file overrides in the environment and apply them if found."""
81
+ file_overrides = FileOverrides()
82
+ if path in file_overrides.overrides:
83
+ overrides = file_overrides.overrides.get(path)
84
+ if overrides is not None:
85
+ config = _read_config_file(path)
86
+ _update_dict(config, overrides)
87
+ _write_config_file(path, config)
88
+
89
+
90
+ def _write_config_file(path: str, config: Any) -> None:
91
+ """Write a config file to disk.
92
+
93
+ Args:
94
+ path (str): The path to the config file.
95
+ config (Any): The contents of the config file as a Python object.
96
+
97
+ Raises:
98
+ LaunchError: If the file extension is not supported.
99
+ """
100
+ _, ext = os.path.splitext(path)
101
+ if ext == ".json":
102
+ with open(path, "w") as f:
103
+ json.dump(config, f, indent=2)
104
+ elif ext in [".yaml", ".yml"]:
105
+ with open(path, "w") as f:
106
+ yaml.safe_dump(config, f)
107
+ else:
108
+ raise LaunchError(f"Unsupported file extension: {ext}")
109
+
110
+
111
+ def _read_config_file(path: str) -> Any:
112
+ """Read a config file from disk.
113
+
114
+ Args:
115
+ path (str): The path to the config file.
116
+
117
+ Returns:
118
+ Any: The contents of the config file as a Python object.
119
+ """
120
+ _, ext = os.path.splitext(path)
121
+ if ext == ".json":
122
+ with open(
123
+ path,
124
+ ) as f:
125
+ return json.load(f)
126
+ elif ext in [".yaml", ".yml"]:
127
+ with open(
128
+ path,
129
+ ) as f:
130
+ return yaml.safe_load(f)
131
+ else:
132
+ raise LaunchError(f"Unsupported file extension: {ext}")
133
+
134
+
135
+ def _update_dict(target: Dict, source: Dict) -> None:
136
+ """Update a dictionary with the contents of another dictionary.
137
+
138
+ Args:
139
+ target (Dict): The dictionary to update.
140
+ source (Dict): The dictionary to update from.
141
+ """
142
+ for key, value in source.items():
143
+ if isinstance(value, dict):
144
+ if key not in target:
145
+ target[key] = {}
146
+ _update_dict(target[key], value)
147
+ else:
148
+ target[key] = value
@@ -0,0 +1,217 @@
1
+ """The layer between launch sdk user code and the wandb internal process.
2
+
3
+ If there is an active run this communication is done through the wandb run's
4
+ backend interface.
5
+
6
+ If there is no active run, the messages are staged on the StagedLaunchInputs
7
+ singleton and sent when a run is created.
8
+ """
9
+
10
+ import os
11
+ import pathlib
12
+ import shutil
13
+ import tempfile
14
+ from typing import List, Optional
15
+
16
+ import wandb
17
+ import wandb.data_types
18
+ from wandb.sdk.launch.errors import LaunchError
19
+ from wandb.sdk.wandb_run import Run
20
+
21
+ from .files import config_path_is_valid, override_file
22
+
23
+ PERIOD = "."
24
+ BACKSLASH = "\\"
25
+
26
+
27
+ class ConfigTmpDir:
28
+ """Singleton for managing temporary directories for configuration files.
29
+
30
+ Any configuration files designated as inputs to a launch job are copied to
31
+ a temporary directory. This singleton manages the temporary directory and
32
+ provides paths to the configuration files.
33
+ """
34
+
35
+ _instance = None
36
+
37
+ def __new__(cls):
38
+ if cls._instance is None:
39
+ cls._instance = object.__new__(cls)
40
+ return cls._instance
41
+
42
+ def __init__(self):
43
+ if not hasattr(self, "_tmp_dir"):
44
+ self._tmp_dir = tempfile.mkdtemp()
45
+ self._configs_dir = os.path.join(self._tmp_dir, "configs")
46
+ os.mkdir(self._configs_dir)
47
+
48
+ @property
49
+ def tmp_dir(self):
50
+ return pathlib.Path(self._tmp_dir)
51
+
52
+ @property
53
+ def configs_dir(self):
54
+ return pathlib.Path(self._configs_dir)
55
+
56
+
57
+ class JobInputArguments:
58
+ """Arguments for the publish_job_input of Interface."""
59
+
60
+ def __init__(
61
+ self,
62
+ include: Optional[List[str]] = None,
63
+ exclude: Optional[List[str]] = None,
64
+ file_path: Optional[str] = None,
65
+ run_config: Optional[bool] = None,
66
+ ):
67
+ self.include = include
68
+ self.exclude = exclude
69
+ self.file_path = file_path
70
+ self.run_config = run_config
71
+
72
+
73
+ class StagedLaunchInputs:
74
+ _instance = None
75
+
76
+ def __new__(cls):
77
+ if cls._instance is None:
78
+ cls._instance = object.__new__(cls)
79
+ return cls._instance
80
+
81
+ def __init__(self) -> None:
82
+ if not hasattr(self, "_staged_inputs"):
83
+ self._staged_inputs: List[JobInputArguments] = []
84
+
85
+ def add_staged_input(
86
+ self,
87
+ input_arguments: JobInputArguments,
88
+ ):
89
+ self._staged_inputs.append(input_arguments)
90
+
91
+ def apply(self, run: Run):
92
+ """Apply the staged inputs to the given run."""
93
+ for input in self._staged_inputs:
94
+ _publish_job_input(input, run)
95
+
96
+
97
+ def _publish_job_input(
98
+ input: JobInputArguments,
99
+ run: Run,
100
+ ) -> None:
101
+ """Publish a job input to the backend interface of the given run.
102
+
103
+ Arguments:
104
+ input (JobInputArguments): The arguments for the job input.
105
+ run (Run): The run to publish the job input to.
106
+ """
107
+ assert run._backend is not None
108
+ assert run._backend.interface is not None
109
+ assert input.run_config is not None
110
+
111
+ interface = run._backend.interface
112
+ if input.file_path:
113
+ config_dir = ConfigTmpDir()
114
+ dest = os.path.join(config_dir.configs_dir, input.file_path)
115
+ run.save(dest, base_path=config_dir.tmp_dir)
116
+ interface.publish_job_input(
117
+ include_paths=[_split_on_unesc_dot(path) for path in input.include]
118
+ if input.include
119
+ else [],
120
+ exclude_paths=[_split_on_unesc_dot(path) for path in input.exclude]
121
+ if input.exclude
122
+ else [],
123
+ run_config=input.run_config,
124
+ file_path=input.file_path or "",
125
+ )
126
+
127
+
128
+ def handle_config_file_input(
129
+ path: str,
130
+ include: Optional[List[str]] = None,
131
+ exclude: Optional[List[str]] = None,
132
+ ):
133
+ """Declare an overridable configuration file for a launch job.
134
+
135
+ The configuration file is copied to a temporary directory and the path to
136
+ the copy is sent to the backend interface of the active run and used to
137
+ configure the job builder.
138
+
139
+ If there is no active run, the configuration file is staged and sent when a
140
+ run is created.
141
+ """
142
+ config_path_is_valid(path)
143
+ override_file(path)
144
+ tmp_dir = ConfigTmpDir()
145
+ dest = os.path.join(tmp_dir.configs_dir, path)
146
+ shutil.copy(path, dest)
147
+ arguments = JobInputArguments(
148
+ include=include,
149
+ exclude=exclude,
150
+ file_path=path,
151
+ run_config=False,
152
+ )
153
+ if wandb.run is not None:
154
+ _publish_job_input(arguments, wandb.run)
155
+ else:
156
+ staged_inputs = StagedLaunchInputs()
157
+ staged_inputs.add_staged_input(arguments)
158
+
159
+
160
+ def handle_run_config_input(
161
+ include: Optional[List[str]] = None, exclude: Optional[List[str]] = None
162
+ ):
163
+ """Declare wandb.config as an overridable configuration for a launch job.
164
+
165
+ The include and exclude paths are sent to the backend interface of the
166
+ active run and used to configure the job builder.
167
+
168
+ If there is no active run, the include and exclude paths are staged and sent
169
+ when a run is created.
170
+ """
171
+ arguments = JobInputArguments(
172
+ include=include,
173
+ exclude=exclude,
174
+ run_config=True,
175
+ file_path=None,
176
+ )
177
+ if wandb.run is not None:
178
+ _publish_job_input(arguments, wandb.run)
179
+ else:
180
+ stage_inputs = StagedLaunchInputs()
181
+ stage_inputs.add_staged_input(arguments)
182
+
183
+
184
+ def _split_on_unesc_dot(path: str) -> List[str]:
185
+ r"""Split a string on unescaped dots.
186
+
187
+ Arguments:
188
+ path (str): The string to split.
189
+
190
+ Raises:
191
+ ValueError: If the path has a trailing escape character.
192
+
193
+ Returns:
194
+ List[str]: The split string.
195
+ """
196
+ parts = []
197
+ part = ""
198
+ i = 0
199
+ while i < len(path):
200
+ if path[i] == BACKSLASH:
201
+ if i == len(path) - 1:
202
+ raise LaunchError(
203
+ f"Invalid config path {path}: trailing {BACKSLASH}.",
204
+ )
205
+ if path[i + 1] == PERIOD:
206
+ part += PERIOD
207
+ i += 2
208
+ elif path[i] == PERIOD:
209
+ parts.append(part)
210
+ part = ""
211
+ i += 1
212
+ else:
213
+ part += path[i]
214
+ i += 1
215
+ if part:
216
+ parts.append(part)
217
+ return parts
@@ -0,0 +1,95 @@
1
+ """Functions for declaring overridable configuration for launch jobs."""
2
+
3
+ from typing import List, Optional
4
+
5
+
6
+ def manage_config_file(
7
+ path: str,
8
+ include: Optional[List[str]] = None,
9
+ exclude: Optional[List[str]] = None,
10
+ ):
11
+ r"""Declare an overridable configuration file for a launch job.
12
+
13
+ If a new job version is created from the active run, the configuration file
14
+ will be added to the job's inputs. If the job is launched and overrides
15
+ have been provided for the configuration file, this function will detect
16
+ the overrides from the environment and update the configuration file on disk.
17
+ Note that these overrides will only be applied in ephemeral containers.
18
+ `include` and `exclude` are lists of dot separated paths with the config.
19
+ The paths are used to filter subtrees of the configuration file out of the
20
+ job's inputs.
21
+
22
+ For example, given the following configuration file:
23
+ ```yaml
24
+ model:
25
+ name: resnet
26
+ layers: 18
27
+ training:
28
+ epochs: 10
29
+ batch_size: 32
30
+ ```
31
+
32
+ Passing `include=['model']` will only include the `model` subtree in the
33
+ job's inputs. Passing `exclude=['model.layers']` will exclude the `layers`
34
+ key from the `model` subtree. Note that `exclude` takes precedence over
35
+ `include`.
36
+
37
+ `.` is used as a separator for nested keys. If a key contains a `.`, it
38
+ should be escaped with a backslash, e.g. `include=[r'model\.layers']`. Note
39
+ the use of `r` to denote a raw string when using escape chars.
40
+
41
+ Args:
42
+ path (str): The path to the configuration file. This path must be
43
+ relative and must not contain backwards traversal, i.e. `..`.
44
+ include (List[str]): A list of keys to include in the configuration file.
45
+ exclude (List[str]): A list of keys to exclude from the configuration file.
46
+
47
+ Raises:
48
+ LaunchError: If the path is not valid, or if there is no active run.
49
+ """
50
+ from .internal import handle_config_file_input
51
+
52
+ return handle_config_file_input(path, include, exclude)
53
+
54
+
55
+ def manage_wandb_config(
56
+ include: Optional[List[str]] = None,
57
+ exclude: Optional[List[str]] = None,
58
+ ):
59
+ r"""Declare wandb.config as an overridable configuration for a launch job.
60
+
61
+ If a new job version is created from the active run, the run config
62
+ (wandb.config) will become an overridable input of the job. If the job is
63
+ launched and overrides have been provided for the run config, the overrides
64
+ will be applied to the run config when `wandb.init` is called.
65
+ `include` and `exclude` are lists of dot separated paths with the config.
66
+ The paths are used to filter subtrees of the configuration file out of the
67
+ job's inputs.
68
+
69
+ For example, given the following run config contents:
70
+ ```yaml
71
+ model:
72
+ name: resnet
73
+ layers: 18
74
+ training:
75
+ epochs: 10
76
+ batch_size: 32
77
+ ```
78
+ Passing `include=['model']` will only include the `model` subtree in the
79
+ job's inputs. Passing `exclude=['model.layers']` will exclude the `layers`
80
+ key from the `model` subtree. Note that `exclude` takes precedence over
81
+ `include`.
82
+ `.` is used as a separator for nested keys. If a key contains a `.`, it
83
+ should be escaped with a backslash, e.g. `include=[r'model\.layers']`. Note
84
+ the use of `r` to denote a raw string when using escape chars.
85
+
86
+ Args:
87
+ include (List[str]): A list of subtrees to include in the configuration.
88
+ exclude (List[str]): A list of subtrees to exclude from the configuration.
89
+
90
+ Raises:
91
+ LaunchError: If there is no active run.
92
+ """
93
+ from .internal import handle_run_config_input
94
+
95
+ handle_run_config_input(include, exclude)
@@ -1,4 +1,5 @@
1
1
  """Utilities for the agent."""
2
+
2
3
  from typing import Any, Dict, Optional
3
4
 
4
5
  import wandb
@@ -1,4 +1,5 @@
1
1
  """Abstract base class for registries."""
2
+
2
3
  from abc import ABC, abstractmethod
3
4
  from typing import Tuple
4
5
 
@@ -1,4 +1,5 @@
1
1
  """Implementation of AzureContainerRegistry class."""
2
+
2
3
  import re
3
4
  from typing import TYPE_CHECKING, Optional, Tuple
4
5
 
@@ -1,4 +1,5 @@
1
1
  """Implementation of Elastic Container Registry class for wandb launch."""
2
+
2
3
  import base64
3
4
  import logging
4
5
  from typing import Dict, Optional, Tuple
@@ -1,4 +1,5 @@
1
1
  """Implementation of Google Artifact Registry for wandb launch."""
2
+
2
3
  import logging
3
4
  from typing import Optional, Tuple
4
5
 
@@ -210,7 +211,7 @@ class GoogleArtifactRegistry(AbstractRegistry):
210
211
  for image in await list_images(request={"parent": parent}):
211
212
  if tag in image.tags:
212
213
  return True
213
- except google.api_core.exceptions.NotFound as e:
214
+ except google.api_core.exceptions.NotFound as e: # type: ignore[attr-defined]
214
215
  raise LaunchError(
215
216
  f"The Google Artifact Registry repository {self.repository} "
216
217
  f"does not exist. Please create it or modify your registry configuration."
@@ -1,4 +1,5 @@
1
1
  """Local registry implementation."""
2
+
2
3
  import logging
3
4
  from typing import Tuple
4
5
 
@@ -3,6 +3,7 @@
3
3
  This class defines the interface that the W&B launch runner uses to manage the lifecycle
4
4
  of runs launched in different environments (e.g. runs launched locally or in a cluster).
5
5
  """
6
+
6
7
  import logging
7
8
  import os
8
9
  import subprocess
@@ -1,4 +1,5 @@
1
1
  """Monitors kubernetes resources managed by the launch agent."""
2
+
2
3
  import asyncio
3
4
  import logging
4
5
  import sys
@@ -1,4 +1,5 @@
1
1
  """Implementation of KubernetesRunner class for wandb launch."""
2
+
2
3
  import asyncio
3
4
  import base64
4
5
  import datetime
@@ -28,7 +29,6 @@ from wandb.sdk.lib.retry import ExponentialBackoff, retry_async
28
29
  from wandb.util import get_module
29
30
 
30
31
  from .._project_spec import EntryPoint, LaunchProject
31
- from ..builder.build import get_env_vars_dict
32
32
  from ..errors import LaunchError
33
33
  from ..utils import (
34
34
  LOG_PREFIX,
@@ -373,8 +373,7 @@ class KubernetesRunner(AbstractRunner):
373
373
  }
374
374
 
375
375
  entry_point = (
376
- launch_project.override_entrypoint
377
- or launch_project.get_single_entry_point()
376
+ launch_project.override_entrypoint or launch_project.get_job_entry_point()
378
377
  )
379
378
  if launch_project.docker_image:
380
379
  # dont specify run id if user provided image, could have multiple runs
@@ -400,8 +399,8 @@ class KubernetesRunner(AbstractRunner):
400
399
  launch_project.override_entrypoint is not None,
401
400
  )
402
401
 
403
- env_vars = get_env_vars_dict(
404
- launch_project, self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
402
+ env_vars = launch_project.get_env_vars_dict(
403
+ self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
405
404
  )
406
405
  api_key_secret = None
407
406
  for cont in containers:
@@ -510,8 +509,8 @@ class KubernetesRunner(AbstractRunner):
510
509
  api_version = resource_args.get("apiVersion", "batch/v1")
511
510
 
512
511
  if api_version not in ["batch/v1", "batch/v1beta1"]:
513
- env_vars = get_env_vars_dict(
514
- launch_project, self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
512
+ env_vars = launch_project.get_env_vars_dict(
513
+ self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
515
514
  )
516
515
  # Crawl the resource args and add our env vars to the containers.
517
516
  add_wandb_env(resource_args, env_vars)
@@ -539,9 +538,9 @@ class KubernetesRunner(AbstractRunner):
539
538
  WANDB_K8S_LABEL_MONITOR,
540
539
  LaunchAgent.name(),
541
540
  )
542
- resource_args["metadata"]["labels"][
543
- WANDB_K8S_LABEL_AGENT
544
- ] = LaunchAgent.name()
541
+ resource_args["metadata"]["labels"][WANDB_K8S_LABEL_AGENT] = (
542
+ LaunchAgent.name()
543
+ )
545
544
 
546
545
  overrides = {}
547
546
  if launch_project.override_args:
@@ -12,7 +12,6 @@ from wandb.sdk.launch.environment.abstract import AbstractEnvironment
12
12
  from wandb.sdk.launch.registry.abstract import AbstractRegistry
13
13
 
14
14
  from .._project_spec import LaunchProject
15
- from ..builder.build import get_env_vars_dict
16
15
  from ..errors import LaunchError
17
16
  from ..utils import (
18
17
  LOG_PREFIX,
@@ -133,8 +132,8 @@ class LocalContainerRunner(AbstractRunner):
133
132
  docker_args = self._populate_docker_args(launch_project, image_uri)
134
133
  synchronous: bool = self.backend_config[PROJECT_SYNCHRONOUS]
135
134
 
136
- env_vars = get_env_vars_dict(
137
- launch_project, self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
135
+ env_vars = launch_project.get_env_vars_dict(
136
+ self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
138
137
  )
139
138
 
140
139
  # When running against local port, need to swap to local docker host
@@ -4,16 +4,12 @@ from typing import Any, List, Optional
4
4
 
5
5
  import wandb
6
6
 
7
- from .._project_spec import LaunchProject, get_entry_point_command
8
- from ..builder.build import get_env_vars_dict
7
+ from .._project_spec import LaunchProject
9
8
  from ..errors import LaunchError
10
9
  from ..utils import (
11
10
  LOG_PREFIX,
12
11
  MAX_ENV_LENGTHS,
13
12
  PROJECT_SYNCHRONOUS,
14
- _is_wandb_uri,
15
- download_wandb_python_deps,
16
- parse_wandb_uri,
17
13
  sanitize_wandb_api_key,
18
14
  validate_wandb_python_deps,
19
15
  )
@@ -47,8 +43,7 @@ class LocalProcessRunner(AbstractRunner):
47
43
 
48
44
  synchronous: bool = self.backend_config[PROJECT_SYNCHRONOUS]
49
45
  entry_point = (
50
- launch_project.override_entrypoint
51
- or launch_project.get_single_entry_point()
46
+ launch_project.override_entrypoint or launch_project.get_job_entry_point()
52
47
  )
53
48
 
54
49
  cmd: List[Any] = []
@@ -56,23 +51,7 @@ class LocalProcessRunner(AbstractRunner):
56
51
  if launch_project.project_dir is None:
57
52
  raise LaunchError("Launch LocalProcessRunner received empty project dir")
58
53
 
59
- # Check to make sure local python dependencies match run's requirement.txt
60
- if launch_project.uri and _is_wandb_uri(launch_project.uri):
61
- source_entity, source_project, run_name = parse_wandb_uri(
62
- launch_project.uri
63
- )
64
- run_requirements_file = download_wandb_python_deps(
65
- source_entity,
66
- source_project,
67
- run_name,
68
- self._api,
69
- launch_project.project_dir,
70
- )
71
- validate_wandb_python_deps(
72
- run_requirements_file,
73
- launch_project.project_dir,
74
- )
75
- elif launch_project.job:
54
+ if launch_project.job:
76
55
  assert launch_project._job_artifact is not None
77
56
  try:
78
57
  validate_wandb_python_deps(
@@ -81,14 +60,14 @@ class LocalProcessRunner(AbstractRunner):
81
60
  )
82
61
  except Exception:
83
62
  wandb.termwarn("Unable to validate python dependencies")
84
- env_vars = get_env_vars_dict(
85
- launch_project, self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
63
+ env_vars = launch_project.get_env_vars_dict(
64
+ self._api, MAX_ENV_LENGTHS[self.__class__.__name__]
86
65
  )
87
66
  for env_key, env_value in env_vars.items():
88
67
  cmd += [f"{shlex.quote(env_key)}={shlex.quote(env_value)}"]
89
-
90
- entry_cmd = get_entry_point_command(entry_point, launch_project.override_args)
91
- cmd += entry_cmd
68
+ if entry_point is not None:
69
+ cmd += entry_point.command
70
+ cmd += launch_project.override_args
92
71
 
93
72
  command_str = " ".join(cmd).strip()
94
73
  _msg = f"{LOG_PREFIX}Launching run as a local-process with command {sanitize_wandb_api_key(command_str)}"