diff --git a/.gitattributes b/.gitattributes index 511b1905ec7ba6679e5bf351c2256f0c87012da2..9d4ae82a2ccd8507e112ae941f498d544ba53a87 100644 --- a/.gitattributes +++ b/.gitattributes @@ -147,3 +147,4 @@ parrot/lib/python3.10/site-packages/wandb/vendor/pygments/lexers/__pycache__/_ph parrot/lib/python3.10/site-packages/aiohttp/_http_writer.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text parrot/lib/libquadmath.so filter=lfs diff=lfs merge=lfs -text parrot/lib/python3.10/site-packages/pyarrow/_dataset_parquet.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text +parrot/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text diff --git a/parrot/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl b/parrot/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..673f289f117f53c03ab13e13af450df69b012431 --- /dev/null +++ b/parrot/lib/python3.10/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f62ea9da9ed6289bfe868cd6845968a2c854d1427f8548d52cae02a42b4f0356 +size 1232695 diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/__init__.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7f4174a70f4f29ddd0323fa929f62f0f14d20e35 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/__init__.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_alerts.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_alerts.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c7cfc0cd4a2d3a5535c37751f6d0905f794f990 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_alerts.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_config.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e36c213f793e56f3ba94066ed0abec5e5d48c0a1 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_config.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_helper.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_helper.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1a6269986643fae70818270ff9d5e2b5aa3a9b6c Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_helper.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_init.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_init.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5f8d5d6cb2ef6a720111f60887535d9f7f32c038 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_init.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_login.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_login.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..da3b270b824a8346431b289ab0080a2ee7c09ab0 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_login.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_manager.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_manager.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..028010c3b743766cb33d62eb406019ee93e4ccf3 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_manager.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_metric.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_metric.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ccfb0a37be6d76625c87925b0a4f35ec2ff3b3ae Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_metric.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b5382f4cfd662b14b5da0c72e2ba80585817a3f Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require_helpers.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require_helpers.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a3312f49b77b3ae3c505d3b914aeaadbacd60f5d Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_require_helpers.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_settings.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_settings.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..75a4132deb52baa7a1786a4d3c776d4ecc67346e Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_settings.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_setup.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_setup.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cd81c27c40137e27f6fa04f38c5a5d0f29f473e4 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_setup.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_summary.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_summary.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f6be478c8df0189cb8b5bf3172e9449e34b5a703 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_summary.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sweep.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sweep.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..84fef57712c303d282d31debbc546bfc7b4bd917 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sweep.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sync.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sync.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bbdfa48104b7616f4e6163ba062b3d8a6c00f231 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_sync.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_watch.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_watch.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ab9574ddd929ad1df650fce45aa72bb523ac2e6f Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/__pycache__/wandb_watch.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_download_logger.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_download_logger.py new file mode 100644 index 0000000000000000000000000000000000000000..2849b0b115dbb4d2fd9804732ab6a6a44fcec325 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_download_logger.py @@ -0,0 +1,43 @@ +"""Artifact download logger.""" + +import multiprocessing.dummy +import time +from typing import Callable + +from wandb.errors.term import termlog + + +class ArtifactDownloadLogger: + def __init__( + self, + nfiles: int, + clock_for_testing: Callable[[], float] = time.monotonic, + termlog_for_testing: Callable[..., None] = termlog, + ) -> None: + self._nfiles = nfiles + self._clock = clock_for_testing + self._termlog = termlog_for_testing + + self._n_files_downloaded = 0 + self._spinner_index = 0 + self._last_log_time = self._clock() + self._lock = multiprocessing.dummy.Lock() + + def notify_downloaded(self) -> None: + with self._lock: + self._n_files_downloaded += 1 + if self._n_files_downloaded == self._nfiles: + self._termlog( + f" {self._nfiles} of {self._nfiles} files downloaded. ", + # ^ trailing spaces to wipe out ellipsis from previous logs + newline=True, + ) + self._last_log_time = self._clock() + elif self._clock() - self._last_log_time > 0.1: + self._spinner_index += 1 + spinner = r"-\|/"[self._spinner_index % 4] + self._termlog( + f"{spinner} {self._n_files_downloaded} of {self._nfiles} files downloaded...\r", + newline=False, + ) + self._last_log_time = self._clock() diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.py new file mode 100644 index 0000000000000000000000000000000000000000..fb5053f9dc64d0bcc5c55abfefd0a433b581a4d0 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.py @@ -0,0 +1,72 @@ +"""Artifact manifest.""" + +from typing import TYPE_CHECKING, Dict, List, Mapping, Optional + +from wandb.sdk.internal.internal_api import Api as InternalApi +from wandb.sdk.lib.hashutil import HexMD5 + +if TYPE_CHECKING: + from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry + from wandb.sdk.artifacts.storage_policy import StoragePolicy + + +class ArtifactManifest: + entries: Dict[str, "ArtifactManifestEntry"] + + @classmethod + def from_manifest_json( + cls, manifest_json: Dict, api: Optional[InternalApi] = None + ) -> "ArtifactManifest": + if "version" not in manifest_json: + raise ValueError("Invalid manifest format. Must contain version field.") + version = manifest_json["version"] + for sub in cls.__subclasses__(): + if sub.version() == version: + return sub.from_manifest_json(manifest_json, api=api) + raise ValueError("Invalid manifest version.") + + @classmethod + def version(cls) -> int: + raise NotImplementedError + + def __init__( + self, + storage_policy: "StoragePolicy", + entries: Optional[Mapping[str, "ArtifactManifestEntry"]] = None, + ) -> None: + self.storage_policy = storage_policy + self.entries = dict(entries) if entries else {} + + def __len__(self) -> int: + return len(self.entries) + + def to_manifest_json(self) -> Dict: + raise NotImplementedError + + def digest(self) -> HexMD5: + raise NotImplementedError + + def add_entry(self, entry: "ArtifactManifestEntry") -> None: + if ( + entry.path in self.entries + and entry.digest != self.entries[entry.path].digest + ): + raise ValueError("Cannot add the same path twice: {}".format(entry.path)) + self.entries[entry.path] = entry + + def remove_entry(self, entry: "ArtifactManifestEntry") -> None: + if entry.path not in self.entries: + raise FileNotFoundError(f"Cannot remove missing entry: '{entry.path}'") + del self.entries[entry.path] + + def get_entry_by_path(self, path: str) -> Optional["ArtifactManifestEntry"]: + return self.entries.get(path) + + def get_entries_in_directory(self, directory: str) -> List["ArtifactManifestEntry"]: + return [ + self.entries[entry_key] + for entry_key in self.entries + if entry_key.startswith( + directory + "/" + ) # entries use forward slash even for windows + ] diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/__init__.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2e5fc516b5f5dce9e8c1f9b5168e7ec909e89578 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/__init__.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/artifact_manifest_v1.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/artifact_manifest_v1.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..98479c96811194de7b6fb113793e10243b03de4b Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/artifact_manifest_v1.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_saver.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_saver.py new file mode 100644 index 0000000000000000000000000000000000000000..3fd5131ec7c9fa84c7152519a4357ffafc9e7e13 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_saver.py @@ -0,0 +1,267 @@ +"""Artifact saver.""" + +import concurrent.futures +import json +import os +import sys +import tempfile +from typing import TYPE_CHECKING, Awaitable, Dict, Optional, Sequence + +import wandb +import wandb.filesync.step_prepare +from wandb import util +from wandb.sdk.artifacts.artifact_manifest import ArtifactManifest +from wandb.sdk.lib.hashutil import B64MD5, b64_to_hex_id, md5_file_b64 +from wandb.sdk.lib.paths import URIStr + +if TYPE_CHECKING: + from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry + from wandb.sdk.internal.file_pusher import FilePusher + from wandb.sdk.internal.internal_api import Api as InternalApi + from wandb.sdk.internal.progress import ProgressFn + + if sys.version_info >= (3, 8): + from typing import Protocol + else: + from typing_extensions import Protocol + + class SaveFn(Protocol): + def __call__( + self, entry: "ArtifactManifestEntry", progress_callback: "ProgressFn" + ) -> bool: + pass + + class SaveFnAsync(Protocol): + def __call__( + self, entry: "ArtifactManifestEntry", progress_callback: "ProgressFn" + ) -> Awaitable[bool]: + pass + + +class ArtifactSaver: + _server_artifact: Optional[Dict] # TODO better define this dict + + def __init__( + self, + api: "InternalApi", + digest: str, + manifest_json: Dict, + file_pusher: "FilePusher", + is_user_created: bool = False, + ) -> None: + self._api = api + self._file_pusher = file_pusher + self._digest = digest + self._manifest = ArtifactManifest.from_manifest_json( + manifest_json, + api=self._api, + ) + self._is_user_created = is_user_created + self._server_artifact = None + + def save( + self, + type: str, + name: str, + client_id: str, + sequence_client_id: str, + distributed_id: Optional[str] = None, + finalize: bool = True, + metadata: Optional[Dict] = None, + ttl_duration_seconds: Optional[int] = None, + description: Optional[str] = None, + aliases: Optional[Sequence[str]] = None, + tags: Optional[Sequence[str]] = None, + use_after_commit: bool = False, + incremental: bool = False, + history_step: Optional[int] = None, + base_id: Optional[str] = None, + ) -> Optional[Dict]: + return self._save_internal( + type, + name, + client_id, + sequence_client_id, + distributed_id, + finalize, + metadata, + ttl_duration_seconds, + description, + aliases, + tags, + use_after_commit, + incremental, + history_step, + base_id, + ) + + def _save_internal( + self, + type: str, + name: str, + client_id: str, + sequence_client_id: str, + distributed_id: Optional[str] = None, + finalize: bool = True, + metadata: Optional[Dict] = None, + ttl_duration_seconds: Optional[int] = None, + description: Optional[str] = None, + aliases: Optional[Sequence[str]] = None, + tags: Optional[Sequence[str]] = None, + use_after_commit: bool = False, + incremental: bool = False, + history_step: Optional[int] = None, + base_id: Optional[str] = None, + ) -> Optional[Dict]: + alias_specs = [] + for alias in aliases or []: + alias_specs.append({"artifactCollectionName": name, "alias": alias}) + + tag_specs = [{"tagName": tag} for tag in tags or []] + + """Returns the server artifact.""" + self._server_artifact, latest = self._api.create_artifact( + type, + name, + self._digest, + metadata=metadata, + ttl_duration_seconds=ttl_duration_seconds, + aliases=alias_specs, + tags=tag_specs, + description=description, + is_user_created=self._is_user_created, + distributed_id=distributed_id, + client_id=client_id, + sequence_client_id=sequence_client_id, + history_step=history_step, + ) + + assert self._server_artifact is not None # mypy optionality unwrapper + artifact_id = self._server_artifact["id"] + if base_id is None and latest: + base_id = latest["id"] + if self._server_artifact["state"] == "COMMITTED": + if use_after_commit: + self._api.use_artifact(artifact_id) + return self._server_artifact + if ( + self._server_artifact["state"] != "PENDING" + # For old servers, see https://github.com/wandb/wandb/pull/6190 + and self._server_artifact["state"] != "DELETED" + ): + raise Exception( + 'Unknown artifact state "{}"'.format(self._server_artifact["state"]) + ) + + manifest_type = "FULL" + manifest_filename = "wandb_manifest.json" + if incremental: + manifest_type = "INCREMENTAL" + manifest_filename = "wandb_manifest.incremental.json" + elif distributed_id: + manifest_type = "PATCH" + manifest_filename = "wandb_manifest.patch.json" + artifact_manifest_id, _ = self._api.create_artifact_manifest( + manifest_filename, + "", + artifact_id, + base_artifact_id=base_id, + include_upload=False, + type=manifest_type, + ) + + step_prepare = wandb.filesync.step_prepare.StepPrepare( + self._api, 0.1, 0.01, 1000 + ) # TODO: params + step_prepare.start() + + # Upload Artifact "L1" files, the actual artifact contents + self._file_pusher.store_manifest_files( + self._manifest, + artifact_id, + lambda entry, progress_callback: self._manifest.storage_policy.store_file( + artifact_id, + artifact_manifest_id, + entry, + step_prepare, + progress_callback=progress_callback, + ), + ) + + def before_commit() -> None: + self._resolve_client_id_manifest_references() + with tempfile.NamedTemporaryFile("w+", suffix=".json", delete=False) as fp: + path = os.path.abspath(fp.name) + json.dump(self._manifest.to_manifest_json(), fp, indent=4) + digest = md5_file_b64(path) + if distributed_id or incremental: + # If we're in the distributed flow, we want to update the + # patch manifest we created with our finalized digest. + _, resp = self._api.update_artifact_manifest( + artifact_manifest_id, + digest=digest, + ) + else: + # In the regular flow, we can recreate the full manifest with the + # updated digest. + # + # NOTE: We do this for backwards compatibility with older backends + # that don't support the 'updateArtifactManifest' API. + _, resp = self._api.create_artifact_manifest( + manifest_filename, + digest, + artifact_id, + base_artifact_id=base_id, + ) + + # We're duplicating the file upload logic a little, which isn't great. + upload_url = resp["uploadUrl"] + upload_headers = resp["uploadHeaders"] + extra_headers = {} + for upload_header in upload_headers: + key, val = upload_header.split(":", 1) + extra_headers[key] = val + with open(path, "rb") as fp2: + self._api.upload_file_retry( + upload_url, + fp2, + extra_headers=extra_headers, + ) + + commit_result: concurrent.futures.Future[None] = concurrent.futures.Future() + + # This will queue the commit. It will only happen after all the file uploads are done + self._file_pusher.commit_artifact( + artifact_id, + finalize=finalize, + before_commit=before_commit, + result_future=commit_result, + ) + + # Block until all artifact files are uploaded and the + # artifact is committed. + try: + commit_result.result() + finally: + step_prepare.shutdown() + + if finalize and use_after_commit: + self._api.use_artifact(artifact_id) + + return self._server_artifact + + def _resolve_client_id_manifest_references(self) -> None: + for entry_path in self._manifest.entries: + entry = self._manifest.entries[entry_path] + if entry.ref is not None: + if entry.ref.startswith("wandb-client-artifact:"): + client_id = util.host_from_path(entry.ref) + artifact_file_path = util.uri_from_path(entry.ref) + artifact_id = self._api._resolve_client_id(client_id) + if artifact_id is None: + raise RuntimeError(f"Could not resolve client id {client_id}") + entry.ref = URIStr( + "wandb-artifact://{}/{}".format( + b64_to_hex_id(B64MD5(artifact_id)), artifact_file_path + ) + ) diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/staging.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/staging.py new file mode 100644 index 0000000000000000000000000000000000000000..d970d71b02f381fe7985e1cc8aed9b9d551ec890 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/staging.py @@ -0,0 +1,25 @@ +"""Manages artifact file staging. + +Artifact files are copied to the staging area as soon as they are added to an artifact +in order to avoid file changes corrupting the artifact. Once the upload is complete, the +file should be moved to the artifact cache. +""" + +import os + +from wandb import env +from wandb.sdk.lib.filesystem import mkdir_exists_ok +from wandb.sdk.lib.paths import FilePathStr + + +def get_staging_dir() -> FilePathStr: + path = os.path.join(env.get_data_dir(), "artifacts", "staging") + try: + mkdir_exists_ok(path) + except OSError as e: + raise PermissionError( + f"Unable to write staging files to {path}. To fix this problem, please set " + f"{env.DATA_DIR} to a directory where you have the necessary write access." + ) from e + + return FilePathStr(os.path.abspath(os.path.expanduser(path))) diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handler.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..bd58cabfd0c2e600e0f13f53bdc02461aeb70ace --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handler.py @@ -0,0 +1,60 @@ +"""Storage handler.""" + +from typing import TYPE_CHECKING, Optional, Sequence, Union + +from wandb.sdk.lib.paths import FilePathStr, URIStr + +if TYPE_CHECKING: + from urllib.parse import ParseResult + + from wandb.sdk.artifacts.artifact import Artifact + from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry + +DEFAULT_MAX_OBJECTS = 10**7 + + +class StorageHandler: + def can_handle(self, parsed_url: "ParseResult") -> bool: + """Checks whether this handler can handle the given url. + + Returns: + Whether this handler can handle the given url. + """ + raise NotImplementedError + + def load_path( + self, + manifest_entry: "ArtifactManifestEntry", + local: bool = False, + ) -> Union[URIStr, FilePathStr]: + """Load a file or directory given the corresponding index entry. + + Args: + manifest_entry: The index entry to load + local: Whether to load the file locally or not + + Returns: + A path to the file represented by `index_entry` + """ + raise NotImplementedError + + def store_path( + self, + artifact: "Artifact", + path: Union[URIStr, FilePathStr], + name: Optional[str] = None, + checksum: bool = True, + max_objects: Optional[int] = None, + ) -> Sequence["ArtifactManifestEntry"]: + """Store the file or directory at the given path to the specified artifact. + + Args: + path: The path to store + name: If specified, the logical name that should map to `path` + checksum: Whether to compute the checksum of the file + max_objects: The maximum number of objects to store + + Returns: + A list of manifest entries to store within the artifact + """ + raise NotImplementedError diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__init__.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/azure_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/azure_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ba6f6e615506390d561934497e2af909b24e8446 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/azure_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/gcs_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/gcs_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dfa23f7d7a75b6ba731ad9044f32ae17d32e5e02 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/gcs_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/local_file_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/local_file_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..440b06954e9abae3d2e416b247a7e4ccb369296c Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/local_file_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/multi_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/multi_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cf6f3da52804fa09665e28862791dbbb07fc26fc Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/multi_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/s3_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/s3_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..32680dc941ed217abdb5072ff347c47fd020ae50 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/s3_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/wb_artifact_handler.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/wb_artifact_handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..070ec15025071fc65074508b613271b71d6d0245 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/wb_artifact_handler.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/gcs_handler.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/gcs_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..6ca802718ff05a0e6d6d1103739accadf7b0ff4f --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/gcs_handler.py @@ -0,0 +1,226 @@ +"""GCS storage handler.""" + +import time +from pathlib import PurePosixPath +from typing import TYPE_CHECKING, Optional, Sequence, Tuple, Union +from urllib.parse import ParseResult, urlparse + +from wandb import util +from wandb.errors.term import termlog +from wandb.sdk.artifacts.artifact_file_cache import get_artifact_file_cache +from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry +from wandb.sdk.artifacts.storage_handler import DEFAULT_MAX_OBJECTS, StorageHandler +from wandb.sdk.lib.hashutil import ETag +from wandb.sdk.lib.paths import FilePathStr, StrPath, URIStr + +if TYPE_CHECKING: + import google.cloud.storage as gcs_module # type: ignore + + from wandb.sdk.artifacts.artifact import Artifact + + +class _GCSIsADirectoryError(Exception): + """Raised when we try to download a GCS folder.""" + + pass + + +class GCSHandler(StorageHandler): + _client: Optional["gcs_module.client.Client"] + + def __init__(self, scheme: Optional[str] = None) -> None: + self._scheme = scheme or "gs" + self._client = None + self._cache = get_artifact_file_cache() + + def can_handle(self, parsed_url: "ParseResult") -> bool: + return parsed_url.scheme == self._scheme + + def init_gcs(self) -> "gcs_module.client.Client": + if self._client is not None: + return self._client + storage = util.get_module( + "google.cloud.storage", + required="gs:// references requires the google-cloud-storage library, run pip install wandb[gcp]", + ) + self._client = storage.Client() + return self._client + + def _parse_uri(self, uri: str) -> Tuple[str, str, Optional[str]]: + url = urlparse(uri) + bucket = url.netloc + key = url.path[1:] + version = url.fragment if url.fragment else None + return bucket, key, version + + def load_path( + self, + manifest_entry: ArtifactManifestEntry, + local: bool = False, + ) -> Union[URIStr, FilePathStr]: + assert manifest_entry.ref is not None + if not local: + return manifest_entry.ref + + path, hit, cache_open = self._cache.check_etag_obj_path( + url=URIStr(manifest_entry.ref), + etag=ETag(manifest_entry.digest), + size=manifest_entry.size if manifest_entry.size is not None else 0, + ) + if hit: + return path + + self.init_gcs() + assert self._client is not None # mypy: unwraps optionality + assert manifest_entry.ref is not None + bucket, key, _ = self._parse_uri(manifest_entry.ref) + version = manifest_entry.extra.get("versionID") + + if self._is_dir(manifest_entry): + raise _GCSIsADirectoryError( + f"Unable to download GCS folder {manifest_entry.ref!r}, skipping" + ) + + obj = None + # First attempt to get the generation specified, this will return None if versioning is not enabled + if version is not None: + obj = self._client.bucket(bucket).get_blob(key, generation=version) + + if obj is None: + # Object versioning is disabled on the bucket, so just get + # the latest version and make sure the MD5 matches. + obj = self._client.bucket(bucket).get_blob(key) + if obj is None: + raise ValueError( + f"Unable to download object {manifest_entry.ref} with generation {version}" + ) + if obj.etag != manifest_entry.digest: + raise ValueError( + f"Digest mismatch for object {manifest_entry.ref}: " + f"expected {manifest_entry.digest} but found {obj.etag}" + ) + + with cache_open(mode="wb") as f: + obj.download_to_file(f) + return path + + def store_path( + self, + artifact: "Artifact", + path: Union[URIStr, FilePathStr], + name: Optional[StrPath] = None, + checksum: bool = True, + max_objects: Optional[int] = None, + ) -> Sequence[ArtifactManifestEntry]: + self.init_gcs() + assert self._client is not None # mypy: unwraps optionality + + # After parsing any query params / fragments for additional context, + # such as version identifiers, pare down the path to just the bucket + # and key. + bucket, key, version = self._parse_uri(path) + path = URIStr(f"{self._scheme}://{bucket}/{key}") + max_objects = max_objects or DEFAULT_MAX_OBJECTS + + if not checksum: + return [ArtifactManifestEntry(path=name or key, ref=path, digest=path)] + + start_time = None + obj = self._client.bucket(bucket).get_blob(key, generation=version) + if obj is None and version is not None: + raise ValueError(f"Object does not exist: {path}#{version}") + multi = obj is None + if multi: + start_time = time.time() + termlog( + 'Generating checksum for up to %i objects with prefix "%s"... ' + % (max_objects, key), + newline=False, + ) + objects = self._client.bucket(bucket).list_blobs( + prefix=key, max_results=max_objects + ) + else: + objects = [obj] + + entries = [ + self._entry_from_obj(obj, path, name, prefix=key, multi=multi) + for obj in objects + if not obj.name.endswith("/") + ] + if start_time is not None: + termlog("Done. %.1fs" % (time.time() - start_time), prefix=False) + if len(entries) > max_objects: + raise ValueError( + "Exceeded %i objects tracked, pass max_objects to add_reference" + % max_objects + ) + return entries + + def _entry_from_obj( + self, + obj: "gcs_module.blob.Blob", + path: str, + name: Optional[StrPath] = None, + prefix: str = "", + multi: bool = False, + ) -> ArtifactManifestEntry: + """Create an ArtifactManifestEntry from a GCS object. + + Arguments: + obj: The GCS object + path: The GCS-style path (e.g.: "gs://bucket/file.txt") + name: The user assigned name, or None if not specified + prefix: The prefix to add (will be the same as `path` for directories) + multi: Whether or not this is a multi-object add. + """ + bucket, key, _ = self._parse_uri(path) + + # Always use posix paths, since that's what S3 uses. + posix_key = PurePosixPath(obj.name) # the bucket key + posix_path = PurePosixPath(bucket) / PurePosixPath( + key + ) # the path, with the scheme stripped + posix_prefix = PurePosixPath(prefix) # the prefix, if adding a prefix + posix_name = PurePosixPath(name or "") + posix_ref = posix_path + + if name is None: + # We're adding a directory (prefix), so calculate a relative path. + if str(posix_prefix) in str(posix_key) and posix_prefix != posix_key: + posix_name = posix_key.relative_to(posix_prefix) + posix_ref = posix_path / posix_name + else: + posix_name = PurePosixPath(posix_key.name) + posix_ref = posix_path + elif multi: + # We're adding a directory with a name override. + relpath = posix_key.relative_to(posix_prefix) + posix_name = posix_name / relpath + posix_ref = posix_path / relpath + return ArtifactManifestEntry( + path=posix_name, + ref=URIStr(f"{self._scheme}://{str(posix_ref)}"), + digest=obj.etag, + size=obj.size, + extra={"versionID": obj.generation}, + ) + + def _is_dir( + self, + manifest_entry: ArtifactManifestEntry, + ) -> bool: + assert self._client is not None + assert manifest_entry.ref is not None + bucket, key, _ = self._parse_uri(manifest_entry.ref) + bucket_obj = self._client.bucket(bucket) + # A gcs bucket key should end with a forward slash on gcloud, but + # we save these refs without the forward slash in the manifest entry + # so we check the size and extension, make sure its not referring to + # an actual file with this reference, and that the ref with the slash + # exists on gcloud + return key.endswith("/") or ( + not (manifest_entry.size or PurePosixPath(key).suffix) + and bucket_obj.get_blob(key) is None + and bucket_obj.get_blob(f"{key}/") is not None + ) diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/http_handler.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/http_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..c7a8e26f6ccdb1d3d2a6a9fbb592704b86e2ba57 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/http_handler.py @@ -0,0 +1,113 @@ +"""HTTP storage handler.""" + +import os +from typing import TYPE_CHECKING, Dict, Optional, Sequence, Tuple, Union +from urllib.parse import ParseResult + +from wandb.sdk.artifacts.artifact_file_cache import get_artifact_file_cache +from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry +from wandb.sdk.artifacts.storage_handler import StorageHandler +from wandb.sdk.internal.thread_local_settings import _thread_local_api_settings +from wandb.sdk.lib.hashutil import ETag +from wandb.sdk.lib.paths import FilePathStr, StrPath, URIStr + +if TYPE_CHECKING: + import requests + + from wandb.sdk.artifacts.artifact import Artifact + + +class HTTPHandler(StorageHandler): + def __init__( + self, session: "requests.Session", scheme: Optional[str] = None + ) -> None: + self._scheme = scheme or "http" + self._cache = get_artifact_file_cache() + self._session = session + + def can_handle(self, parsed_url: "ParseResult") -> bool: + return parsed_url.scheme == self._scheme + + def load_path( + self, + manifest_entry: ArtifactManifestEntry, + local: bool = False, + ) -> Union[URIStr, FilePathStr]: + if not local: + assert manifest_entry.ref is not None + return manifest_entry.ref + + assert manifest_entry.ref is not None + + path, hit, cache_open = self._cache.check_etag_obj_path( + URIStr(manifest_entry.ref), + ETag(manifest_entry.digest), # TODO(spencerpearson): unsafe cast + manifest_entry.size if manifest_entry.size is not None else 0, + ) + if hit: + return path + + response = self._session.get( + manifest_entry.ref, + stream=True, + cookies=_thread_local_api_settings.cookies, + headers=_thread_local_api_settings.headers, + ) + response.raise_for_status() + + digest: Optional[Union[ETag, FilePathStr, URIStr]] + digest, size, extra = self._entry_from_headers(response.headers) + digest = digest or manifest_entry.ref + if manifest_entry.digest != digest: + raise ValueError( + f"Digest mismatch for url {manifest_entry.ref}: expected {manifest_entry.digest} but found {digest}" + ) + + with cache_open(mode="wb") as file: + for data in response.iter_content(chunk_size=16 * 1024): + file.write(data) + return path + + def store_path( + self, + artifact: "Artifact", + path: Union[URIStr, FilePathStr], + name: Optional[StrPath] = None, + checksum: bool = True, + max_objects: Optional[int] = None, + ) -> Sequence[ArtifactManifestEntry]: + name = name or os.path.basename(path) + if not checksum: + return [ArtifactManifestEntry(path=name, ref=path, digest=path)] + + with self._session.get( + path, + stream=True, + cookies=_thread_local_api_settings.cookies, + headers=_thread_local_api_settings.headers, + ) as response: + response.raise_for_status() + digest: Optional[Union[ETag, FilePathStr, URIStr]] + digest, size, extra = self._entry_from_headers(response.headers) + digest = digest or path + return [ + ArtifactManifestEntry( + path=name, ref=path, digest=digest, size=size, extra=extra + ) + ] + + def _entry_from_headers( + self, headers: "requests.structures.CaseInsensitiveDict" + ) -> Tuple[Optional[ETag], Optional[int], Dict[str, str]]: + response_headers = {k.lower(): v for k, v in headers.items()} + size = None + if response_headers.get("content-length", None): + size = int(response_headers["content-length"]) + + digest = response_headers.get("etag", None) + extra = {} + if digest: + extra["etag"] = digest + if digest and digest[:1] == '"' and digest[-1:] == '"': + digest = digest[1:-1] # trim leading and trailing quotes around etag + return digest, size, extra diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/multi_handler.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/multi_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..93981d07b36c412fc36044479f28c011ac67dbd4 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/multi_handler.py @@ -0,0 +1,54 @@ +"""Multi storage handler.""" + +from typing import TYPE_CHECKING, List, Optional, Sequence, Union +from urllib.parse import urlparse + +from wandb.sdk.artifacts.storage_handler import StorageHandler +from wandb.sdk.lib.paths import FilePathStr, URIStr + +if TYPE_CHECKING: + from wandb.sdk.artifacts.artifact import Artifact + from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry + + +class MultiHandler(StorageHandler): + _handlers: List[StorageHandler] + + def __init__( + self, + handlers: Optional[List[StorageHandler]] = None, + default_handler: Optional[StorageHandler] = None, + ) -> None: + self._handlers = handlers or [] + self._default_handler = default_handler + + def _get_handler(self, url: Union[FilePathStr, URIStr]) -> StorageHandler: + parsed_url = urlparse(url) + for handler in self._handlers: + if handler.can_handle(parsed_url): + return handler + if self._default_handler is not None: + return self._default_handler + raise ValueError('No storage handler registered for url "{}"'.format(str(url))) + + def load_path( + self, + manifest_entry: "ArtifactManifestEntry", + local: bool = False, + ) -> Union[URIStr, FilePathStr]: + assert manifest_entry.ref is not None + handler = self._get_handler(manifest_entry.ref) + return handler.load_path(manifest_entry, local=local) + + def store_path( + self, + artifact: "Artifact", + path: Union[URIStr, FilePathStr], + name: Optional[str] = None, + checksum: bool = True, + max_objects: Optional[int] = None, + ) -> Sequence["ArtifactManifestEntry"]: + handler = self._get_handler(path) + return handler.store_path( + artifact, path, name=name, checksum=checksum, max_objects=max_objects + ) diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/tracking_handler.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/tracking_handler.py new file mode 100644 index 0000000000000000000000000000000000000000..ea39cf14edc67b154cf2fa3bbf0c03bb393a2c21 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/tracking_handler.py @@ -0,0 +1,70 @@ +"""Tracking storage handler.""" + +from typing import TYPE_CHECKING, Optional, Sequence, Union +from urllib.parse import urlparse + +from wandb.errors.term import termwarn +from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry +from wandb.sdk.artifacts.storage_handler import StorageHandler +from wandb.sdk.lib.paths import FilePathStr, StrPath, URIStr + +if TYPE_CHECKING: + from urllib.parse import ParseResult + + from wandb.sdk.artifacts.artifact import Artifact + + +class TrackingHandler(StorageHandler): + def __init__(self, scheme: Optional[str] = None) -> None: + """Track paths with no modification or special processing. + + Useful when paths being tracked are on file systems mounted at a standardized + location. + + For example, if the data to track is located on an NFS share mounted on + `/data`, then it is sufficient to just track the paths. + """ + self._scheme = scheme or "" + + def can_handle(self, parsed_url: "ParseResult") -> bool: + return parsed_url.scheme == self._scheme + + def load_path( + self, + manifest_entry: ArtifactManifestEntry, + local: bool = False, + ) -> Union[URIStr, FilePathStr]: + if local: + # Likely a user error. The tracking handler is + # oblivious to the underlying paths, so it has + # no way of actually loading it. + url = urlparse(manifest_entry.ref) + raise ValueError( + f"Cannot download file at path {str(manifest_entry.ref)}, scheme {str(url.scheme)} not recognized" + ) + # TODO(spencerpearson): should this go through util.to_native_slash_path + # instead of just getting typecast? + return FilePathStr(manifest_entry.path) + + def store_path( + self, + artifact: "Artifact", + path: Union[URIStr, FilePathStr], + name: Optional[StrPath] = None, + checksum: bool = True, + max_objects: Optional[int] = None, + ) -> Sequence[ArtifactManifestEntry]: + url = urlparse(path) + if name is None: + raise ValueError( + 'You must pass name="" when tracking references with unknown schemes. ref: {}'.format( + path + ) + ) + termwarn( + "Artifact references with unsupported schemes cannot be checksummed: {}".format( + path + ) + ) + name = name or url.path[1:] # strip leading slash + return [ArtifactManifestEntry(path=name, ref=path, digest=path)] diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_layout.py b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_layout.py new file mode 100644 index 0000000000000000000000000000000000000000..b07cbd8e50fdc507e6f2787611514f09f653b851 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_layout.py @@ -0,0 +1,6 @@ +"""Storage layout.""" + + +class StorageLayout: + V1 = "V1" + V2 = "V2" diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/backend/__pycache__/__init__.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/backend/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5bd4fdc624e1e07c6adef376c0c494e1fb454ef5 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/backend/__pycache__/__init__.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/__init__.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fab40d4ecc80995768a526dcf1f1aafed0acc272 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/__init__.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_settings_toposort_generate.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_settings_toposort_generate.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b8b432aed5a4376f67c8c06a4dcba0352e0c82b2 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_settings_toposort_generate.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_wburls_generate.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_wburls_generate.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..794e253b74c4100fe5d4157db64af6672270e1a7 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/_wburls_generate.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/apikey.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/apikey.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..abfead80da7bf58500210d799f31e779719e26f0 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/apikey.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/capped_dict.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/capped_dict.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..632933fe675619f543a5deb847414947ab553dd7 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/capped_dict.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/deprecate.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/deprecate.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bc5530be722f362d6d7c712670e45eb9e110420e Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/deprecate.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/exit_hooks.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/exit_hooks.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a9051d6d070afc7706bbb7dbcfd87b1d9258f409 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/exit_hooks.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/file_stream_utils.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/file_stream_utils.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fd238d3904f64fa97b06e9d02c2ab0ef7bd9dabb Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/file_stream_utils.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filenames.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filenames.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bb2d27414af76b9503bdf7c64012945abbf8b5a2 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filenames.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filesystem.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filesystem.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8404d3c0a9819cf80cd501fa717e790eda8e0ba9 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/filesystem.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/fsm.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/fsm.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92acaac625806255d6d2dbff5a28e54c30604053 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/fsm.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gitlib.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gitlib.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0faaf5c8661877a0ff5fb89072e98b88f7ba0ded Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gitlib.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gql_request.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gql_request.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..274bb04793723cec2e4ea6bd1618c07c8ad93f7d Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/gql_request.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/handler_util.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/handler_util.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d6cd39bbcee875b0b3e26c163848035e6af8fd7e Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/handler_util.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/hashutil.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/hashutil.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..464f2ea9aed6fec02f21ec82e3250e1fe6d05c67 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/hashutil.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/import_hooks.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/import_hooks.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e9e83781d3494c7bd8c660404b1033ae43b0171 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/import_hooks.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/ipython.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/ipython.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e0cb9a268f4cc97527407d7c7622aa50c4f9ffcf Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/ipython.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/json_util.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/json_util.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7d0a3ed2c0248eebb6256f78c4875119d9441574 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/json_util.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/mailbox.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/mailbox.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cbe2ad73e59e5f1139aac0114af57862dcc9dc28 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/mailbox.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/module.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/module.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..59593d2713f0739a62994d8ee8c0d62032b571fd Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/module.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/preinit.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/preinit.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1e0a38aaff85d669dd38312b1c4e522274c76758 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/preinit.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/printer.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/printer.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ecb61e7a915be6c5d82b1a2f60263fe2310ad56c Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/printer.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/redirect.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/redirect.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..21e861cb9dd3e4a70ea04b64dde218b8fa394d08 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/redirect.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/retry.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/retry.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4878137eb8fcf8df4f470f0090b69263f35c6429 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/retry.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/run_moment.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/run_moment.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9c990c5d5d9f62e901ab37626459f9aa1cb7491 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/run_moment.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/runid.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/runid.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..000f8e49390aabcd212a2338a965b844c11b9faf Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/runid.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/server.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/server.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c1bf79a801c8b30d37a3eb4e43bf1b9570fdfa1 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/server.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/telemetry.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/telemetry.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e326fe6ceb2472dc0bdcb7f1db5e932697910113 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/telemetry.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/timed_input.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/timed_input.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e0c316c8109c7aed3d8367426b469340042d764 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/timed_input.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/tracelog.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/tracelog.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c5729920248692f2b641228ca589ff00065d691 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/tracelog.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/viz.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/viz.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c5ea06b916d97fc4cae412833954e811e2650f4f Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/viz.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/wburls.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/wburls.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b177a13597acf6f972e390578cc8d5afd57d62d7 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/lib/__pycache__/wburls.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/__init__.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/__pycache__/server_sock.cpython-310.pyc b/parrot/lib/python3.10/site-packages/wandb/sdk/service/__pycache__/server_sock.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b7649369faf1218504083918a6ab0df7896a5990 Binary files /dev/null and b/parrot/lib/python3.10/site-packages/wandb/sdk/service/__pycache__/server_sock.cpython-310.pyc differ diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/_startup_debug.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/_startup_debug.py new file mode 100644 index 0000000000000000000000000000000000000000..766a6f1cf3dac53fbfa3cf0a444e4e4e32f62496 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/service/_startup_debug.py @@ -0,0 +1,22 @@ +"""_startup_debug. + +Temporary helper to debug issues with wandb service startup +""" + +import os +import time + + +def is_enabled() -> bool: + # This is very temporary to help diagnose problems seen by some + # customers which we are having trouble reproducing. It should be + # replaced by something more permanent in the future when we have + # proper logging for wandb-service + if os.environ.get("_WANDB_STARTUP_DEBUG"): + return True + return False + + +def print_message(message: str) -> None: + time_now = time.time() + print("WANDB_STARTUP_DEBUG", time_now, message) diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/port_file.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/port_file.py new file mode 100644 index 0000000000000000000000000000000000000000..1980a84dd29af08d4c402a932231b7b04615337e --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/service/port_file.py @@ -0,0 +1,53 @@ +"""port_file: write/read file containing port info.""" + +import os +import tempfile +from typing import Optional + + +class PortFile: + _sock_port: Optional[int] + _valid: bool + + SOCK_TOKEN = "sock=" + EOF_TOKEN = "EOF" + + def __init__(self, sock_port: Optional[int] = None) -> None: + self._sock_port = sock_port + self._valid = False + + def write(self, fname: str) -> None: + dname, bname = os.path.split(fname) + f = tempfile.NamedTemporaryFile(prefix=bname, dir=dname, mode="w", delete=False) + try: + tmp_filename = f.name + with f: + data = [] + if self._sock_port: + data.append(f"{self.SOCK_TOKEN}{self._sock_port}") + data.append(self.EOF_TOKEN) + port_str = "\n".join(data) + written = f.write(port_str) + assert written == len(port_str) + os.rename(tmp_filename, fname) + except Exception: + os.unlink(tmp_filename) + raise + + def read(self, fname: str) -> None: + with open(fname) as f: + lines = f.readlines() + if lines[-1] != self.EOF_TOKEN: + return + for ln in lines: + if ln.startswith(self.SOCK_TOKEN): + self._sock_port = int(ln[len(self.SOCK_TOKEN) :]) + self._valid = True + + @property + def sock_port(self) -> Optional[int]: + return self._sock_port + + @property + def is_valid(self) -> bool: + return self._valid diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/server.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/server.py new file mode 100644 index 0000000000000000000000000000000000000000..6d6beae965174049c3d1ada921c3af4ac5047ec7 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/service/server.py @@ -0,0 +1,119 @@ +"""wandb server. + +Start up socket transport servers. +""" + +import logging +import os +import sys +from typing import Optional + +import wandb + +from ..lib import tracelog +from . import _startup_debug, port_file +from .server_sock import SocketServer +from .streams import StreamMux + + +class WandbServer: + _pid: Optional[int] + _sock_port: Optional[int] + _debug: bool + _serve_sock: bool + _sock_server: Optional[SocketServer] + _startup_debug_enabled: bool + + def __init__( + self, + sock_port: Optional[int] = None, + port_fname: Optional[str] = None, + address: Optional[str] = None, + pid: Optional[int] = None, + debug: bool = True, + serve_sock: bool = False, + ) -> None: + self._sock_port = sock_port + self._port_fname = port_fname + self._address = address + self._pid = pid + self._debug = debug + self._serve_sock = serve_sock + self._sock_server = None + self._startup_debug_enabled = _startup_debug.is_enabled() + + if debug: + logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) + + def _inform_used_ports(self, sock_port: Optional[int]) -> None: + if not self._port_fname: + return + pf = port_file.PortFile(sock_port=sock_port) + pf.write(self._port_fname) + + def _start_sock(self, mux: StreamMux) -> int: + address: str = self._address or "127.0.0.1" + port: int = self._sock_port or 0 + self._sock_server = SocketServer(mux=mux, address=address, port=port) + try: + self._sock_server.start() + port = self._sock_server.port + if self._pid: + mux.set_pid(self._pid) + except KeyboardInterrupt: + mux.cleanup() + raise + except Exception: + mux.cleanup() + raise + return port + + def _stop_servers(self) -> None: + if self._sock_server: + self._sock_server.stop() + + def _setup_tracelog(self) -> None: + # TODO: remove this temporary hack, need to find a better way to pass settings + # to the server. for now lets just look at the environment variable we need + tracelog_mode = os.environ.get("WANDB_TRACELOG") + if tracelog_mode: + tracelog.enable(tracelog_mode) + + def _startup_debug_print(self, message: str) -> None: + if not self._startup_debug_enabled: + return + _startup_debug.print_message(message) + + def _setup_proctitle(self, sock_port: Optional[int]) -> None: + # TODO: similar to _setup_tracelog, the internal_process should have + # a better way to have access to settings. + disable_setproctitle = os.environ.get("WANDB__DISABLE_SETPROCTITLE") + if disable_setproctitle: + return + + setproctitle = wandb.util.get_optional_module("setproctitle") + if setproctitle: + service_ver = 2 + pid = str(self._pid or 0) + transport = "s" if sock_port else "g" + port = sock_port or 0 + # this format is similar to wandb_manager token, but it's purely informative now + # (consider unifying this in the future) + service_id = f"{service_ver}-{pid}-{transport}-{port}" + proc_title = f"wandb-service({service_id})" + self._startup_debug_print("before_setproctitle") + setproctitle.setproctitle(proc_title) + self._startup_debug_print("after_setproctitle") + + def serve(self) -> None: + self._setup_tracelog() + mux = StreamMux() + self._startup_debug_print("before_network") + sock_port = self._start_sock(mux=mux) if self._serve_sock else None + self._startup_debug_print("after_network") + self._inform_used_ports(sock_port=sock_port) + self._startup_debug_print("after_inform") + self._setup_proctitle(sock_port=sock_port) + self._startup_debug_print("before_loop") + mux.loop() + self._stop_servers() diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/server_sock.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/server_sock.py new file mode 100644 index 0000000000000000000000000000000000000000..a1261c563cec4c7fe18a0580dbadfa0bb34edca3 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/service/server_sock.py @@ -0,0 +1,276 @@ +import queue +import socket +import threading +import time +from typing import TYPE_CHECKING, Any, Callable, Dict, Optional + +from wandb.proto import wandb_server_pb2 as spb +from wandb.sdk.internal.settings_static import SettingsStatic + +from ..lib import tracelog +from ..lib.sock_client import SockClient, SockClientClosedError +from .streams import StreamMux + +if TYPE_CHECKING: + from threading import Event + + from ..interface.interface_relay import InterfaceRelay + + +class ClientDict: + _client_dict: Dict[str, SockClient] + _lock: threading.Lock + + def __init__(self) -> None: + self._client_dict = {} + self._lock = threading.Lock() + + def get_client(self, client_id: str) -> Optional[SockClient]: + with self._lock: + client = self._client_dict.get(client_id) + return client + + def add_client(self, client: SockClient) -> None: + with self._lock: + self._client_dict[client._sockid] = client + + def del_client(self, client: SockClient) -> None: + with self._lock: + del self._client_dict[client._sockid] + + +class SockServerInterfaceReaderThread(threading.Thread): + _socket_client: SockClient + _stopped: "Event" + + def __init__( + self, clients: ClientDict, iface: "InterfaceRelay", stopped: "Event" + ) -> None: + self._iface = iface + self._clients = clients + threading.Thread.__init__(self) + self.name = "SockSrvIntRdThr" + self._stopped = stopped + + def run(self) -> None: + assert self._iface.relay_q + while not self._stopped.is_set(): + try: + result = self._iface.relay_q.get(timeout=1) + except queue.Empty: + continue + except OSError: + # handle is closed + break + except ValueError: + # queue is closed + break + tracelog.log_message_dequeue(result, self._iface.relay_q) + sockid = result.control.relay_id + assert sockid + sock_client = self._clients.get_client(sockid) + assert sock_client + sresp = spb.ServerResponse() + sresp.result_communicate.CopyFrom(result) + sock_client.send_server_response(sresp) + + +class SockServerReadThread(threading.Thread): + _sock_client: SockClient + _mux: StreamMux + _stopped: "Event" + _clients: ClientDict + + def __init__( + self, conn: socket.socket, mux: StreamMux, clients: ClientDict + ) -> None: + self._mux = mux + threading.Thread.__init__(self) + self.name = "SockSrvRdThr" + sock_client = SockClient() + sock_client.set_socket(conn) + self._sock_client = sock_client + self._stopped = mux._get_stopped_event() + self._clients = clients + + def run(self) -> None: + while not self._stopped.is_set(): + try: + sreq = self._sock_client.read_server_request() + except SockClientClosedError: + # socket has been closed + # TODO: shut down other threads serving this socket? + break + assert sreq, "read_server_request should never timeout" + sreq_type = sreq.WhichOneof("server_request_type") + shandler_str = "server_" + sreq_type # type: ignore + shandler: Callable[[spb.ServerRequest], None] = getattr( # type: ignore + self, shandler_str, None + ) + assert shandler, f"unknown handle: {shandler_str}" # type: ignore + shandler(sreq) + + def stop(self) -> None: + try: + # See shutdown notes in class SocketServer for a discussion about this mechanism + self._sock_client.shutdown(socket.SHUT_RDWR) + except OSError: + pass + self._sock_client.close() + + def server_inform_init(self, sreq: "spb.ServerRequest") -> None: + request = sreq.inform_init + stream_id = request._info.stream_id + settings = SettingsStatic(request.settings) + self._mux.add_stream(stream_id, settings=settings) + + iface = self._mux.get_stream(stream_id).interface + self._clients.add_client(self._sock_client) + iface_reader_thread = SockServerInterfaceReaderThread( + clients=self._clients, + iface=iface, + stopped=self._stopped, + ) + iface_reader_thread.start() + + def server_inform_start(self, sreq: "spb.ServerRequest") -> None: + request = sreq.inform_start + stream_id = request._info.stream_id + settings = SettingsStatic(request.settings) + self._mux.update_stream(stream_id, settings=settings) + self._mux.start_stream(stream_id) + + def server_inform_attach(self, sreq: "spb.ServerRequest") -> None: + request = sreq.inform_attach + stream_id = request._info.stream_id + + self._clients.add_client(self._sock_client) + inform_attach_response = spb.ServerInformAttachResponse() + inform_attach_response.settings.CopyFrom( + self._mux._streams[stream_id]._settings._proto, + ) + response = spb.ServerResponse(inform_attach_response=inform_attach_response) + self._sock_client.send_server_response(response) + iface = self._mux.get_stream(stream_id).interface + + assert iface + + def server_record_communicate(self, sreq: "spb.ServerRequest") -> None: + record = sreq.record_communicate + # encode relay information so the right socket picks up the data + record.control.relay_id = self._sock_client._sockid + stream_id = record._info.stream_id + iface = self._mux.get_stream(stream_id).interface + assert iface.record_q + iface.record_q.put(record) + + def server_record_publish(self, sreq: "spb.ServerRequest") -> None: + record = sreq.record_publish + # encode relay information so the right socket picks up the data + record.control.relay_id = self._sock_client._sockid + stream_id = record._info.stream_id + iface = self._mux.get_stream(stream_id).interface + assert iface.record_q + iface.record_q.put(record) + + def server_inform_finish(self, sreq: "spb.ServerRequest") -> None: + request = sreq.inform_finish + stream_id = request._info.stream_id + self._mux.drop_stream(stream_id) + + def server_inform_teardown(self, sreq: "spb.ServerRequest") -> None: + request = sreq.inform_teardown + exit_code = request.exit_code + self._mux.teardown(exit_code) + + +class SockAcceptThread(threading.Thread): + _sock: socket.socket + _mux: StreamMux + _stopped: "Event" + _clients: ClientDict + + def __init__(self, sock: socket.socket, mux: StreamMux) -> None: + self._sock = sock + self._mux = mux + self._stopped = mux._get_stopped_event() + threading.Thread.__init__(self) + self.name = "SockAcceptThr" + self._clients = ClientDict() + + def run(self) -> None: + read_threads = [] + + while not self._stopped.is_set(): + try: + conn, addr = self._sock.accept() + except ConnectionAbortedError: + break + except OSError: + # on shutdown + break + sr = SockServerReadThread(conn=conn, mux=self._mux, clients=self._clients) + sr.start() + read_threads.append(sr) + + for rt in read_threads: + rt.stop() + + +class DebugThread(threading.Thread): + def __init__(self, mux: "StreamMux") -> None: + threading.Thread.__init__(self) + self.daemon = True + self.name = "DebugThr" + + def run(self) -> None: + while True: + time.sleep(30) + for thread in threading.enumerate(): + print(f"DEBUG: {thread.name}") + + +class SocketServer: + _mux: StreamMux + _address: str + _port: int + _sock: socket.socket + + def __init__(self, mux: Any, address: str, port: int) -> None: + self._mux = mux + self._address = address + self._port = port + # This is the server socket that we accept new connections from + self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + def _bind(self) -> None: + self._sock.bind((self._address, self._port)) + self._port = self._sock.getsockname()[1] + + @property + def port(self) -> int: + return self._port + + def start(self) -> None: + self._bind() + self._sock.listen(5) + self._thread = SockAcceptThread(sock=self._sock, mux=self._mux) + self._thread.start() + # Note: Uncomment to figure out what thread is not exiting properly + # self._dbg_thread = DebugThread(mux=self._mux) + # self._dbg_thread.start() + + def stop(self) -> None: + if self._sock: + # we need to stop the SockAcceptThread + try: + # TODO(jhr): consider a more graceful shutdown in the future + # socket.shutdown() is a more heavy handed approach to interrupting socket.accept() + # in the future we might want to consider a more graceful shutdown which would involve setting + # a threading Event and then initiating one last connection just to close down the thread + # The advantage of the heavy handed approach is that it doesnt depend on the threads functioning + # properly, that is, if something has gone wrong, we probably want to use this hammer to shut things down + self._sock.shutdown(socket.SHUT_RDWR) + except OSError: + pass + self._sock.close() diff --git a/parrot/lib/python3.10/site-packages/wandb/sdk/service/service_sock.py b/parrot/lib/python3.10/site-packages/wandb/sdk/service/service_sock.py new file mode 100644 index 0000000000000000000000000000000000000000..36c21dd89be1f409005e1453a3f298e1cee9ac01 --- /dev/null +++ b/parrot/lib/python3.10/site-packages/wandb/sdk/service/service_sock.py @@ -0,0 +1,70 @@ +"""socket service. + +Implement ServiceInterface for socket transport. +""" + +from typing import TYPE_CHECKING, Optional + +from wandb.proto import wandb_server_pb2 as spb + +from ..lib.sock_client import SockClient +from .service_base import ServiceInterface + +if TYPE_CHECKING: + from wandb.proto import wandb_settings_pb2 + + +class ServiceSockInterface(ServiceInterface): + _sock_client: SockClient + + def __init__(self) -> None: + self._sock_client = SockClient() + + def get_transport(self) -> str: + return "tcp" + + def _get_sock_client(self) -> SockClient: + return self._sock_client + + def _svc_connect(self, port: int) -> None: + self._sock_client.connect(port=port) + + def _svc_inform_init( + self, settings: "wandb_settings_pb2.Settings", run_id: str + ) -> None: + inform_init = spb.ServerInformInitRequest() + inform_init.settings.CopyFrom(settings) + inform_init._info.stream_id = run_id + assert self._sock_client + self._sock_client.send(inform_init=inform_init) + + def _svc_inform_start( + self, settings: "wandb_settings_pb2.Settings", run_id: str + ) -> None: + inform_start = spb.ServerInformStartRequest() + inform_start.settings.CopyFrom(settings) + inform_start._info.stream_id = run_id + assert self._sock_client + self._sock_client.send(inform_start=inform_start) + + def _svc_inform_finish(self, run_id: Optional[str] = None) -> None: + assert run_id + inform_finish = spb.ServerInformFinishRequest() + inform_finish._info.stream_id = run_id + + assert self._sock_client + self._sock_client.send(inform_finish=inform_finish) + + def _svc_inform_attach(self, attach_id: str) -> spb.ServerInformAttachResponse: + inform_attach = spb.ServerInformAttachRequest() + inform_attach._info.stream_id = attach_id + + assert self._sock_client + response = self._sock_client.send_and_recv(inform_attach=inform_attach) + return response.inform_attach_response + + def _svc_inform_teardown(self, exit_code: int) -> None: + inform_teardown = spb.ServerInformTeardownRequest(exit_code=exit_code) + + assert self._sock_client + self._sock_client.send(inform_teardown=inform_teardown)