wandb 0.19.1rc1__py3-none-musllinux_1_2_aarch64.whl
Sign up to get free protection for your applications and to get access to all the features.
- package_readme.md +97 -0
- wandb/__init__.py +252 -0
- wandb/__init__.pyi +1197 -0
- wandb/__main__.py +3 -0
- wandb/_globals.py +19 -0
- wandb/agents/__init__.py +0 -0
- wandb/agents/pyagent.py +363 -0
- wandb/analytics/__init__.py +3 -0
- wandb/analytics/sentry.py +263 -0
- wandb/apis/__init__.py +48 -0
- wandb/apis/attrs.py +51 -0
- wandb/apis/importers/__init__.py +1 -0
- wandb/apis/importers/internals/internal.py +385 -0
- wandb/apis/importers/internals/protocols.py +103 -0
- wandb/apis/importers/internals/util.py +78 -0
- wandb/apis/importers/mlflow.py +254 -0
- wandb/apis/importers/validation.py +108 -0
- wandb/apis/importers/wandb.py +1603 -0
- wandb/apis/internal.py +232 -0
- wandb/apis/normalize.py +73 -0
- wandb/apis/paginator.py +81 -0
- wandb/apis/public/__init__.py +34 -0
- wandb/apis/public/api.py +1387 -0
- wandb/apis/public/artifacts.py +1095 -0
- wandb/apis/public/const.py +4 -0
- wandb/apis/public/files.py +263 -0
- wandb/apis/public/history.py +149 -0
- wandb/apis/public/jobs.py +653 -0
- wandb/apis/public/projects.py +154 -0
- wandb/apis/public/query_generator.py +166 -0
- wandb/apis/public/reports.py +458 -0
- wandb/apis/public/runs.py +1012 -0
- wandb/apis/public/sweeps.py +240 -0
- wandb/apis/public/teams.py +198 -0
- wandb/apis/public/users.py +136 -0
- wandb/apis/public/utils.py +68 -0
- wandb/apis/reports/__init__.py +1 -0
- wandb/apis/reports/v1/__init__.py +8 -0
- wandb/apis/reports/v2/__init__.py +8 -0
- wandb/apis/workspaces/__init__.py +8 -0
- wandb/beta/workflows.py +288 -0
- wandb/bin/gpu_stats +0 -0
- wandb/bin/wandb-core +0 -0
- wandb/cli/__init__.py +0 -0
- wandb/cli/beta.py +178 -0
- wandb/cli/cli.py +2812 -0
- wandb/data_types.py +66 -0
- wandb/docker/__init__.py +343 -0
- wandb/docker/auth.py +435 -0
- wandb/docker/wandb-entrypoint.sh +33 -0
- wandb/docker/www_authenticate.py +94 -0
- wandb/env.py +513 -0
- wandb/errors/__init__.py +17 -0
- wandb/errors/errors.py +37 -0
- wandb/errors/links.py +73 -0
- wandb/errors/term.py +415 -0
- wandb/errors/util.py +57 -0
- wandb/errors/warnings.py +2 -0
- wandb/filesync/__init__.py +0 -0
- wandb/filesync/dir_watcher.py +403 -0
- wandb/filesync/stats.py +100 -0
- wandb/filesync/step_checksum.py +142 -0
- wandb/filesync/step_prepare.py +179 -0
- wandb/filesync/step_upload.py +287 -0
- wandb/filesync/upload_job.py +142 -0
- wandb/integration/__init__.py +0 -0
- wandb/integration/catboost/__init__.py +5 -0
- wandb/integration/catboost/catboost.py +178 -0
- wandb/integration/cohere/__init__.py +3 -0
- wandb/integration/cohere/cohere.py +21 -0
- wandb/integration/cohere/resolver.py +347 -0
- wandb/integration/diffusers/__init__.py +3 -0
- wandb/integration/diffusers/autologger.py +76 -0
- wandb/integration/diffusers/pipeline_resolver.py +50 -0
- wandb/integration/diffusers/resolvers/__init__.py +9 -0
- wandb/integration/diffusers/resolvers/multimodal.py +882 -0
- wandb/integration/diffusers/resolvers/utils.py +102 -0
- wandb/integration/fastai/__init__.py +245 -0
- wandb/integration/gym/__init__.py +99 -0
- wandb/integration/huggingface/__init__.py +3 -0
- wandb/integration/huggingface/huggingface.py +18 -0
- wandb/integration/huggingface/resolver.py +213 -0
- wandb/integration/keras/__init__.py +11 -0
- wandb/integration/keras/callbacks/__init__.py +5 -0
- wandb/integration/keras/callbacks/metrics_logger.py +129 -0
- wandb/integration/keras/callbacks/model_checkpoint.py +188 -0
- wandb/integration/keras/callbacks/tables_builder.py +228 -0
- wandb/integration/keras/keras.py +1089 -0
- wandb/integration/kfp/__init__.py +6 -0
- wandb/integration/kfp/helpers.py +28 -0
- wandb/integration/kfp/kfp_patch.py +334 -0
- wandb/integration/kfp/wandb_logging.py +182 -0
- wandb/integration/langchain/__init__.py +3 -0
- wandb/integration/langchain/wandb_tracer.py +48 -0
- wandb/integration/lightgbm/__init__.py +239 -0
- wandb/integration/lightning/__init__.py +0 -0
- wandb/integration/lightning/fabric/__init__.py +3 -0
- wandb/integration/lightning/fabric/logger.py +764 -0
- wandb/integration/metaflow/__init__.py +3 -0
- wandb/integration/metaflow/metaflow.py +383 -0
- wandb/integration/openai/__init__.py +3 -0
- wandb/integration/openai/fine_tuning.py +480 -0
- wandb/integration/openai/openai.py +22 -0
- wandb/integration/openai/resolver.py +240 -0
- wandb/integration/prodigy/__init__.py +3 -0
- wandb/integration/prodigy/prodigy.py +299 -0
- wandb/integration/sacred/__init__.py +117 -0
- wandb/integration/sagemaker/__init__.py +12 -0
- wandb/integration/sagemaker/auth.py +28 -0
- wandb/integration/sagemaker/config.py +49 -0
- wandb/integration/sagemaker/files.py +3 -0
- wandb/integration/sagemaker/resources.py +34 -0
- wandb/integration/sb3/__init__.py +3 -0
- wandb/integration/sb3/sb3.py +147 -0
- wandb/integration/sklearn/__init__.py +37 -0
- wandb/integration/sklearn/calculate/__init__.py +32 -0
- wandb/integration/sklearn/calculate/calibration_curves.py +125 -0
- wandb/integration/sklearn/calculate/class_proportions.py +68 -0
- wandb/integration/sklearn/calculate/confusion_matrix.py +93 -0
- wandb/integration/sklearn/calculate/decision_boundaries.py +40 -0
- wandb/integration/sklearn/calculate/elbow_curve.py +55 -0
- wandb/integration/sklearn/calculate/feature_importances.py +67 -0
- wandb/integration/sklearn/calculate/learning_curve.py +64 -0
- wandb/integration/sklearn/calculate/outlier_candidates.py +69 -0
- wandb/integration/sklearn/calculate/residuals.py +86 -0
- wandb/integration/sklearn/calculate/silhouette.py +118 -0
- wandb/integration/sklearn/calculate/summary_metrics.py +62 -0
- wandb/integration/sklearn/plot/__init__.py +35 -0
- wandb/integration/sklearn/plot/classifier.py +329 -0
- wandb/integration/sklearn/plot/clusterer.py +146 -0
- wandb/integration/sklearn/plot/regressor.py +121 -0
- wandb/integration/sklearn/plot/shared.py +91 -0
- wandb/integration/sklearn/utils.py +183 -0
- wandb/integration/tensorboard/__init__.py +10 -0
- wandb/integration/tensorboard/log.py +354 -0
- wandb/integration/tensorboard/monkeypatch.py +186 -0
- wandb/integration/tensorflow/__init__.py +5 -0
- wandb/integration/tensorflow/estimator_hook.py +54 -0
- wandb/integration/torch/__init__.py +0 -0
- wandb/integration/torch/wandb_torch.py +554 -0
- wandb/integration/ultralytics/__init__.py +11 -0
- wandb/integration/ultralytics/bbox_utils.py +215 -0
- wandb/integration/ultralytics/callback.py +524 -0
- wandb/integration/ultralytics/classification_utils.py +83 -0
- wandb/integration/ultralytics/mask_utils.py +202 -0
- wandb/integration/ultralytics/pose_utils.py +103 -0
- wandb/integration/xgboost/__init__.py +11 -0
- wandb/integration/xgboost/xgboost.py +189 -0
- wandb/integration/yolov8/__init__.py +0 -0
- wandb/integration/yolov8/yolov8.py +284 -0
- wandb/jupyter.py +513 -0
- wandb/mpmain/__init__.py +0 -0
- wandb/mpmain/__main__.py +1 -0
- wandb/old/__init__.py +0 -0
- wandb/old/core.py +53 -0
- wandb/old/settings.py +173 -0
- wandb/old/summary.py +440 -0
- wandb/plot/__init__.py +28 -0
- wandb/plot/bar.py +70 -0
- wandb/plot/confusion_matrix.py +181 -0
- wandb/plot/custom_chart.py +124 -0
- wandb/plot/histogram.py +65 -0
- wandb/plot/line.py +74 -0
- wandb/plot/line_series.py +176 -0
- wandb/plot/pr_curve.py +185 -0
- wandb/plot/roc_curve.py +163 -0
- wandb/plot/scatter.py +66 -0
- wandb/plot/utils.py +183 -0
- wandb/plot/viz.py +41 -0
- wandb/proto/__init__.py +0 -0
- wandb/proto/v3/__init__.py +0 -0
- wandb/proto/v3/wandb_base_pb2.py +55 -0
- wandb/proto/v3/wandb_internal_pb2.py +1658 -0
- wandb/proto/v3/wandb_server_pb2.py +228 -0
- wandb/proto/v3/wandb_settings_pb2.py +122 -0
- wandb/proto/v3/wandb_telemetry_pb2.py +106 -0
- wandb/proto/v4/__init__.py +0 -0
- wandb/proto/v4/wandb_base_pb2.py +30 -0
- wandb/proto/v4/wandb_internal_pb2.py +370 -0
- wandb/proto/v4/wandb_server_pb2.py +67 -0
- wandb/proto/v4/wandb_settings_pb2.py +47 -0
- wandb/proto/v4/wandb_telemetry_pb2.py +41 -0
- wandb/proto/v5/wandb_base_pb2.py +31 -0
- wandb/proto/v5/wandb_internal_pb2.py +371 -0
- wandb/proto/v5/wandb_server_pb2.py +68 -0
- wandb/proto/v5/wandb_settings_pb2.py +48 -0
- wandb/proto/v5/wandb_telemetry_pb2.py +42 -0
- wandb/proto/wandb_base_pb2.py +10 -0
- wandb/proto/wandb_deprecated.py +45 -0
- wandb/proto/wandb_generate_deprecated.py +30 -0
- wandb/proto/wandb_generate_proto.py +49 -0
- wandb/proto/wandb_internal_pb2.py +16 -0
- wandb/proto/wandb_server_pb2.py +10 -0
- wandb/proto/wandb_settings_pb2.py +10 -0
- wandb/proto/wandb_telemetry_pb2.py +10 -0
- wandb/py.typed +0 -0
- wandb/sdk/__init__.py +37 -0
- wandb/sdk/artifacts/__init__.py +0 -0
- wandb/sdk/artifacts/_validators.py +121 -0
- wandb/sdk/artifacts/artifact.py +2364 -0
- wandb/sdk/artifacts/artifact_download_logger.py +43 -0
- wandb/sdk/artifacts/artifact_file_cache.py +249 -0
- wandb/sdk/artifacts/artifact_instance_cache.py +17 -0
- wandb/sdk/artifacts/artifact_manifest.py +75 -0
- wandb/sdk/artifacts/artifact_manifest_entry.py +249 -0
- wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
- wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +92 -0
- wandb/sdk/artifacts/artifact_saver.py +265 -0
- wandb/sdk/artifacts/artifact_state.py +11 -0
- wandb/sdk/artifacts/artifact_ttl.py +7 -0
- wandb/sdk/artifacts/exceptions.py +57 -0
- wandb/sdk/artifacts/staging.py +25 -0
- wandb/sdk/artifacts/storage_handler.py +62 -0
- wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
- wandb/sdk/artifacts/storage_handlers/azure_handler.py +213 -0
- wandb/sdk/artifacts/storage_handlers/gcs_handler.py +224 -0
- wandb/sdk/artifacts/storage_handlers/http_handler.py +114 -0
- wandb/sdk/artifacts/storage_handlers/local_file_handler.py +139 -0
- wandb/sdk/artifacts/storage_handlers/multi_handler.py +56 -0
- wandb/sdk/artifacts/storage_handlers/s3_handler.py +298 -0
- wandb/sdk/artifacts/storage_handlers/tracking_handler.py +72 -0
- wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +135 -0
- wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +74 -0
- wandb/sdk/artifacts/storage_layout.py +6 -0
- wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
- wandb/sdk/artifacts/storage_policies/register.py +1 -0
- wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +378 -0
- wandb/sdk/artifacts/storage_policy.py +72 -0
- wandb/sdk/backend/__init__.py +0 -0
- wandb/sdk/backend/backend.py +221 -0
- wandb/sdk/data_types/__init__.py +0 -0
- wandb/sdk/data_types/_dtypes.py +918 -0
- wandb/sdk/data_types/_private.py +10 -0
- wandb/sdk/data_types/audio.py +165 -0
- wandb/sdk/data_types/base_types/__init__.py +0 -0
- wandb/sdk/data_types/base_types/json_metadata.py +55 -0
- wandb/sdk/data_types/base_types/media.py +376 -0
- wandb/sdk/data_types/base_types/wb_value.py +282 -0
- wandb/sdk/data_types/bokeh.py +70 -0
- wandb/sdk/data_types/graph.py +405 -0
- wandb/sdk/data_types/helper_types/__init__.py +0 -0
- wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +305 -0
- wandb/sdk/data_types/helper_types/classes.py +159 -0
- wandb/sdk/data_types/helper_types/image_mask.py +241 -0
- wandb/sdk/data_types/histogram.py +94 -0
- wandb/sdk/data_types/html.py +115 -0
- wandb/sdk/data_types/image.py +847 -0
- wandb/sdk/data_types/molecule.py +241 -0
- wandb/sdk/data_types/object_3d.py +470 -0
- wandb/sdk/data_types/plotly.py +82 -0
- wandb/sdk/data_types/saved_model.py +445 -0
- wandb/sdk/data_types/table.py +1204 -0
- wandb/sdk/data_types/trace_tree.py +438 -0
- wandb/sdk/data_types/utils.py +228 -0
- wandb/sdk/data_types/video.py +268 -0
- wandb/sdk/integration_utils/__init__.py +0 -0
- wandb/sdk/integration_utils/auto_logging.py +232 -0
- wandb/sdk/integration_utils/data_logging.py +475 -0
- wandb/sdk/interface/__init__.py +0 -0
- wandb/sdk/interface/constants.py +4 -0
- wandb/sdk/interface/interface.py +1010 -0
- wandb/sdk/interface/interface_queue.py +53 -0
- wandb/sdk/interface/interface_relay.py +53 -0
- wandb/sdk/interface/interface_shared.py +546 -0
- wandb/sdk/interface/interface_sock.py +61 -0
- wandb/sdk/interface/message_future.py +27 -0
- wandb/sdk/interface/message_future_poll.py +50 -0
- wandb/sdk/interface/router.py +115 -0
- wandb/sdk/interface/router_queue.py +41 -0
- wandb/sdk/interface/router_relay.py +37 -0
- wandb/sdk/interface/router_sock.py +36 -0
- wandb/sdk/interface/summary_record.py +67 -0
- wandb/sdk/internal/__init__.py +0 -0
- wandb/sdk/internal/context.py +89 -0
- wandb/sdk/internal/datastore.py +297 -0
- wandb/sdk/internal/file_pusher.py +181 -0
- wandb/sdk/internal/file_stream.py +695 -0
- wandb/sdk/internal/flow_control.py +263 -0
- wandb/sdk/internal/handler.py +905 -0
- wandb/sdk/internal/internal.py +403 -0
- wandb/sdk/internal/internal_api.py +4587 -0
- wandb/sdk/internal/internal_util.py +97 -0
- wandb/sdk/internal/job_builder.py +638 -0
- wandb/sdk/internal/profiler.py +78 -0
- wandb/sdk/internal/progress.py +79 -0
- wandb/sdk/internal/run.py +25 -0
- wandb/sdk/internal/sample.py +70 -0
- wandb/sdk/internal/sender.py +1696 -0
- wandb/sdk/internal/sender_config.py +197 -0
- wandb/sdk/internal/settings_static.py +97 -0
- wandb/sdk/internal/system/__init__.py +0 -0
- wandb/sdk/internal/system/assets/__init__.py +25 -0
- wandb/sdk/internal/system/assets/aggregators.py +37 -0
- wandb/sdk/internal/system/assets/asset_registry.py +20 -0
- wandb/sdk/internal/system/assets/cpu.py +163 -0
- wandb/sdk/internal/system/assets/disk.py +210 -0
- wandb/sdk/internal/system/assets/gpu.py +416 -0
- wandb/sdk/internal/system/assets/gpu_amd.py +233 -0
- wandb/sdk/internal/system/assets/interfaces.py +205 -0
- wandb/sdk/internal/system/assets/ipu.py +177 -0
- wandb/sdk/internal/system/assets/memory.py +166 -0
- wandb/sdk/internal/system/assets/network.py +125 -0
- wandb/sdk/internal/system/assets/open_metrics.py +293 -0
- wandb/sdk/internal/system/assets/tpu.py +154 -0
- wandb/sdk/internal/system/assets/trainium.py +393 -0
- wandb/sdk/internal/system/env_probe_helpers.py +13 -0
- wandb/sdk/internal/system/system_info.py +250 -0
- wandb/sdk/internal/system/system_monitor.py +222 -0
- wandb/sdk/internal/tb_watcher.py +519 -0
- wandb/sdk/internal/thread_local_settings.py +18 -0
- wandb/sdk/internal/writer.py +204 -0
- wandb/sdk/launch/__init__.py +15 -0
- wandb/sdk/launch/_launch.py +331 -0
- wandb/sdk/launch/_launch_add.py +255 -0
- wandb/sdk/launch/_project_spec.py +566 -0
- wandb/sdk/launch/agent/__init__.py +5 -0
- wandb/sdk/launch/agent/agent.py +924 -0
- wandb/sdk/launch/agent/config.py +296 -0
- wandb/sdk/launch/agent/job_status_tracker.py +53 -0
- wandb/sdk/launch/agent/run_queue_item_file_saver.py +39 -0
- wandb/sdk/launch/builder/__init__.py +0 -0
- wandb/sdk/launch/builder/abstract.py +156 -0
- wandb/sdk/launch/builder/build.py +297 -0
- wandb/sdk/launch/builder/context_manager.py +235 -0
- wandb/sdk/launch/builder/docker_builder.py +177 -0
- wandb/sdk/launch/builder/kaniko_builder.py +594 -0
- wandb/sdk/launch/builder/noop.py +58 -0
- wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +188 -0
- wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
- wandb/sdk/launch/create_job.py +528 -0
- wandb/sdk/launch/environment/abstract.py +29 -0
- wandb/sdk/launch/environment/aws_environment.py +322 -0
- wandb/sdk/launch/environment/azure_environment.py +105 -0
- wandb/sdk/launch/environment/gcp_environment.py +335 -0
- wandb/sdk/launch/environment/local_environment.py +65 -0
- wandb/sdk/launch/errors.py +13 -0
- wandb/sdk/launch/git_reference.py +109 -0
- wandb/sdk/launch/inputs/files.py +148 -0
- wandb/sdk/launch/inputs/internal.py +315 -0
- wandb/sdk/launch/inputs/manage.py +113 -0
- wandb/sdk/launch/inputs/schema.py +39 -0
- wandb/sdk/launch/loader.py +249 -0
- wandb/sdk/launch/registry/abstract.py +48 -0
- wandb/sdk/launch/registry/anon.py +29 -0
- wandb/sdk/launch/registry/azure_container_registry.py +124 -0
- wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
- wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
- wandb/sdk/launch/registry/local_registry.py +65 -0
- wandb/sdk/launch/runner/__init__.py +0 -0
- wandb/sdk/launch/runner/abstract.py +185 -0
- wandb/sdk/launch/runner/kubernetes_monitor.py +472 -0
- wandb/sdk/launch/runner/kubernetes_runner.py +963 -0
- wandb/sdk/launch/runner/local_container.py +301 -0
- wandb/sdk/launch/runner/local_process.py +78 -0
- wandb/sdk/launch/runner/sagemaker_runner.py +426 -0
- wandb/sdk/launch/runner/vertex_runner.py +230 -0
- wandb/sdk/launch/sweeps/__init__.py +37 -0
- wandb/sdk/launch/sweeps/scheduler.py +740 -0
- wandb/sdk/launch/sweeps/scheduler_sweep.py +90 -0
- wandb/sdk/launch/sweeps/utils.py +316 -0
- wandb/sdk/launch/utils.py +747 -0
- wandb/sdk/launch/wandb_reference.py +138 -0
- wandb/sdk/lib/__init__.py +5 -0
- wandb/sdk/lib/apikey.py +269 -0
- wandb/sdk/lib/capped_dict.py +26 -0
- wandb/sdk/lib/config_util.py +101 -0
- wandb/sdk/lib/credentials.py +141 -0
- wandb/sdk/lib/deprecate.py +42 -0
- wandb/sdk/lib/disabled.py +29 -0
- wandb/sdk/lib/exit_hooks.py +54 -0
- wandb/sdk/lib/file_stream_utils.py +118 -0
- wandb/sdk/lib/filenames.py +64 -0
- wandb/sdk/lib/filesystem.py +372 -0
- wandb/sdk/lib/fsm.py +180 -0
- wandb/sdk/lib/gitlib.py +239 -0
- wandb/sdk/lib/gql_request.py +65 -0
- wandb/sdk/lib/handler_util.py +21 -0
- wandb/sdk/lib/hashutil.py +84 -0
- wandb/sdk/lib/import_hooks.py +275 -0
- wandb/sdk/lib/ipython.py +126 -0
- wandb/sdk/lib/json_util.py +80 -0
- wandb/sdk/lib/lazyloader.py +63 -0
- wandb/sdk/lib/mailbox.py +456 -0
- wandb/sdk/lib/module.py +78 -0
- wandb/sdk/lib/paths.py +106 -0
- wandb/sdk/lib/preinit.py +42 -0
- wandb/sdk/lib/printer.py +548 -0
- wandb/sdk/lib/progress.py +273 -0
- wandb/sdk/lib/proto_util.py +90 -0
- wandb/sdk/lib/redirect.py +845 -0
- wandb/sdk/lib/retry.py +289 -0
- wandb/sdk/lib/run_moment.py +72 -0
- wandb/sdk/lib/runid.py +12 -0
- wandb/sdk/lib/server.py +38 -0
- wandb/sdk/lib/service_connection.py +216 -0
- wandb/sdk/lib/service_token.py +94 -0
- wandb/sdk/lib/sock_client.py +290 -0
- wandb/sdk/lib/sparkline.py +44 -0
- wandb/sdk/lib/telemetry.py +100 -0
- wandb/sdk/lib/timed_input.py +133 -0
- wandb/sdk/lib/timer.py +19 -0
- wandb/sdk/service/__init__.py +0 -0
- wandb/sdk/service/_startup_debug.py +22 -0
- wandb/sdk/service/port_file.py +53 -0
- wandb/sdk/service/server.py +107 -0
- wandb/sdk/service/server_sock.py +274 -0
- wandb/sdk/service/service.py +242 -0
- wandb/sdk/service/streams.py +425 -0
- wandb/sdk/verify/__init__.py +0 -0
- wandb/sdk/verify/verify.py +501 -0
- wandb/sdk/wandb_alerts.py +12 -0
- wandb/sdk/wandb_config.py +322 -0
- wandb/sdk/wandb_helper.py +54 -0
- wandb/sdk/wandb_init.py +1313 -0
- wandb/sdk/wandb_login.py +339 -0
- wandb/sdk/wandb_metric.py +110 -0
- wandb/sdk/wandb_require.py +94 -0
- wandb/sdk/wandb_require_helpers.py +44 -0
- wandb/sdk/wandb_run.py +4066 -0
- wandb/sdk/wandb_settings.py +1309 -0
- wandb/sdk/wandb_setup.py +402 -0
- wandb/sdk/wandb_summary.py +150 -0
- wandb/sdk/wandb_sweep.py +119 -0
- wandb/sdk/wandb_sync.py +82 -0
- wandb/sdk/wandb_watch.py +150 -0
- wandb/sklearn.py +35 -0
- wandb/sync/__init__.py +3 -0
- wandb/sync/sync.py +442 -0
- wandb/trigger.py +29 -0
- wandb/util.py +1955 -0
- wandb/vendor/__init__.py +0 -0
- wandb/vendor/gql-0.2.0/setup.py +40 -0
- wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
- wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
- wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
- wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
- wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
- wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
- wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
- wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
- wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
- wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
- wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
- wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
- wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
- wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
- wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
- wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
- wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
- wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
- wandb/vendor/graphql-core-1.1/setup.py +86 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
- wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
- wandb/vendor/promise-2.3.0/conftest.py +30 -0
- wandb/vendor/promise-2.3.0/setup.py +64 -0
- wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
- wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
- wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
- wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
- wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
- wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
- wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
- wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
- wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
- wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
- wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
- wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
- wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
- wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
- wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
- wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
- wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
- wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
- wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
- wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
- wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
- wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
- wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
- wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
- wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
- wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
- wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
- wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
- wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
- wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
- wandb/vendor/pygments/__init__.py +90 -0
- wandb/vendor/pygments/cmdline.py +568 -0
- wandb/vendor/pygments/console.py +74 -0
- wandb/vendor/pygments/filter.py +74 -0
- wandb/vendor/pygments/filters/__init__.py +350 -0
- wandb/vendor/pygments/formatter.py +95 -0
- wandb/vendor/pygments/formatters/__init__.py +153 -0
- wandb/vendor/pygments/formatters/_mapping.py +85 -0
- wandb/vendor/pygments/formatters/bbcode.py +109 -0
- wandb/vendor/pygments/formatters/html.py +851 -0
- wandb/vendor/pygments/formatters/img.py +600 -0
- wandb/vendor/pygments/formatters/irc.py +182 -0
- wandb/vendor/pygments/formatters/latex.py +482 -0
- wandb/vendor/pygments/formatters/other.py +160 -0
- wandb/vendor/pygments/formatters/rtf.py +147 -0
- wandb/vendor/pygments/formatters/svg.py +153 -0
- wandb/vendor/pygments/formatters/terminal.py +136 -0
- wandb/vendor/pygments/formatters/terminal256.py +309 -0
- wandb/vendor/pygments/lexer.py +871 -0
- wandb/vendor/pygments/lexers/__init__.py +329 -0
- wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
- wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
- wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
- wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
- wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
- wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
- wandb/vendor/pygments/lexers/_mapping.py +500 -0
- wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
- wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
- wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
- wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
- wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
- wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
- wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
- wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
- wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
- wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
- wandb/vendor/pygments/lexers/actionscript.py +240 -0
- wandb/vendor/pygments/lexers/agile.py +24 -0
- wandb/vendor/pygments/lexers/algebra.py +221 -0
- wandb/vendor/pygments/lexers/ambient.py +76 -0
- wandb/vendor/pygments/lexers/ampl.py +87 -0
- wandb/vendor/pygments/lexers/apl.py +101 -0
- wandb/vendor/pygments/lexers/archetype.py +318 -0
- wandb/vendor/pygments/lexers/asm.py +641 -0
- wandb/vendor/pygments/lexers/automation.py +374 -0
- wandb/vendor/pygments/lexers/basic.py +500 -0
- wandb/vendor/pygments/lexers/bibtex.py +160 -0
- wandb/vendor/pygments/lexers/business.py +612 -0
- wandb/vendor/pygments/lexers/c_cpp.py +252 -0
- wandb/vendor/pygments/lexers/c_like.py +541 -0
- wandb/vendor/pygments/lexers/capnproto.py +78 -0
- wandb/vendor/pygments/lexers/chapel.py +102 -0
- wandb/vendor/pygments/lexers/clean.py +288 -0
- wandb/vendor/pygments/lexers/compiled.py +34 -0
- wandb/vendor/pygments/lexers/configs.py +833 -0
- wandb/vendor/pygments/lexers/console.py +114 -0
- wandb/vendor/pygments/lexers/crystal.py +393 -0
- wandb/vendor/pygments/lexers/csound.py +366 -0
- wandb/vendor/pygments/lexers/css.py +689 -0
- wandb/vendor/pygments/lexers/d.py +251 -0
- wandb/vendor/pygments/lexers/dalvik.py +125 -0
- wandb/vendor/pygments/lexers/data.py +555 -0
- wandb/vendor/pygments/lexers/diff.py +165 -0
- wandb/vendor/pygments/lexers/dotnet.py +691 -0
- wandb/vendor/pygments/lexers/dsls.py +878 -0
- wandb/vendor/pygments/lexers/dylan.py +289 -0
- wandb/vendor/pygments/lexers/ecl.py +125 -0
- wandb/vendor/pygments/lexers/eiffel.py +65 -0
- wandb/vendor/pygments/lexers/elm.py +121 -0
- wandb/vendor/pygments/lexers/erlang.py +533 -0
- wandb/vendor/pygments/lexers/esoteric.py +277 -0
- wandb/vendor/pygments/lexers/ezhil.py +69 -0
- wandb/vendor/pygments/lexers/factor.py +344 -0
- wandb/vendor/pygments/lexers/fantom.py +250 -0
- wandb/vendor/pygments/lexers/felix.py +273 -0
- wandb/vendor/pygments/lexers/forth.py +177 -0
- wandb/vendor/pygments/lexers/fortran.py +205 -0
- wandb/vendor/pygments/lexers/foxpro.py +428 -0
- wandb/vendor/pygments/lexers/functional.py +21 -0
- wandb/vendor/pygments/lexers/go.py +101 -0
- wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
- wandb/vendor/pygments/lexers/graph.py +80 -0
- wandb/vendor/pygments/lexers/graphics.py +553 -0
- wandb/vendor/pygments/lexers/haskell.py +843 -0
- wandb/vendor/pygments/lexers/haxe.py +936 -0
- wandb/vendor/pygments/lexers/hdl.py +382 -0
- wandb/vendor/pygments/lexers/hexdump.py +103 -0
- wandb/vendor/pygments/lexers/html.py +602 -0
- wandb/vendor/pygments/lexers/idl.py +270 -0
- wandb/vendor/pygments/lexers/igor.py +288 -0
- wandb/vendor/pygments/lexers/inferno.py +96 -0
- wandb/vendor/pygments/lexers/installers.py +322 -0
- wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
- wandb/vendor/pygments/lexers/iolang.py +63 -0
- wandb/vendor/pygments/lexers/j.py +146 -0
- wandb/vendor/pygments/lexers/javascript.py +1525 -0
- wandb/vendor/pygments/lexers/julia.py +333 -0
- wandb/vendor/pygments/lexers/jvm.py +1573 -0
- wandb/vendor/pygments/lexers/lisp.py +2621 -0
- wandb/vendor/pygments/lexers/make.py +202 -0
- wandb/vendor/pygments/lexers/markup.py +595 -0
- wandb/vendor/pygments/lexers/math.py +21 -0
- wandb/vendor/pygments/lexers/matlab.py +663 -0
- wandb/vendor/pygments/lexers/ml.py +769 -0
- wandb/vendor/pygments/lexers/modeling.py +358 -0
- wandb/vendor/pygments/lexers/modula2.py +1561 -0
- wandb/vendor/pygments/lexers/monte.py +204 -0
- wandb/vendor/pygments/lexers/ncl.py +894 -0
- wandb/vendor/pygments/lexers/nimrod.py +159 -0
- wandb/vendor/pygments/lexers/nit.py +64 -0
- wandb/vendor/pygments/lexers/nix.py +136 -0
- wandb/vendor/pygments/lexers/oberon.py +105 -0
- wandb/vendor/pygments/lexers/objective.py +504 -0
- wandb/vendor/pygments/lexers/ooc.py +85 -0
- wandb/vendor/pygments/lexers/other.py +41 -0
- wandb/vendor/pygments/lexers/parasail.py +79 -0
- wandb/vendor/pygments/lexers/parsers.py +835 -0
- wandb/vendor/pygments/lexers/pascal.py +644 -0
- wandb/vendor/pygments/lexers/pawn.py +199 -0
- wandb/vendor/pygments/lexers/perl.py +620 -0
- wandb/vendor/pygments/lexers/php.py +267 -0
- wandb/vendor/pygments/lexers/praat.py +294 -0
- wandb/vendor/pygments/lexers/prolog.py +306 -0
- wandb/vendor/pygments/lexers/python.py +939 -0
- wandb/vendor/pygments/lexers/qvt.py +152 -0
- wandb/vendor/pygments/lexers/r.py +453 -0
- wandb/vendor/pygments/lexers/rdf.py +270 -0
- wandb/vendor/pygments/lexers/rebol.py +431 -0
- wandb/vendor/pygments/lexers/resource.py +85 -0
- wandb/vendor/pygments/lexers/rnc.py +67 -0
- wandb/vendor/pygments/lexers/roboconf.py +82 -0
- wandb/vendor/pygments/lexers/robotframework.py +560 -0
- wandb/vendor/pygments/lexers/ruby.py +519 -0
- wandb/vendor/pygments/lexers/rust.py +220 -0
- wandb/vendor/pygments/lexers/sas.py +228 -0
- wandb/vendor/pygments/lexers/scripting.py +1222 -0
- wandb/vendor/pygments/lexers/shell.py +794 -0
- wandb/vendor/pygments/lexers/smalltalk.py +195 -0
- wandb/vendor/pygments/lexers/smv.py +79 -0
- wandb/vendor/pygments/lexers/snobol.py +83 -0
- wandb/vendor/pygments/lexers/special.py +103 -0
- wandb/vendor/pygments/lexers/sql.py +681 -0
- wandb/vendor/pygments/lexers/stata.py +108 -0
- wandb/vendor/pygments/lexers/supercollider.py +90 -0
- wandb/vendor/pygments/lexers/tcl.py +145 -0
- wandb/vendor/pygments/lexers/templates.py +2283 -0
- wandb/vendor/pygments/lexers/testing.py +207 -0
- wandb/vendor/pygments/lexers/text.py +25 -0
- wandb/vendor/pygments/lexers/textedit.py +169 -0
- wandb/vendor/pygments/lexers/textfmts.py +297 -0
- wandb/vendor/pygments/lexers/theorem.py +458 -0
- wandb/vendor/pygments/lexers/trafficscript.py +54 -0
- wandb/vendor/pygments/lexers/typoscript.py +226 -0
- wandb/vendor/pygments/lexers/urbi.py +133 -0
- wandb/vendor/pygments/lexers/varnish.py +190 -0
- wandb/vendor/pygments/lexers/verification.py +111 -0
- wandb/vendor/pygments/lexers/web.py +24 -0
- wandb/vendor/pygments/lexers/webmisc.py +988 -0
- wandb/vendor/pygments/lexers/whiley.py +116 -0
- wandb/vendor/pygments/lexers/x10.py +69 -0
- wandb/vendor/pygments/modeline.py +44 -0
- wandb/vendor/pygments/plugin.py +68 -0
- wandb/vendor/pygments/regexopt.py +92 -0
- wandb/vendor/pygments/scanner.py +105 -0
- wandb/vendor/pygments/sphinxext.py +158 -0
- wandb/vendor/pygments/style.py +155 -0
- wandb/vendor/pygments/styles/__init__.py +80 -0
- wandb/vendor/pygments/styles/abap.py +29 -0
- wandb/vendor/pygments/styles/algol.py +63 -0
- wandb/vendor/pygments/styles/algol_nu.py +63 -0
- wandb/vendor/pygments/styles/arduino.py +98 -0
- wandb/vendor/pygments/styles/autumn.py +65 -0
- wandb/vendor/pygments/styles/borland.py +51 -0
- wandb/vendor/pygments/styles/bw.py +49 -0
- wandb/vendor/pygments/styles/colorful.py +81 -0
- wandb/vendor/pygments/styles/default.py +73 -0
- wandb/vendor/pygments/styles/emacs.py +72 -0
- wandb/vendor/pygments/styles/friendly.py +72 -0
- wandb/vendor/pygments/styles/fruity.py +42 -0
- wandb/vendor/pygments/styles/igor.py +29 -0
- wandb/vendor/pygments/styles/lovelace.py +97 -0
- wandb/vendor/pygments/styles/manni.py +75 -0
- wandb/vendor/pygments/styles/monokai.py +106 -0
- wandb/vendor/pygments/styles/murphy.py +80 -0
- wandb/vendor/pygments/styles/native.py +65 -0
- wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
- wandb/vendor/pygments/styles/paraiso_light.py +125 -0
- wandb/vendor/pygments/styles/pastie.py +75 -0
- wandb/vendor/pygments/styles/perldoc.py +69 -0
- wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
- wandb/vendor/pygments/styles/rrt.py +33 -0
- wandb/vendor/pygments/styles/sas.py +44 -0
- wandb/vendor/pygments/styles/stata.py +40 -0
- wandb/vendor/pygments/styles/tango.py +141 -0
- wandb/vendor/pygments/styles/trac.py +63 -0
- wandb/vendor/pygments/styles/vim.py +63 -0
- wandb/vendor/pygments/styles/vs.py +38 -0
- wandb/vendor/pygments/styles/xcode.py +51 -0
- wandb/vendor/pygments/token.py +213 -0
- wandb/vendor/pygments/unistring.py +217 -0
- wandb/vendor/pygments/util.py +388 -0
- wandb/vendor/pynvml/__init__.py +0 -0
- wandb/vendor/pynvml/pynvml.py +4779 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
- wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
- wandb/wandb_agent.py +588 -0
- wandb/wandb_controller.py +719 -0
- wandb/wandb_run.py +9 -0
- wandb-0.19.1rc1.dist-info/METADATA +223 -0
- wandb-0.19.1rc1.dist-info/RECORD +822 -0
- wandb-0.19.1rc1.dist-info/WHEEL +5 -0
- wandb-0.19.1rc1.dist-info/entry_points.txt +3 -0
- wandb-0.19.1rc1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,2364 @@
|
|
1
|
+
"""Artifact class."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import atexit
|
6
|
+
import concurrent.futures
|
7
|
+
import contextlib
|
8
|
+
import json
|
9
|
+
import logging
|
10
|
+
import multiprocessing.dummy
|
11
|
+
import os
|
12
|
+
import re
|
13
|
+
import shutil
|
14
|
+
import stat
|
15
|
+
import tempfile
|
16
|
+
import time
|
17
|
+
from copy import copy
|
18
|
+
from datetime import datetime, timedelta
|
19
|
+
from functools import partial
|
20
|
+
from pathlib import PurePosixPath
|
21
|
+
from typing import IO, TYPE_CHECKING, Any, Dict, Iterator, Literal, Sequence, Type, cast
|
22
|
+
from urllib.parse import urlparse
|
23
|
+
|
24
|
+
import requests
|
25
|
+
|
26
|
+
import wandb
|
27
|
+
from wandb import data_types, env, util
|
28
|
+
from wandb.apis.normalize import normalize_exceptions
|
29
|
+
from wandb.apis.public import ArtifactCollection, ArtifactFiles, RetryingClient, Run
|
30
|
+
from wandb.data_types import WBValue
|
31
|
+
from wandb.errors.term import termerror, termlog, termwarn
|
32
|
+
from wandb.sdk.artifacts._validators import (
|
33
|
+
ensure_logged,
|
34
|
+
ensure_not_finalized,
|
35
|
+
validate_aliases,
|
36
|
+
validate_tags,
|
37
|
+
)
|
38
|
+
from wandb.sdk.artifacts.artifact_download_logger import ArtifactDownloadLogger
|
39
|
+
from wandb.sdk.artifacts.artifact_instance_cache import artifact_instance_cache
|
40
|
+
from wandb.sdk.artifacts.artifact_manifest import ArtifactManifest
|
41
|
+
from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry
|
42
|
+
from wandb.sdk.artifacts.artifact_manifests.artifact_manifest_v1 import (
|
43
|
+
ArtifactManifestV1,
|
44
|
+
)
|
45
|
+
from wandb.sdk.artifacts.artifact_state import ArtifactState
|
46
|
+
from wandb.sdk.artifacts.artifact_ttl import ArtifactTTL
|
47
|
+
from wandb.sdk.artifacts.exceptions import ArtifactNotLoggedError, WaitTimeoutError
|
48
|
+
from wandb.sdk.artifacts.staging import get_staging_dir
|
49
|
+
from wandb.sdk.artifacts.storage_handlers.gcs_handler import _GCSIsADirectoryError
|
50
|
+
from wandb.sdk.artifacts.storage_layout import StorageLayout
|
51
|
+
from wandb.sdk.artifacts.storage_policies import WANDB_STORAGE_POLICY
|
52
|
+
from wandb.sdk.artifacts.storage_policy import StoragePolicy
|
53
|
+
from wandb.sdk.data_types._dtypes import Type as WBType
|
54
|
+
from wandb.sdk.data_types._dtypes import TypeRegistry
|
55
|
+
from wandb.sdk.internal.internal_api import Api as InternalApi
|
56
|
+
from wandb.sdk.internal.thread_local_settings import _thread_local_api_settings
|
57
|
+
from wandb.sdk.lib import filesystem, retry, runid, telemetry
|
58
|
+
from wandb.sdk.lib.deprecate import Deprecated, deprecate
|
59
|
+
from wandb.sdk.lib.hashutil import B64MD5, b64_to_hex_id, md5_file_b64
|
60
|
+
from wandb.sdk.lib.mailbox import Mailbox
|
61
|
+
from wandb.sdk.lib.paths import FilePathStr, LogicalPath, StrPath, URIStr
|
62
|
+
from wandb.sdk.lib.runid import generate_id
|
63
|
+
|
64
|
+
reset_path = util.vendor_setup()
|
65
|
+
|
66
|
+
from wandb_gql import gql # noqa: E402
|
67
|
+
|
68
|
+
reset_path()
|
69
|
+
|
70
|
+
logger = logging.getLogger(__name__)
|
71
|
+
|
72
|
+
if TYPE_CHECKING:
|
73
|
+
from wandb.sdk.interface.message_future import MessageFuture
|
74
|
+
|
75
|
+
|
76
|
+
class Artifact:
|
77
|
+
"""Flexible and lightweight building block for dataset and model versioning.
|
78
|
+
|
79
|
+
Construct an empty W&B Artifact. Populate an artifacts contents with methods that
|
80
|
+
begin with `add`. Once the artifact has all the desired files, you can call
|
81
|
+
`wandb.log_artifact()` to log it.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
name: A human-readable name for the artifact. Use the name to identify
|
85
|
+
a specific artifact in the W&B App UI or programmatically. You can
|
86
|
+
interactively reference an artifact with the `use_artifact` Public API.
|
87
|
+
A name can contain letters, numbers, underscores, hyphens, and dots.
|
88
|
+
The name must be unique across a project.
|
89
|
+
type: The artifact's type. Use the type of an artifact to both organize
|
90
|
+
and differentiate artifacts. You can use any string that contains letters,
|
91
|
+
numbers, underscores, hyphens, and dots. Common types include `dataset` or `model`.
|
92
|
+
Include `model` within your type string if you want to link the artifact
|
93
|
+
to the W&B Model Registry.
|
94
|
+
description: A description of the artifact. For Model or Dataset Artifacts,
|
95
|
+
add documentation for your standardized team model or dataset card. View
|
96
|
+
an artifact's description programmatically with the `Artifact.description`
|
97
|
+
attribute or programmatically with the W&B App UI. W&B renders the
|
98
|
+
description as markdown in the W&B App.
|
99
|
+
metadata: Additional information about an artifact. Specify metadata as a
|
100
|
+
dictionary of key-value pairs. You can specify no more than 100 total keys.
|
101
|
+
|
102
|
+
Returns:
|
103
|
+
An `Artifact` object.
|
104
|
+
"""
|
105
|
+
|
106
|
+
_TMP_DIR = tempfile.TemporaryDirectory("wandb-artifacts")
|
107
|
+
atexit.register(_TMP_DIR.cleanup)
|
108
|
+
|
109
|
+
def __init__(
|
110
|
+
self,
|
111
|
+
name: str,
|
112
|
+
type: str,
|
113
|
+
description: str | None = None,
|
114
|
+
metadata: dict[str, Any] | None = None,
|
115
|
+
incremental: bool = False,
|
116
|
+
use_as: str | None = None,
|
117
|
+
) -> None:
|
118
|
+
if not re.match(r"^[a-zA-Z0-9_\-.]+$", name):
|
119
|
+
raise ValueError(
|
120
|
+
f"Artifact name may only contain alphanumeric characters, dashes, "
|
121
|
+
f"underscores, and dots. Invalid name: {name}"
|
122
|
+
)
|
123
|
+
if type == "job" or type.startswith("wandb-"):
|
124
|
+
raise ValueError(
|
125
|
+
"Artifact types 'job' and 'wandb-*' are reserved for internal use. "
|
126
|
+
"Please use a different type."
|
127
|
+
)
|
128
|
+
if incremental:
|
129
|
+
termwarn("Using experimental arg `incremental`")
|
130
|
+
|
131
|
+
# Internal.
|
132
|
+
self._client: RetryingClient | None = None
|
133
|
+
|
134
|
+
storage_policy_cls = StoragePolicy.lookup_by_name(WANDB_STORAGE_POLICY)
|
135
|
+
layout = StorageLayout.V1 if env.get_use_v1_artifacts() else StorageLayout.V2
|
136
|
+
policy_config = {"storageLayout": layout}
|
137
|
+
self._storage_policy = storage_policy_cls.from_config(config=policy_config)
|
138
|
+
|
139
|
+
self._tmp_dir: tempfile.TemporaryDirectory | None = None
|
140
|
+
self._added_objs: dict[int, tuple[WBValue, ArtifactManifestEntry]] = {}
|
141
|
+
self._added_local_paths: dict[str, ArtifactManifestEntry] = {}
|
142
|
+
self._save_future: MessageFuture | None = None
|
143
|
+
self._download_roots: set[str] = set()
|
144
|
+
# Set by new_draft(), otherwise the latest artifact will be used as the base.
|
145
|
+
self._base_id: str | None = None
|
146
|
+
# Properties.
|
147
|
+
self._id: str | None = None
|
148
|
+
self._client_id: str = runid.generate_id(128)
|
149
|
+
self._sequence_client_id: str = runid.generate_id(128)
|
150
|
+
self._entity: str | None = None
|
151
|
+
self._project: str | None = None
|
152
|
+
self._name: str = name # includes version after saving
|
153
|
+
self._version: str | None = None
|
154
|
+
self._source_entity: str | None = None
|
155
|
+
self._source_project: str | None = None
|
156
|
+
self._source_name: str = name # includes version after saving
|
157
|
+
self._source_version: str | None = None
|
158
|
+
self._type: str = type
|
159
|
+
self._description: str | None = description
|
160
|
+
self._metadata: dict = self._normalize_metadata(metadata)
|
161
|
+
self._ttl_duration_seconds: int | None = None
|
162
|
+
self._ttl_is_inherited: bool = True
|
163
|
+
self._ttl_changed: bool = False
|
164
|
+
self._aliases: list[str] = []
|
165
|
+
self._saved_aliases: list[str] = []
|
166
|
+
self._tags: list[str] = []
|
167
|
+
self._saved_tags: list[str] = []
|
168
|
+
self._distributed_id: str | None = None
|
169
|
+
self._incremental: bool = incremental
|
170
|
+
self._use_as: str | None = use_as
|
171
|
+
self._state: ArtifactState = ArtifactState.PENDING
|
172
|
+
self._manifest: ArtifactManifest | None = ArtifactManifestV1(
|
173
|
+
self._storage_policy
|
174
|
+
)
|
175
|
+
self._commit_hash: str | None = None
|
176
|
+
self._file_count: int | None = None
|
177
|
+
self._created_at: str | None = None
|
178
|
+
self._updated_at: str | None = None
|
179
|
+
self._final: bool = False
|
180
|
+
|
181
|
+
# Cache.
|
182
|
+
artifact_instance_cache[self._client_id] = self
|
183
|
+
|
184
|
+
def __repr__(self) -> str:
|
185
|
+
return f"<Artifact {self.id or self.name}>"
|
186
|
+
|
187
|
+
@classmethod
|
188
|
+
def _from_id(cls, artifact_id: str, client: RetryingClient) -> Artifact | None:
|
189
|
+
artifact = artifact_instance_cache.get(artifact_id)
|
190
|
+
if artifact is not None:
|
191
|
+
return artifact
|
192
|
+
|
193
|
+
query = gql(
|
194
|
+
"""
|
195
|
+
query ArtifactByID($id: ID!) {
|
196
|
+
artifact(id: $id) {
|
197
|
+
...ArtifactFragment
|
198
|
+
}
|
199
|
+
}
|
200
|
+
"""
|
201
|
+
+ _gql_artifact_fragment()
|
202
|
+
)
|
203
|
+
response = client.execute(
|
204
|
+
query,
|
205
|
+
variable_values={"id": artifact_id},
|
206
|
+
)
|
207
|
+
attrs = response.get("artifact")
|
208
|
+
if attrs is None:
|
209
|
+
return None
|
210
|
+
|
211
|
+
src_collection = attrs["artifactSequence"]
|
212
|
+
src_project = src_collection["project"]
|
213
|
+
|
214
|
+
entity_name = src_project["entityName"] if src_project else ""
|
215
|
+
project_name = src_project["name"] if src_project else ""
|
216
|
+
|
217
|
+
name = "{}:v{}".format(src_collection["name"], attrs["versionIndex"])
|
218
|
+
return cls._from_attrs(entity_name, project_name, name, attrs, client)
|
219
|
+
|
220
|
+
@classmethod
|
221
|
+
def _from_name(
|
222
|
+
cls,
|
223
|
+
*,
|
224
|
+
entity: str,
|
225
|
+
project: str,
|
226
|
+
name: str,
|
227
|
+
client: RetryingClient,
|
228
|
+
enable_tracking: bool = False,
|
229
|
+
) -> Artifact:
|
230
|
+
server_supports_enabling_artifact_usage_tracking = (
|
231
|
+
InternalApi().server_project_type_introspection()
|
232
|
+
)
|
233
|
+
query_vars = ["$entityName: String!", "$projectName: String!", "$name: String!"]
|
234
|
+
query_args = ["name: $name"]
|
235
|
+
if server_supports_enabling_artifact_usage_tracking:
|
236
|
+
query_vars.append("$enableTracking: Boolean")
|
237
|
+
query_args.append("enableTracking: $enableTracking")
|
238
|
+
|
239
|
+
vars_str = ", ".join(query_vars)
|
240
|
+
args_str = ", ".join(query_args)
|
241
|
+
|
242
|
+
query = gql(
|
243
|
+
f"""
|
244
|
+
query ArtifactByName({vars_str}) {{
|
245
|
+
project(name: $projectName, entityName: $entityName) {{
|
246
|
+
artifact({args_str}) {{
|
247
|
+
...ArtifactFragment
|
248
|
+
}}
|
249
|
+
}}
|
250
|
+
}}
|
251
|
+
{_gql_artifact_fragment()}
|
252
|
+
"""
|
253
|
+
)
|
254
|
+
query_variable_values: dict[str, Any] = {
|
255
|
+
"entityName": entity,
|
256
|
+
"projectName": project,
|
257
|
+
"name": name,
|
258
|
+
}
|
259
|
+
if server_supports_enabling_artifact_usage_tracking:
|
260
|
+
query_variable_values["enableTracking"] = enable_tracking
|
261
|
+
|
262
|
+
response = client.execute(
|
263
|
+
query,
|
264
|
+
variable_values=query_variable_values,
|
265
|
+
)
|
266
|
+
project_attrs = response.get("project")
|
267
|
+
if not project_attrs:
|
268
|
+
raise ValueError(f"project '{project}' not found under entity '{entity}'")
|
269
|
+
attrs = project_attrs.get("artifact")
|
270
|
+
if not attrs:
|
271
|
+
raise ValueError(f"artifact '{name}' not found in '{entity}/{project}'")
|
272
|
+
return cls._from_attrs(entity, project, name, attrs, client)
|
273
|
+
|
274
|
+
@classmethod
|
275
|
+
def _from_attrs(
|
276
|
+
cls,
|
277
|
+
entity: str,
|
278
|
+
project: str,
|
279
|
+
name: str,
|
280
|
+
attrs: dict[str, Any],
|
281
|
+
client: RetryingClient,
|
282
|
+
) -> Artifact:
|
283
|
+
# Placeholder is required to skip validation.
|
284
|
+
artifact = cls("placeholder", type="placeholder")
|
285
|
+
artifact._client = client
|
286
|
+
artifact._entity = entity
|
287
|
+
artifact._project = project
|
288
|
+
artifact._name = name
|
289
|
+
artifact._assign_attrs(attrs)
|
290
|
+
|
291
|
+
artifact.finalize()
|
292
|
+
|
293
|
+
# Cache.
|
294
|
+
assert artifact.id is not None
|
295
|
+
artifact_instance_cache[artifact.id] = artifact
|
296
|
+
return artifact
|
297
|
+
|
298
|
+
def _assign_attrs(self, attrs: dict[str, Any]) -> None:
|
299
|
+
"""Update this Artifact's attributes using the server response."""
|
300
|
+
self._id = attrs["id"]
|
301
|
+
|
302
|
+
src_version = f"v{attrs['versionIndex']}"
|
303
|
+
src_collection = attrs["artifactSequence"]
|
304
|
+
src_project = src_collection["project"]
|
305
|
+
|
306
|
+
self._source_entity = src_project["entityName"] if src_project else ""
|
307
|
+
self._source_project = src_project["name"] if src_project else ""
|
308
|
+
self._source_name = f"{src_collection['name']}:{src_version}"
|
309
|
+
self._source_version = src_version
|
310
|
+
|
311
|
+
if self._entity is None:
|
312
|
+
self._entity = self._source_entity
|
313
|
+
if self._project is None:
|
314
|
+
self._project = self._source_project
|
315
|
+
|
316
|
+
if self._name is None:
|
317
|
+
self._name = self._source_name
|
318
|
+
|
319
|
+
self._type = attrs["artifactType"]["name"]
|
320
|
+
self._description = attrs["description"]
|
321
|
+
|
322
|
+
entity = self._entity
|
323
|
+
project = self._project
|
324
|
+
collection, *_ = self._name.split(":")
|
325
|
+
aliases = [
|
326
|
+
obj["alias"]
|
327
|
+
for obj in attrs["aliases"]
|
328
|
+
if obj["artifactCollection"]
|
329
|
+
and obj["artifactCollection"]["project"]
|
330
|
+
and obj["artifactCollection"]["project"]["entityName"] == entity
|
331
|
+
and obj["artifactCollection"]["project"]["name"] == project
|
332
|
+
and obj["artifactCollection"]["name"] == collection
|
333
|
+
]
|
334
|
+
|
335
|
+
version_aliases = [
|
336
|
+
alias for alias in aliases if util.alias_is_version_index(alias)
|
337
|
+
]
|
338
|
+
other_aliases = [
|
339
|
+
alias for alias in aliases if not util.alias_is_version_index(alias)
|
340
|
+
]
|
341
|
+
if version_aliases:
|
342
|
+
try:
|
343
|
+
[version] = version_aliases
|
344
|
+
except ValueError:
|
345
|
+
raise ValueError(
|
346
|
+
f"Expected at most one version alias, got {len(version_aliases)}: {version_aliases!r}"
|
347
|
+
)
|
348
|
+
else:
|
349
|
+
version = src_version
|
350
|
+
|
351
|
+
self._version = version
|
352
|
+
|
353
|
+
if ":" not in self._name:
|
354
|
+
self._name = f"{self._name}:{version}"
|
355
|
+
|
356
|
+
self._aliases = other_aliases
|
357
|
+
self._saved_aliases = copy(other_aliases)
|
358
|
+
|
359
|
+
tags = [obj["name"] for obj in attrs.get("tags", [])]
|
360
|
+
self._tags = tags
|
361
|
+
self._saved_tags = copy(tags)
|
362
|
+
|
363
|
+
metadata_str = attrs["metadata"]
|
364
|
+
self.metadata = self._normalize_metadata(
|
365
|
+
json.loads(metadata_str) if metadata_str else {}
|
366
|
+
)
|
367
|
+
|
368
|
+
self._ttl_duration_seconds = _ttl_duration_seconds_from_gql(
|
369
|
+
attrs.get("ttlDurationSeconds")
|
370
|
+
)
|
371
|
+
self._ttl_is_inherited = (
|
372
|
+
True if (attrs.get("ttlIsInherited") is None) else attrs["ttlIsInherited"]
|
373
|
+
)
|
374
|
+
|
375
|
+
self._state = ArtifactState(attrs["state"])
|
376
|
+
|
377
|
+
try:
|
378
|
+
manifest_url = attrs["currentManifest"]["file"]["directUrl"]
|
379
|
+
except (LookupError, TypeError):
|
380
|
+
self._manifest = None
|
381
|
+
else:
|
382
|
+
self._manifest = self._load_manifest(manifest_url)
|
383
|
+
|
384
|
+
self._commit_hash = attrs["commitHash"]
|
385
|
+
self._file_count = attrs["fileCount"]
|
386
|
+
self._created_at = attrs["createdAt"]
|
387
|
+
self._updated_at = attrs["updatedAt"]
|
388
|
+
|
389
|
+
@ensure_logged
|
390
|
+
def new_draft(self) -> Artifact:
|
391
|
+
"""Create a new draft artifact with the same content as this committed artifact.
|
392
|
+
|
393
|
+
The artifact returned can be extended or modified and logged as a new version.
|
394
|
+
|
395
|
+
Returns:
|
396
|
+
An `Artifact` object.
|
397
|
+
|
398
|
+
Raises:
|
399
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
400
|
+
"""
|
401
|
+
# Name, _entity and _project are set to the *source* name/entity/project:
|
402
|
+
# if this artifact is saved it must be saved to the source sequence.
|
403
|
+
artifact = Artifact(self.source_name.split(":")[0], self.type)
|
404
|
+
artifact._entity = self._source_entity
|
405
|
+
artifact._project = self._source_project
|
406
|
+
artifact._source_entity = self._source_entity
|
407
|
+
artifact._source_project = self._source_project
|
408
|
+
|
409
|
+
# This artifact's parent is the one we are making a draft from.
|
410
|
+
artifact._base_id = self.id
|
411
|
+
|
412
|
+
# We can reuse the client, and copy over all the attributes that aren't
|
413
|
+
# version-dependent and don't depend on having been logged.
|
414
|
+
artifact._client = self._client
|
415
|
+
artifact._description = self.description
|
416
|
+
artifact._metadata = self.metadata
|
417
|
+
artifact._manifest = ArtifactManifest.from_manifest_json(
|
418
|
+
self.manifest.to_manifest_json()
|
419
|
+
)
|
420
|
+
return artifact
|
421
|
+
|
422
|
+
# Properties (Python Class managed attributes).
|
423
|
+
|
424
|
+
@property
|
425
|
+
def id(self) -> str | None:
|
426
|
+
"""The artifact's ID."""
|
427
|
+
if self.is_draft():
|
428
|
+
return None
|
429
|
+
assert self._id is not None
|
430
|
+
return self._id
|
431
|
+
|
432
|
+
@property
|
433
|
+
@ensure_logged
|
434
|
+
def entity(self) -> str:
|
435
|
+
"""The name of the entity of the secondary (portfolio) artifact collection."""
|
436
|
+
assert self._entity is not None
|
437
|
+
return self._entity
|
438
|
+
|
439
|
+
@property
|
440
|
+
@ensure_logged
|
441
|
+
def project(self) -> str:
|
442
|
+
"""The name of the project of the secondary (portfolio) artifact collection."""
|
443
|
+
assert self._project is not None
|
444
|
+
return self._project
|
445
|
+
|
446
|
+
@property
|
447
|
+
def name(self) -> str:
|
448
|
+
"""The artifact name and version in its secondary (portfolio) collection.
|
449
|
+
|
450
|
+
A string with the format `{collection}:{alias}`. Before the artifact is saved,
|
451
|
+
contains only the name since the version is not yet known.
|
452
|
+
"""
|
453
|
+
return self._name
|
454
|
+
|
455
|
+
@property
|
456
|
+
def qualified_name(self) -> str:
|
457
|
+
"""The entity/project/name of the secondary (portfolio) collection."""
|
458
|
+
return f"{self.entity}/{self.project}/{self.name}"
|
459
|
+
|
460
|
+
@property
|
461
|
+
@ensure_logged
|
462
|
+
def version(self) -> str:
|
463
|
+
"""The artifact's version in its secondary (portfolio) collection."""
|
464
|
+
assert self._version is not None
|
465
|
+
return self._version
|
466
|
+
|
467
|
+
@property
|
468
|
+
@ensure_logged
|
469
|
+
def collection(self) -> ArtifactCollection:
|
470
|
+
"""The collection this artifact was retrieved from.
|
471
|
+
|
472
|
+
A collection is an ordered group of artifact versions.
|
473
|
+
If this artifact was retrieved from a portfolio / linked collection, that
|
474
|
+
collection will be returned rather than the collection
|
475
|
+
that an artifact version originated from. The collection
|
476
|
+
that an artifact originates from is known as the source sequence.
|
477
|
+
"""
|
478
|
+
base_name = self.name.split(":")[0]
|
479
|
+
return ArtifactCollection(
|
480
|
+
self._client, self.entity, self.project, base_name, self.type
|
481
|
+
)
|
482
|
+
|
483
|
+
@property
|
484
|
+
@ensure_logged
|
485
|
+
def source_entity(self) -> str:
|
486
|
+
"""The name of the entity of the primary (sequence) artifact collection."""
|
487
|
+
assert self._source_entity is not None
|
488
|
+
return self._source_entity
|
489
|
+
|
490
|
+
@property
|
491
|
+
@ensure_logged
|
492
|
+
def source_project(self) -> str:
|
493
|
+
"""The name of the project of the primary (sequence) artifact collection."""
|
494
|
+
assert self._source_project is not None
|
495
|
+
return self._source_project
|
496
|
+
|
497
|
+
@property
|
498
|
+
def source_name(self) -> str:
|
499
|
+
"""The artifact name and version in its primary (sequence) collection.
|
500
|
+
|
501
|
+
A string with the format `{collection}:{alias}`. Before the artifact is saved,
|
502
|
+
contains only the name since the version is not yet known.
|
503
|
+
"""
|
504
|
+
return self._source_name
|
505
|
+
|
506
|
+
@property
|
507
|
+
def source_qualified_name(self) -> str:
|
508
|
+
"""The entity/project/name of the primary (sequence) collection."""
|
509
|
+
return f"{self.source_entity}/{self.source_project}/{self.source_name}"
|
510
|
+
|
511
|
+
@property
|
512
|
+
@ensure_logged
|
513
|
+
def source_version(self) -> str:
|
514
|
+
"""The artifact's version in its primary (sequence) collection.
|
515
|
+
|
516
|
+
A string with the format `v{number}`.
|
517
|
+
"""
|
518
|
+
assert self._source_version is not None
|
519
|
+
return self._source_version
|
520
|
+
|
521
|
+
@property
|
522
|
+
@ensure_logged
|
523
|
+
def source_collection(self) -> ArtifactCollection:
|
524
|
+
"""The artifact's primary (sequence) collection."""
|
525
|
+
base_name = self.source_name.split(":")[0]
|
526
|
+
return ArtifactCollection(
|
527
|
+
self._client, self.source_entity, self.source_project, base_name, self.type
|
528
|
+
)
|
529
|
+
|
530
|
+
@property
|
531
|
+
def type(self) -> str:
|
532
|
+
"""The artifact's type. Common types include `dataset` or `model`."""
|
533
|
+
return self._type
|
534
|
+
|
535
|
+
@property
|
536
|
+
def description(self) -> str | None:
|
537
|
+
"""A description of the artifact."""
|
538
|
+
return self._description
|
539
|
+
|
540
|
+
@description.setter
|
541
|
+
def description(self, description: str | None) -> None:
|
542
|
+
"""Set the description of the artifact.
|
543
|
+
|
544
|
+
For model or dataset Artifacts, add documentation for your
|
545
|
+
standardized team model or dataset card. In the W&B UI the
|
546
|
+
description is rendered as markdown.
|
547
|
+
|
548
|
+
Args:
|
549
|
+
description: Free text that offers a description of the artifact.
|
550
|
+
"""
|
551
|
+
self._description = description
|
552
|
+
|
553
|
+
@property
|
554
|
+
def metadata(self) -> dict:
|
555
|
+
"""User-defined artifact metadata.
|
556
|
+
|
557
|
+
Structured data associated with the artifact.
|
558
|
+
"""
|
559
|
+
return self._metadata
|
560
|
+
|
561
|
+
@metadata.setter
|
562
|
+
def metadata(self, metadata: dict) -> None:
|
563
|
+
"""User-defined artifact metadata.
|
564
|
+
|
565
|
+
Metadata set this way will eventually be queryable and plottable in the UI; e.g.
|
566
|
+
the class distribution of a dataset.
|
567
|
+
|
568
|
+
Note: There is currently a limit of 100 total keys.
|
569
|
+
|
570
|
+
Args:
|
571
|
+
metadata: Structured data associated with the artifact.
|
572
|
+
"""
|
573
|
+
self._metadata = self._normalize_metadata(metadata)
|
574
|
+
|
575
|
+
@property
|
576
|
+
def ttl(self) -> timedelta | None:
|
577
|
+
"""The time-to-live (TTL) policy of an artifact.
|
578
|
+
|
579
|
+
Artifacts are deleted shortly after a TTL policy's duration passes.
|
580
|
+
If set to `None`, the artifact deactivates TTL policies and will be not
|
581
|
+
scheduled for deletion, even if there is a team default TTL.
|
582
|
+
An artifact inherits a TTL policy from
|
583
|
+
the team default if the team administrator defines a default
|
584
|
+
TTL and there is no custom policy set on an artifact.
|
585
|
+
|
586
|
+
Raises:
|
587
|
+
ArtifactNotLoggedError: Unable to fetch inherited TTL if the artifact has not been logged or saved
|
588
|
+
"""
|
589
|
+
if self._ttl_is_inherited and (self.is_draft() or self._ttl_changed):
|
590
|
+
raise ArtifactNotLoggedError(f"{type(self).__name__}.ttl", self)
|
591
|
+
if self._ttl_duration_seconds is None:
|
592
|
+
return None
|
593
|
+
return timedelta(seconds=self._ttl_duration_seconds)
|
594
|
+
|
595
|
+
@ttl.setter
|
596
|
+
def ttl(self, ttl: timedelta | ArtifactTTL | None) -> None:
|
597
|
+
"""The time-to-live (TTL) policy of an artifact.
|
598
|
+
|
599
|
+
Artifacts are deleted shortly after a TTL policy's duration passes.
|
600
|
+
If set to `None`, the artifact has no TTL policy set and it is not
|
601
|
+
scheduled for deletion. An artifact inherits a TTL policy from
|
602
|
+
the team default if the team administrator defines a default
|
603
|
+
TTL and there is no custom policy set on an artifact.
|
604
|
+
|
605
|
+
Args:
|
606
|
+
ttl: The duration as a positive Python `datetime.timedelta` Type
|
607
|
+
that represents how long the artifact will remain active from its creation.
|
608
|
+
|
609
|
+
"""
|
610
|
+
if self.type == "wandb-history":
|
611
|
+
raise ValueError("Cannot set artifact TTL for type wandb-history")
|
612
|
+
|
613
|
+
self._ttl_changed = True
|
614
|
+
if isinstance(ttl, ArtifactTTL):
|
615
|
+
if ttl == ArtifactTTL.INHERIT:
|
616
|
+
self._ttl_is_inherited = True
|
617
|
+
else:
|
618
|
+
raise ValueError(f"Unhandled ArtifactTTL enum {ttl}")
|
619
|
+
else:
|
620
|
+
self._ttl_is_inherited = False
|
621
|
+
if ttl is None:
|
622
|
+
self._ttl_duration_seconds = None
|
623
|
+
else:
|
624
|
+
if ttl.total_seconds() <= 0:
|
625
|
+
raise ValueError(
|
626
|
+
f"Artifact TTL Duration has to be positive. ttl: {ttl.total_seconds()}"
|
627
|
+
)
|
628
|
+
self._ttl_duration_seconds = int(ttl.total_seconds())
|
629
|
+
|
630
|
+
@property
|
631
|
+
@ensure_logged
|
632
|
+
def aliases(self) -> list[str]:
|
633
|
+
"""List of one or more semantically-friendly references or identifying "nicknames" assigned to an artifact version.
|
634
|
+
|
635
|
+
Aliases are mutable references that you can programmatically reference.
|
636
|
+
Change an artifact's alias with the W&B App UI or programmatically.
|
637
|
+
See [Create new artifact versions](https://docs.wandb.ai/guides/artifacts/create-a-new-artifact-version)
|
638
|
+
for more information.
|
639
|
+
"""
|
640
|
+
return self._aliases
|
641
|
+
|
642
|
+
@aliases.setter
|
643
|
+
@ensure_logged
|
644
|
+
def aliases(self, aliases: list[str]) -> None:
|
645
|
+
"""Set the aliases associated with this artifact."""
|
646
|
+
self._aliases = validate_aliases(aliases)
|
647
|
+
|
648
|
+
@property
|
649
|
+
@ensure_logged
|
650
|
+
def tags(self) -> list[str]:
|
651
|
+
"""List of one or more tags assigned to this artifact version."""
|
652
|
+
return self._tags
|
653
|
+
|
654
|
+
@tags.setter
|
655
|
+
@ensure_logged
|
656
|
+
def tags(self, tags: list[str]) -> None:
|
657
|
+
"""Set the tags associated with this artifact."""
|
658
|
+
self._tags = validate_tags(tags)
|
659
|
+
|
660
|
+
@property
|
661
|
+
def distributed_id(self) -> str | None:
|
662
|
+
return self._distributed_id
|
663
|
+
|
664
|
+
@distributed_id.setter
|
665
|
+
def distributed_id(self, distributed_id: str | None) -> None:
|
666
|
+
self._distributed_id = distributed_id
|
667
|
+
|
668
|
+
@property
|
669
|
+
def incremental(self) -> bool:
|
670
|
+
return self._incremental
|
671
|
+
|
672
|
+
@property
|
673
|
+
def use_as(self) -> str | None:
|
674
|
+
return self._use_as
|
675
|
+
|
676
|
+
@property
|
677
|
+
def state(self) -> str:
|
678
|
+
"""The status of the artifact. One of: "PENDING", "COMMITTED", or "DELETED"."""
|
679
|
+
return self._state.value
|
680
|
+
|
681
|
+
@property
|
682
|
+
def manifest(self) -> ArtifactManifest:
|
683
|
+
"""The artifact's manifest.
|
684
|
+
|
685
|
+
The manifest lists all of its contents, and can't be changed once the artifact
|
686
|
+
has been logged.
|
687
|
+
"""
|
688
|
+
if self._manifest is None:
|
689
|
+
query = gql(
|
690
|
+
"""
|
691
|
+
query ArtifactManifest(
|
692
|
+
$entityName: String!,
|
693
|
+
$projectName: String!,
|
694
|
+
$name: String!
|
695
|
+
) {
|
696
|
+
project(entityName: $entityName, name: $projectName) {
|
697
|
+
artifact(name: $name) {
|
698
|
+
currentManifest {
|
699
|
+
file {
|
700
|
+
directUrl
|
701
|
+
}
|
702
|
+
}
|
703
|
+
}
|
704
|
+
}
|
705
|
+
}
|
706
|
+
"""
|
707
|
+
)
|
708
|
+
assert self._client is not None
|
709
|
+
response = self._client.execute(
|
710
|
+
query,
|
711
|
+
variable_values={
|
712
|
+
"entityName": self._entity,
|
713
|
+
"projectName": self._project,
|
714
|
+
"name": self._name,
|
715
|
+
},
|
716
|
+
)
|
717
|
+
attrs = response["project"]["artifact"]
|
718
|
+
self._manifest = self._load_manifest(
|
719
|
+
attrs["currentManifest"]["file"]["directUrl"]
|
720
|
+
)
|
721
|
+
return self._manifest
|
722
|
+
|
723
|
+
@property
|
724
|
+
def digest(self) -> str:
|
725
|
+
"""The logical digest of the artifact.
|
726
|
+
|
727
|
+
The digest is the checksum of the artifact's contents. If an artifact has the
|
728
|
+
same digest as the current `latest` version, then `log_artifact` is a no-op.
|
729
|
+
"""
|
730
|
+
return self.manifest.digest()
|
731
|
+
|
732
|
+
@property
|
733
|
+
def size(self) -> int:
|
734
|
+
"""The total size of the artifact in bytes.
|
735
|
+
|
736
|
+
Includes any references tracked by this artifact.
|
737
|
+
"""
|
738
|
+
total_size: int = 0
|
739
|
+
for entry in self.manifest.entries.values():
|
740
|
+
if entry.size is not None:
|
741
|
+
total_size += entry.size
|
742
|
+
return total_size
|
743
|
+
|
744
|
+
@property
|
745
|
+
@ensure_logged
|
746
|
+
def commit_hash(self) -> str:
|
747
|
+
"""The hash returned when this artifact was committed."""
|
748
|
+
assert self._commit_hash is not None
|
749
|
+
return self._commit_hash
|
750
|
+
|
751
|
+
@property
|
752
|
+
@ensure_logged
|
753
|
+
def file_count(self) -> int:
|
754
|
+
"""The number of files (including references)."""
|
755
|
+
assert self._file_count is not None
|
756
|
+
return self._file_count
|
757
|
+
|
758
|
+
@property
|
759
|
+
@ensure_logged
|
760
|
+
def created_at(self) -> str:
|
761
|
+
"""Timestamp when the artifact was created."""
|
762
|
+
assert self._created_at is not None
|
763
|
+
return self._created_at
|
764
|
+
|
765
|
+
@property
|
766
|
+
@ensure_logged
|
767
|
+
def updated_at(self) -> str:
|
768
|
+
"""The time when the artifact was last updated."""
|
769
|
+
assert self._created_at is not None
|
770
|
+
return self._updated_at or self._created_at
|
771
|
+
|
772
|
+
# State management.
|
773
|
+
|
774
|
+
def finalize(self) -> None:
|
775
|
+
"""Finalize the artifact version.
|
776
|
+
|
777
|
+
You cannot modify an artifact version once it is finalized because the artifact
|
778
|
+
is logged as a specific artifact version. Create a new artifact version
|
779
|
+
to log more data to an artifact. An artifact is automatically finalized
|
780
|
+
when you log the artifact with `log_artifact`.
|
781
|
+
"""
|
782
|
+
self._final = True
|
783
|
+
|
784
|
+
def is_draft(self) -> bool:
|
785
|
+
"""Check if artifact is not saved.
|
786
|
+
|
787
|
+
Returns: Boolean. `False` if artifact is saved. `True` if artifact is not saved.
|
788
|
+
"""
|
789
|
+
return self._state == ArtifactState.PENDING
|
790
|
+
|
791
|
+
def _is_draft_save_started(self) -> bool:
|
792
|
+
return self._save_future is not None
|
793
|
+
|
794
|
+
def save(
|
795
|
+
self,
|
796
|
+
project: str | None = None,
|
797
|
+
settings: wandb.Settings | None = None,
|
798
|
+
) -> None:
|
799
|
+
"""Persist any changes made to the artifact.
|
800
|
+
|
801
|
+
If currently in a run, that run will log this artifact. If not currently in a
|
802
|
+
run, a run of type "auto" is created to track this artifact.
|
803
|
+
|
804
|
+
Args:
|
805
|
+
project: A project to use for the artifact in the case that a run is not
|
806
|
+
already in context.
|
807
|
+
settings: A settings object to use when initializing an automatic run. Most
|
808
|
+
commonly used in testing harness.
|
809
|
+
"""
|
810
|
+
if self._state != ArtifactState.PENDING:
|
811
|
+
return self._update()
|
812
|
+
|
813
|
+
if self._incremental:
|
814
|
+
with telemetry.context() as tel:
|
815
|
+
tel.feature.artifact_incremental = True
|
816
|
+
|
817
|
+
if wandb.run is None:
|
818
|
+
if settings is None:
|
819
|
+
settings = wandb.Settings(silent="true")
|
820
|
+
with wandb.init( # type: ignore
|
821
|
+
entity=self._source_entity,
|
822
|
+
project=project or self._source_project,
|
823
|
+
job_type="auto",
|
824
|
+
settings=settings,
|
825
|
+
) as run:
|
826
|
+
# redoing this here because in this branch we know we didn't
|
827
|
+
# have the run at the beginning of the method
|
828
|
+
if self._incremental:
|
829
|
+
with telemetry.context(run=run) as tel:
|
830
|
+
tel.feature.artifact_incremental = True
|
831
|
+
run.log_artifact(self)
|
832
|
+
else:
|
833
|
+
wandb.run.log_artifact(self)
|
834
|
+
|
835
|
+
def _set_save_future(
|
836
|
+
self, save_future: MessageFuture, client: RetryingClient
|
837
|
+
) -> None:
|
838
|
+
self._save_future = save_future
|
839
|
+
self._client = client
|
840
|
+
|
841
|
+
def wait(self, timeout: int | None = None) -> Artifact:
|
842
|
+
"""If needed, wait for this artifact to finish logging.
|
843
|
+
|
844
|
+
Args:
|
845
|
+
timeout: The time, in seconds, to wait.
|
846
|
+
|
847
|
+
Returns:
|
848
|
+
An `Artifact` object.
|
849
|
+
"""
|
850
|
+
if self.is_draft():
|
851
|
+
if self._save_future is None:
|
852
|
+
raise ArtifactNotLoggedError(type(self).wait.__qualname__, self)
|
853
|
+
result = self._save_future.get(timeout)
|
854
|
+
if not result:
|
855
|
+
raise WaitTimeoutError(
|
856
|
+
"Artifact upload wait timed out, failed to fetch Artifact response"
|
857
|
+
)
|
858
|
+
response = result.response.log_artifact_response
|
859
|
+
if response.error_message:
|
860
|
+
raise ValueError(response.error_message)
|
861
|
+
self._populate_after_save(response.artifact_id)
|
862
|
+
return self
|
863
|
+
|
864
|
+
def _populate_after_save(self, artifact_id: str) -> None:
|
865
|
+
query_template = """
|
866
|
+
query ArtifactByIDShort($id: ID!) {
|
867
|
+
artifact(id: $id) {
|
868
|
+
...ArtifactFragment
|
869
|
+
}
|
870
|
+
}
|
871
|
+
""" + _gql_artifact_fragment()
|
872
|
+
|
873
|
+
query = gql(query_template)
|
874
|
+
|
875
|
+
assert self._client is not None
|
876
|
+
response = self._client.execute(
|
877
|
+
query,
|
878
|
+
variable_values={"id": artifact_id},
|
879
|
+
)
|
880
|
+
|
881
|
+
try:
|
882
|
+
attrs = response["artifact"]
|
883
|
+
except LookupError:
|
884
|
+
raise ValueError(f"Unable to fetch artifact with id: {artifact_id!r}")
|
885
|
+
else:
|
886
|
+
self._assign_attrs(attrs)
|
887
|
+
|
888
|
+
@normalize_exceptions
|
889
|
+
def _update(self) -> None:
|
890
|
+
"""Persists artifact changes to the wandb backend."""
|
891
|
+
aliases = None
|
892
|
+
introspect_query = gql(
|
893
|
+
"""
|
894
|
+
query ProbeServerAddAliasesInput {
|
895
|
+
AddAliasesInputInfoType: __type(name: "AddAliasesInput") {
|
896
|
+
name
|
897
|
+
inputFields {
|
898
|
+
name
|
899
|
+
}
|
900
|
+
}
|
901
|
+
}
|
902
|
+
"""
|
903
|
+
)
|
904
|
+
assert self._client is not None
|
905
|
+
response = self._client.execute(introspect_query)
|
906
|
+
if response.get("AddAliasesInputInfoType"): # wandb backend version >= 0.13.0
|
907
|
+
aliases_to_add = set(self._aliases) - set(self._saved_aliases)
|
908
|
+
aliases_to_delete = set(self._saved_aliases) - set(self._aliases)
|
909
|
+
if aliases_to_add:
|
910
|
+
add_mutation = gql(
|
911
|
+
"""
|
912
|
+
mutation addAliases(
|
913
|
+
$artifactID: ID!,
|
914
|
+
$aliases: [ArtifactCollectionAliasInput!]!,
|
915
|
+
) {
|
916
|
+
addAliases(
|
917
|
+
input: {artifactID: $artifactID, aliases: $aliases}
|
918
|
+
) {
|
919
|
+
success
|
920
|
+
}
|
921
|
+
}
|
922
|
+
"""
|
923
|
+
)
|
924
|
+
assert self._client is not None
|
925
|
+
self._client.execute(
|
926
|
+
add_mutation,
|
927
|
+
variable_values={
|
928
|
+
"artifactID": self.id,
|
929
|
+
"aliases": [
|
930
|
+
{
|
931
|
+
"entityName": self._entity,
|
932
|
+
"projectName": self._project,
|
933
|
+
"artifactCollectionName": self._name.split(":")[0],
|
934
|
+
"alias": alias,
|
935
|
+
}
|
936
|
+
for alias in aliases_to_add
|
937
|
+
],
|
938
|
+
},
|
939
|
+
)
|
940
|
+
if aliases_to_delete:
|
941
|
+
delete_mutation = gql(
|
942
|
+
"""
|
943
|
+
mutation deleteAliases(
|
944
|
+
$artifactID: ID!,
|
945
|
+
$aliases: [ArtifactCollectionAliasInput!]!,
|
946
|
+
) {
|
947
|
+
deleteAliases(
|
948
|
+
input: {artifactID: $artifactID, aliases: $aliases}
|
949
|
+
) {
|
950
|
+
success
|
951
|
+
}
|
952
|
+
}
|
953
|
+
"""
|
954
|
+
)
|
955
|
+
assert self._client is not None
|
956
|
+
self._client.execute(
|
957
|
+
delete_mutation,
|
958
|
+
variable_values={
|
959
|
+
"artifactID": self.id,
|
960
|
+
"aliases": [
|
961
|
+
{
|
962
|
+
"entityName": self._entity,
|
963
|
+
"projectName": self._project,
|
964
|
+
"artifactCollectionName": self._name.split(":")[0],
|
965
|
+
"alias": alias,
|
966
|
+
}
|
967
|
+
for alias in aliases_to_delete
|
968
|
+
],
|
969
|
+
},
|
970
|
+
)
|
971
|
+
self._saved_aliases = copy(self._aliases)
|
972
|
+
else: # wandb backend version < 0.13.0
|
973
|
+
aliases = [
|
974
|
+
{
|
975
|
+
"artifactCollectionName": self._name.split(":")[0],
|
976
|
+
"alias": alias,
|
977
|
+
}
|
978
|
+
for alias in self._aliases
|
979
|
+
]
|
980
|
+
|
981
|
+
mutation_template = """
|
982
|
+
mutation updateArtifact(
|
983
|
+
$artifactID: ID!
|
984
|
+
$description: String
|
985
|
+
$metadata: JSONString
|
986
|
+
_TTL_DURATION_SECONDS_TYPE_
|
987
|
+
_TAGS_TO_ADD_TYPE_
|
988
|
+
_TAGS_TO_DELETE_TYPE_
|
989
|
+
$aliases: [ArtifactAliasInput!]
|
990
|
+
) {
|
991
|
+
updateArtifact(
|
992
|
+
input: {
|
993
|
+
artifactID: $artifactID,
|
994
|
+
description: $description,
|
995
|
+
metadata: $metadata,
|
996
|
+
_TTL_DURATION_SECONDS_VALUE_
|
997
|
+
_TAGS_TO_ADD_VALUE_
|
998
|
+
_TAGS_TO_DELETE_VALUE_
|
999
|
+
aliases: $aliases
|
1000
|
+
}
|
1001
|
+
) {
|
1002
|
+
artifact {
|
1003
|
+
...ArtifactFragment
|
1004
|
+
}
|
1005
|
+
}
|
1006
|
+
}
|
1007
|
+
""" + _gql_artifact_fragment()
|
1008
|
+
|
1009
|
+
fields = InternalApi().server_artifact_introspection()
|
1010
|
+
if "ttlIsInherited" in fields:
|
1011
|
+
mutation_template = (
|
1012
|
+
mutation_template.replace(
|
1013
|
+
"_TTL_DURATION_SECONDS_TYPE_",
|
1014
|
+
"$ttlDurationSeconds: Int64",
|
1015
|
+
)
|
1016
|
+
.replace(
|
1017
|
+
"_TTL_DURATION_SECONDS_VALUE_",
|
1018
|
+
"ttlDurationSeconds: $ttlDurationSeconds",
|
1019
|
+
)
|
1020
|
+
.replace(
|
1021
|
+
"_TTL_DURATION_SECONDS_FIELDS_",
|
1022
|
+
"ttlDurationSeconds ttlIsInherited",
|
1023
|
+
)
|
1024
|
+
)
|
1025
|
+
else:
|
1026
|
+
if self._ttl_changed:
|
1027
|
+
termwarn(
|
1028
|
+
"Server not compatible with setting Artifact TTLs, please upgrade the server to use Artifact TTL"
|
1029
|
+
)
|
1030
|
+
mutation_template = (
|
1031
|
+
mutation_template.replace("_TTL_DURATION_SECONDS_TYPE_", "")
|
1032
|
+
.replace("_TTL_DURATION_SECONDS_VALUE_", "")
|
1033
|
+
.replace("_TTL_DURATION_SECONDS_FIELDS_", "")
|
1034
|
+
)
|
1035
|
+
|
1036
|
+
tags_to_add = validate_tags(set(self._tags) - set(self._saved_tags))
|
1037
|
+
tags_to_delete = validate_tags(set(self._saved_tags) - set(self._tags))
|
1038
|
+
if "tags" in fields:
|
1039
|
+
mutation_template = (
|
1040
|
+
mutation_template.replace(
|
1041
|
+
"_TAGS_TO_ADD_TYPE_", "$tagsToAdd: [TagInput!]"
|
1042
|
+
)
|
1043
|
+
.replace("_TAGS_TO_DELETE_TYPE_", "$tagsToDelete: [TagInput!]")
|
1044
|
+
.replace("_TAGS_TO_ADD_VALUE_", "tagsToAdd: $tagsToAdd")
|
1045
|
+
.replace("_TAGS_TO_DELETE_VALUE_", "tagsToDelete: $tagsToDelete")
|
1046
|
+
)
|
1047
|
+
else:
|
1048
|
+
if tags_to_add or tags_to_delete:
|
1049
|
+
termwarn(
|
1050
|
+
"Server not compatible with Artifact tags. "
|
1051
|
+
"To use Artifact tags, please upgrade the server to v0.85 or higher."
|
1052
|
+
)
|
1053
|
+
mutation_template = (
|
1054
|
+
mutation_template.replace("_TAGS_TO_ADD_TYPE_", "")
|
1055
|
+
.replace("_TAGS_TO_DELETE_TYPE_", "")
|
1056
|
+
.replace("_TAGS_TO_ADD_VALUE_", "")
|
1057
|
+
.replace("_TAGS_TO_DELETE_VALUE_", "")
|
1058
|
+
)
|
1059
|
+
|
1060
|
+
mutation = gql(mutation_template)
|
1061
|
+
assert self._client is not None
|
1062
|
+
|
1063
|
+
ttl_duration_input = self._ttl_duration_seconds_to_gql()
|
1064
|
+
response = self._client.execute(
|
1065
|
+
mutation,
|
1066
|
+
variable_values={
|
1067
|
+
"artifactID": self.id,
|
1068
|
+
"description": self.description,
|
1069
|
+
"metadata": util.json_dumps_safer(self.metadata),
|
1070
|
+
"ttlDurationSeconds": ttl_duration_input,
|
1071
|
+
"aliases": aliases,
|
1072
|
+
"tagsToAdd": [{"tagName": tag_name} for tag_name in tags_to_add],
|
1073
|
+
"tagsToDelete": [{"tagName": tag_name} for tag_name in tags_to_delete],
|
1074
|
+
},
|
1075
|
+
)
|
1076
|
+
attrs = response["updateArtifact"]["artifact"]
|
1077
|
+
self._assign_attrs(attrs)
|
1078
|
+
|
1079
|
+
self._ttl_changed = False # Reset after updating artifact
|
1080
|
+
|
1081
|
+
# Adding, removing, getting entries.
|
1082
|
+
|
1083
|
+
def __getitem__(self, name: str) -> WBValue | None:
|
1084
|
+
"""Get the WBValue object located at the artifact relative `name`.
|
1085
|
+
|
1086
|
+
Args:
|
1087
|
+
name: The artifact relative name to get.
|
1088
|
+
|
1089
|
+
Returns:
|
1090
|
+
W&B object that can be logged with `wandb.log()` and visualized in the W&B UI.
|
1091
|
+
|
1092
|
+
Raises:
|
1093
|
+
ArtifactNotLoggedError: If the artifact isn't logged or the run is offline.
|
1094
|
+
"""
|
1095
|
+
return self.get(name)
|
1096
|
+
|
1097
|
+
def __setitem__(self, name: str, item: WBValue) -> ArtifactManifestEntry:
|
1098
|
+
"""Add `item` to the artifact at path `name`.
|
1099
|
+
|
1100
|
+
Args:
|
1101
|
+
name: The path within the artifact to add the object.
|
1102
|
+
item: The object to add.
|
1103
|
+
|
1104
|
+
Returns:
|
1105
|
+
The added manifest entry
|
1106
|
+
|
1107
|
+
Raises:
|
1108
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1109
|
+
version because it is finalized. Log a new artifact version instead.
|
1110
|
+
"""
|
1111
|
+
return self.add(item, name)
|
1112
|
+
|
1113
|
+
@contextlib.contextmanager
|
1114
|
+
@ensure_not_finalized
|
1115
|
+
def new_file(
|
1116
|
+
self, name: str, mode: str = "x", encoding: str | None = None
|
1117
|
+
) -> Iterator[IO]:
|
1118
|
+
"""Open a new temporary file and add it to the artifact.
|
1119
|
+
|
1120
|
+
Args:
|
1121
|
+
name: The name of the new file to add to the artifact.
|
1122
|
+
mode: The file access mode to use to open the new file.
|
1123
|
+
encoding: The encoding used to open the new file.
|
1124
|
+
|
1125
|
+
Returns:
|
1126
|
+
A new file object that can be written to. Upon closing, the file will be
|
1127
|
+
automatically added to the artifact.
|
1128
|
+
|
1129
|
+
Raises:
|
1130
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1131
|
+
version because it is finalized. Log a new artifact version instead.
|
1132
|
+
"""
|
1133
|
+
overwrite: bool = "x" not in mode
|
1134
|
+
|
1135
|
+
if self._tmp_dir is None:
|
1136
|
+
self._tmp_dir = tempfile.TemporaryDirectory()
|
1137
|
+
path = os.path.join(self._tmp_dir.name, name.lstrip("/"))
|
1138
|
+
|
1139
|
+
filesystem.mkdir_exists_ok(os.path.dirname(path))
|
1140
|
+
try:
|
1141
|
+
with util.fsync_open(path, mode, encoding) as f:
|
1142
|
+
yield f
|
1143
|
+
except FileExistsError:
|
1144
|
+
raise ValueError(f"File with name {name!r} already exists at {path!r}")
|
1145
|
+
except UnicodeEncodeError as e:
|
1146
|
+
termerror(
|
1147
|
+
f"Failed to open the provided file ({type(e).__name__}: {e}). Please "
|
1148
|
+
f"provide the proper encoding."
|
1149
|
+
)
|
1150
|
+
raise e
|
1151
|
+
|
1152
|
+
self.add_file(
|
1153
|
+
path, name=name, policy="immutable", skip_cache=True, overwrite=overwrite
|
1154
|
+
)
|
1155
|
+
|
1156
|
+
@ensure_not_finalized
|
1157
|
+
def add_file(
|
1158
|
+
self,
|
1159
|
+
local_path: str,
|
1160
|
+
name: str | None = None,
|
1161
|
+
is_tmp: bool | None = False,
|
1162
|
+
skip_cache: bool | None = False,
|
1163
|
+
policy: Literal["mutable", "immutable"] | None = "mutable",
|
1164
|
+
overwrite: bool = False,
|
1165
|
+
) -> ArtifactManifestEntry:
|
1166
|
+
"""Add a local file to the artifact.
|
1167
|
+
|
1168
|
+
Args:
|
1169
|
+
local_path: The path to the file being added.
|
1170
|
+
name: The path within the artifact to use for the file being added. Defaults
|
1171
|
+
to the basename of the file.
|
1172
|
+
is_tmp: If true, then the file is renamed deterministically to avoid
|
1173
|
+
collisions.
|
1174
|
+
skip_cache: If `True`, W&B will not copy files to the cache after uploading.
|
1175
|
+
policy: By default, set to "mutable". If set to "mutable", create a temporary copy of the
|
1176
|
+
file to prevent corruption during upload. If set to "immutable", disable
|
1177
|
+
protection and rely on the user not to delete or change the file.
|
1178
|
+
overwrite: If `True`, overwrite the file if it already exists.
|
1179
|
+
|
1180
|
+
Returns:
|
1181
|
+
The added manifest entry.
|
1182
|
+
|
1183
|
+
Raises:
|
1184
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1185
|
+
version because it is finalized. Log a new artifact version instead.
|
1186
|
+
ValueError: Policy must be "mutable" or "immutable"
|
1187
|
+
"""
|
1188
|
+
if not os.path.isfile(local_path):
|
1189
|
+
raise ValueError(f"Path is not a file: {local_path!r}")
|
1190
|
+
|
1191
|
+
name = LogicalPath(name or os.path.basename(local_path))
|
1192
|
+
digest = md5_file_b64(local_path)
|
1193
|
+
|
1194
|
+
if is_tmp:
|
1195
|
+
file_path, file_name = os.path.split(name)
|
1196
|
+
file_name_parts = file_name.split(".")
|
1197
|
+
file_name_parts[0] = b64_to_hex_id(digest)[:20]
|
1198
|
+
name = os.path.join(file_path, ".".join(file_name_parts))
|
1199
|
+
|
1200
|
+
return self._add_local_file(
|
1201
|
+
name,
|
1202
|
+
local_path,
|
1203
|
+
digest=digest,
|
1204
|
+
skip_cache=skip_cache,
|
1205
|
+
policy=policy,
|
1206
|
+
overwrite=overwrite,
|
1207
|
+
)
|
1208
|
+
|
1209
|
+
@ensure_not_finalized
|
1210
|
+
def add_dir(
|
1211
|
+
self,
|
1212
|
+
local_path: str,
|
1213
|
+
name: str | None = None,
|
1214
|
+
skip_cache: bool | None = False,
|
1215
|
+
policy: Literal["mutable", "immutable"] | None = "mutable",
|
1216
|
+
) -> None:
|
1217
|
+
"""Add a local directory to the artifact.
|
1218
|
+
|
1219
|
+
Args:
|
1220
|
+
local_path: The path of the local directory.
|
1221
|
+
name: The subdirectory name within an artifact. The name you specify appears
|
1222
|
+
in the W&B App UI nested by artifact's `type`.
|
1223
|
+
Defaults to the root of the artifact.
|
1224
|
+
skip_cache: If set to `True`, W&B will not copy/move files to the cache while uploading
|
1225
|
+
policy: "mutable" | "immutable". By default, "mutable"
|
1226
|
+
"mutable": Create a temporary copy of the file to prevent corruption during upload.
|
1227
|
+
"immutable": Disable protection, rely on the user not to delete or change the file.
|
1228
|
+
|
1229
|
+
Raises:
|
1230
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1231
|
+
version because it is finalized. Log a new artifact version instead.
|
1232
|
+
ValueError: Policy must be "mutable" or "immutable"
|
1233
|
+
"""
|
1234
|
+
if not os.path.isdir(local_path):
|
1235
|
+
raise ValueError("Path is not a directory: {}".format(local_path))
|
1236
|
+
|
1237
|
+
termlog(
|
1238
|
+
"Adding directory to artifact ({})... ".format(
|
1239
|
+
os.path.join(".", os.path.normpath(local_path))
|
1240
|
+
),
|
1241
|
+
newline=False,
|
1242
|
+
)
|
1243
|
+
start_time = time.time()
|
1244
|
+
|
1245
|
+
paths = []
|
1246
|
+
for dirpath, _, filenames in os.walk(local_path, followlinks=True):
|
1247
|
+
for fname in filenames:
|
1248
|
+
physical_path = os.path.join(dirpath, fname)
|
1249
|
+
logical_path = os.path.relpath(physical_path, start=local_path)
|
1250
|
+
if name is not None:
|
1251
|
+
logical_path = os.path.join(name, logical_path)
|
1252
|
+
paths.append((logical_path, physical_path))
|
1253
|
+
|
1254
|
+
def add_manifest_file(log_phy_path: tuple[str, str]) -> None:
|
1255
|
+
logical_path, physical_path = log_phy_path
|
1256
|
+
self._add_local_file(
|
1257
|
+
name=logical_path,
|
1258
|
+
path=physical_path,
|
1259
|
+
skip_cache=skip_cache,
|
1260
|
+
policy=policy,
|
1261
|
+
)
|
1262
|
+
|
1263
|
+
num_threads = 8
|
1264
|
+
pool = multiprocessing.dummy.Pool(num_threads)
|
1265
|
+
pool.map(add_manifest_file, paths)
|
1266
|
+
pool.close()
|
1267
|
+
pool.join()
|
1268
|
+
|
1269
|
+
termlog("Done. %.1fs" % (time.time() - start_time), prefix=False)
|
1270
|
+
|
1271
|
+
@ensure_not_finalized
|
1272
|
+
def add_reference(
|
1273
|
+
self,
|
1274
|
+
uri: ArtifactManifestEntry | str,
|
1275
|
+
name: StrPath | None = None,
|
1276
|
+
checksum: bool = True,
|
1277
|
+
max_objects: int | None = None,
|
1278
|
+
) -> Sequence[ArtifactManifestEntry]:
|
1279
|
+
"""Add a reference denoted by a URI to the artifact.
|
1280
|
+
|
1281
|
+
Unlike files or directories that you add to an artifact, references are not
|
1282
|
+
uploaded to W&B. For more information,
|
1283
|
+
see [Track external files](https://docs.wandb.ai/guides/artifacts/track-external-files).
|
1284
|
+
|
1285
|
+
By default, the following schemes are supported:
|
1286
|
+
|
1287
|
+
- http(s): The size and digest of the file will be inferred by the
|
1288
|
+
`Content-Length` and the `ETag` response headers returned by the server.
|
1289
|
+
- s3: The checksum and size are pulled from the object metadata. If bucket
|
1290
|
+
versioning is enabled, then the version ID is also tracked.
|
1291
|
+
- gs: The checksum and size are pulled from the object metadata. If bucket
|
1292
|
+
versioning is enabled, then the version ID is also tracked.
|
1293
|
+
- https, domain matching `*.blob.core.windows.net` (Azure): The checksum and size
|
1294
|
+
are be pulled from the blob metadata. If storage account versioning is
|
1295
|
+
enabled, then the version ID is also tracked.
|
1296
|
+
- file: The checksum and size are pulled from the file system. This scheme
|
1297
|
+
is useful if you have an NFS share or other externally mounted volume
|
1298
|
+
containing files you wish to track but not necessarily upload.
|
1299
|
+
|
1300
|
+
For any other scheme, the digest is just a hash of the URI and the size is left
|
1301
|
+
blank.
|
1302
|
+
|
1303
|
+
Args:
|
1304
|
+
uri: The URI path of the reference to add. The URI path can be an object
|
1305
|
+
returned from `Artifact.get_entry` to store a reference to another
|
1306
|
+
artifact's entry.
|
1307
|
+
name: The path within the artifact to place the contents of this reference.
|
1308
|
+
checksum: Whether or not to checksum the resource(s) located at the
|
1309
|
+
reference URI. Checksumming is strongly recommended as it enables
|
1310
|
+
automatic integrity validation. Disabling checksumming will speed up
|
1311
|
+
artifact creation but reference directories will not iterated through so the
|
1312
|
+
objects in the directory will not be saved to the artifact. We recommend
|
1313
|
+
setting `checksum=False` when adding reference objects, in which case
|
1314
|
+
a new version will only be created if the reference URI changes.
|
1315
|
+
max_objects: The maximum number of objects to consider when adding a
|
1316
|
+
reference that points to directory or bucket store prefix. By default,
|
1317
|
+
the maximum number of objects allowed for Amazon S3,
|
1318
|
+
GCS, Azure, and local files is 10,000,000. Other URI schemas do not have a maximum.
|
1319
|
+
|
1320
|
+
Returns:
|
1321
|
+
The added manifest entries.
|
1322
|
+
|
1323
|
+
Raises:
|
1324
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1325
|
+
version because it is finalized. Log a new artifact version instead.
|
1326
|
+
"""
|
1327
|
+
if name is not None:
|
1328
|
+
name = LogicalPath(name)
|
1329
|
+
|
1330
|
+
# This is a bit of a hack, we want to check if the uri is a of the type
|
1331
|
+
# ArtifactManifestEntry. If so, then recover the reference URL.
|
1332
|
+
if isinstance(uri, ArtifactManifestEntry):
|
1333
|
+
uri_str = uri.ref_url()
|
1334
|
+
elif isinstance(uri, str):
|
1335
|
+
uri_str = uri
|
1336
|
+
url = urlparse(str(uri_str))
|
1337
|
+
if not url.scheme:
|
1338
|
+
raise ValueError(
|
1339
|
+
"References must be URIs. To reference a local file, use file://"
|
1340
|
+
)
|
1341
|
+
|
1342
|
+
manifest_entries = self._storage_policy.store_reference(
|
1343
|
+
self,
|
1344
|
+
URIStr(uri_str),
|
1345
|
+
name=name,
|
1346
|
+
checksum=checksum,
|
1347
|
+
max_objects=max_objects,
|
1348
|
+
)
|
1349
|
+
for entry in manifest_entries:
|
1350
|
+
self.manifest.add_entry(entry)
|
1351
|
+
|
1352
|
+
return manifest_entries
|
1353
|
+
|
1354
|
+
@ensure_not_finalized
|
1355
|
+
def add(
|
1356
|
+
self, obj: WBValue, name: StrPath, overwrite: bool = False
|
1357
|
+
) -> ArtifactManifestEntry:
|
1358
|
+
"""Add wandb.WBValue `obj` to the artifact.
|
1359
|
+
|
1360
|
+
Args:
|
1361
|
+
obj: The object to add. Currently support one of Bokeh, JoinedTable,
|
1362
|
+
PartitionedTable, Table, Classes, ImageMask, BoundingBoxes2D, Audio,
|
1363
|
+
Image, Video, Html, Object3D
|
1364
|
+
name: The path within the artifact to add the object.
|
1365
|
+
overwrite: If True, overwrite existing objects with the same file path (if applicable).
|
1366
|
+
|
1367
|
+
Returns:
|
1368
|
+
The added manifest entry
|
1369
|
+
|
1370
|
+
Raises:
|
1371
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1372
|
+
version because it is finalized. Log a new artifact version instead.
|
1373
|
+
"""
|
1374
|
+
name = LogicalPath(name)
|
1375
|
+
|
1376
|
+
# This is a "hack" to automatically rename tables added to
|
1377
|
+
# the wandb /media/tables directory to their sha-based name.
|
1378
|
+
# TODO: figure out a more appropriate convention.
|
1379
|
+
is_tmp_name = name.startswith("media/tables")
|
1380
|
+
|
1381
|
+
# Validate that the object is one of the correct wandb.Media types
|
1382
|
+
# TODO: move this to checking subclass of wandb.Media once all are
|
1383
|
+
# generally supported
|
1384
|
+
allowed_types = (
|
1385
|
+
data_types.Bokeh,
|
1386
|
+
data_types.JoinedTable,
|
1387
|
+
data_types.PartitionedTable,
|
1388
|
+
data_types.Table,
|
1389
|
+
data_types.Classes,
|
1390
|
+
data_types.ImageMask,
|
1391
|
+
data_types.BoundingBoxes2D,
|
1392
|
+
data_types.Audio,
|
1393
|
+
data_types.Image,
|
1394
|
+
data_types.Video,
|
1395
|
+
data_types.Html,
|
1396
|
+
data_types.Object3D,
|
1397
|
+
data_types.Molecule,
|
1398
|
+
data_types._SavedModel,
|
1399
|
+
)
|
1400
|
+
if not isinstance(obj, allowed_types):
|
1401
|
+
raise ValueError(
|
1402
|
+
f"Found object of type {obj.__class__}, expected one of: {allowed_types}"
|
1403
|
+
)
|
1404
|
+
|
1405
|
+
obj_id = id(obj)
|
1406
|
+
if obj_id in self._added_objs:
|
1407
|
+
return self._added_objs[obj_id][1]
|
1408
|
+
|
1409
|
+
# If the object is coming from another artifact, save it as a reference
|
1410
|
+
ref_path = obj._get_artifact_entry_ref_url()
|
1411
|
+
if ref_path is not None:
|
1412
|
+
return self.add_reference(ref_path, type(obj).with_suffix(name))[0]
|
1413
|
+
|
1414
|
+
val = obj.to_json(self)
|
1415
|
+
name = obj.with_suffix(name)
|
1416
|
+
entry = self.manifest.get_entry_by_path(name)
|
1417
|
+
if (not overwrite) and (entry is not None):
|
1418
|
+
return entry
|
1419
|
+
|
1420
|
+
if is_tmp_name:
|
1421
|
+
file_path = os.path.join(self._TMP_DIR.name, str(id(self)), name)
|
1422
|
+
folder_path, _ = os.path.split(file_path)
|
1423
|
+
os.makedirs(folder_path, exist_ok=True)
|
1424
|
+
with open(file_path, "w", encoding="utf-8") as tmp_f:
|
1425
|
+
json.dump(val, tmp_f, sort_keys=True)
|
1426
|
+
else:
|
1427
|
+
filemode = "w" if overwrite else "x"
|
1428
|
+
with self.new_file(name, mode=filemode, encoding="utf-8") as f:
|
1429
|
+
json.dump(val, f, sort_keys=True)
|
1430
|
+
file_path = f.name
|
1431
|
+
|
1432
|
+
# Note, we add the file from our temp directory.
|
1433
|
+
# It will be added again later on finalize, but succeed since
|
1434
|
+
# the checksum should match
|
1435
|
+
entry = self.add_file(file_path, name, is_tmp_name)
|
1436
|
+
# We store a reference to the obj so that its id doesn't get reused.
|
1437
|
+
self._added_objs[obj_id] = (obj, entry)
|
1438
|
+
if obj._artifact_target is None:
|
1439
|
+
obj._set_artifact_target(self, entry.path)
|
1440
|
+
|
1441
|
+
if is_tmp_name:
|
1442
|
+
with contextlib.suppress(FileNotFoundError):
|
1443
|
+
os.remove(file_path)
|
1444
|
+
|
1445
|
+
return entry
|
1446
|
+
|
1447
|
+
def _add_local_file(
|
1448
|
+
self,
|
1449
|
+
name: StrPath,
|
1450
|
+
path: StrPath,
|
1451
|
+
digest: B64MD5 | None = None,
|
1452
|
+
skip_cache: bool | None = False,
|
1453
|
+
policy: Literal["mutable", "immutable"] | None = "mutable",
|
1454
|
+
overwrite: bool = False,
|
1455
|
+
) -> ArtifactManifestEntry:
|
1456
|
+
policy = policy or "mutable"
|
1457
|
+
if policy not in ["mutable", "immutable"]:
|
1458
|
+
raise ValueError(
|
1459
|
+
f"Invalid policy {policy!r}. Policy may only be `mutable` or `immutable`."
|
1460
|
+
)
|
1461
|
+
upload_path = path
|
1462
|
+
if policy == "mutable":
|
1463
|
+
with tempfile.NamedTemporaryFile(dir=get_staging_dir(), delete=False) as f:
|
1464
|
+
staging_path = f.name
|
1465
|
+
shutil.copyfile(path, staging_path)
|
1466
|
+
# Set as read-only to prevent changes to the file during upload process
|
1467
|
+
os.chmod(staging_path, stat.S_IRUSR)
|
1468
|
+
upload_path = staging_path
|
1469
|
+
|
1470
|
+
entry = ArtifactManifestEntry(
|
1471
|
+
path=name,
|
1472
|
+
digest=digest or md5_file_b64(upload_path),
|
1473
|
+
size=os.path.getsize(upload_path),
|
1474
|
+
local_path=upload_path,
|
1475
|
+
skip_cache=skip_cache,
|
1476
|
+
)
|
1477
|
+
self.manifest.add_entry(entry, overwrite=overwrite)
|
1478
|
+
self._added_local_paths[os.fspath(path)] = entry
|
1479
|
+
return entry
|
1480
|
+
|
1481
|
+
@ensure_not_finalized
|
1482
|
+
def remove(self, item: StrPath | ArtifactManifestEntry) -> None:
|
1483
|
+
"""Remove an item from the artifact.
|
1484
|
+
|
1485
|
+
Args:
|
1486
|
+
item: The item to remove. Can be a specific manifest entry or the name of an
|
1487
|
+
artifact-relative path. If the item matches a directory all items in
|
1488
|
+
that directory will be removed.
|
1489
|
+
|
1490
|
+
Raises:
|
1491
|
+
ArtifactFinalizedError: You cannot make changes to the current artifact
|
1492
|
+
version because it is finalized. Log a new artifact version instead.
|
1493
|
+
FileNotFoundError: If the item isn't found in the artifact.
|
1494
|
+
"""
|
1495
|
+
if isinstance(item, ArtifactManifestEntry):
|
1496
|
+
self.manifest.remove_entry(item)
|
1497
|
+
return
|
1498
|
+
|
1499
|
+
path = str(PurePosixPath(item))
|
1500
|
+
entry = self.manifest.get_entry_by_path(path)
|
1501
|
+
if entry:
|
1502
|
+
self.manifest.remove_entry(entry)
|
1503
|
+
return
|
1504
|
+
|
1505
|
+
entries = self.manifest.get_entries_in_directory(path)
|
1506
|
+
if not entries:
|
1507
|
+
raise FileNotFoundError(f"No such file or directory: {path}")
|
1508
|
+
for entry in entries:
|
1509
|
+
self.manifest.remove_entry(entry)
|
1510
|
+
|
1511
|
+
def get_path(self, name: StrPath) -> ArtifactManifestEntry:
|
1512
|
+
"""Deprecated. Use `get_entry(name)`."""
|
1513
|
+
deprecate(
|
1514
|
+
field_name=Deprecated.artifact__get_path,
|
1515
|
+
warning_message="Artifact.get_path(name) is deprecated, use Artifact.get_entry(name) instead.",
|
1516
|
+
)
|
1517
|
+
return self.get_entry(name)
|
1518
|
+
|
1519
|
+
@ensure_logged
|
1520
|
+
def get_entry(self, name: StrPath) -> ArtifactManifestEntry:
|
1521
|
+
"""Get the entry with the given name.
|
1522
|
+
|
1523
|
+
Args:
|
1524
|
+
name: The artifact relative name to get
|
1525
|
+
|
1526
|
+
Returns:
|
1527
|
+
A `W&B` object.
|
1528
|
+
|
1529
|
+
Raises:
|
1530
|
+
ArtifactNotLoggedError: if the artifact isn't logged or the run is offline.
|
1531
|
+
KeyError: if the artifact doesn't contain an entry with the given name.
|
1532
|
+
"""
|
1533
|
+
name = LogicalPath(name)
|
1534
|
+
entry = self.manifest.entries.get(name) or self._get_obj_entry(name)[0]
|
1535
|
+
if entry is None:
|
1536
|
+
raise KeyError("Path not contained in artifact: {}".format(name))
|
1537
|
+
entry._parent_artifact = self
|
1538
|
+
return entry
|
1539
|
+
|
1540
|
+
@ensure_logged
|
1541
|
+
def get(self, name: str) -> WBValue | None:
|
1542
|
+
"""Get the WBValue object located at the artifact relative `name`.
|
1543
|
+
|
1544
|
+
Args:
|
1545
|
+
name: The artifact relative name to retrieve.
|
1546
|
+
|
1547
|
+
Returns:
|
1548
|
+
W&B object that can be logged with `wandb.log()` and visualized in the W&B UI.
|
1549
|
+
|
1550
|
+
Raises:
|
1551
|
+
ArtifactNotLoggedError: if the artifact isn't logged or the run is offline
|
1552
|
+
"""
|
1553
|
+
entry, wb_class = self._get_obj_entry(name)
|
1554
|
+
if entry is None or wb_class is None:
|
1555
|
+
return None
|
1556
|
+
|
1557
|
+
# If the entry is a reference from another artifact, then get it directly from
|
1558
|
+
# that artifact.
|
1559
|
+
referenced_id = entry._referenced_artifact_id()
|
1560
|
+
if referenced_id:
|
1561
|
+
assert self._client is not None
|
1562
|
+
artifact = self._from_id(referenced_id, client=self._client)
|
1563
|
+
assert artifact is not None
|
1564
|
+
return artifact.get(util.uri_from_path(entry.ref))
|
1565
|
+
|
1566
|
+
# Special case for wandb.Table. This is intended to be a short term
|
1567
|
+
# optimization. Since tables are likely to download many other assets in
|
1568
|
+
# artifact(s), we eagerly download the artifact using the parallelized
|
1569
|
+
# `artifact.download`. In the future, we should refactor the deserialization
|
1570
|
+
# pattern such that this special case is not needed.
|
1571
|
+
if wb_class == wandb.Table:
|
1572
|
+
self.download()
|
1573
|
+
|
1574
|
+
# Get the ArtifactManifestEntry
|
1575
|
+
item = self.get_entry(entry.path)
|
1576
|
+
item_path = item.download()
|
1577
|
+
|
1578
|
+
# Load the object from the JSON blob
|
1579
|
+
result = None
|
1580
|
+
json_obj = {}
|
1581
|
+
with open(item_path) as file:
|
1582
|
+
json_obj = json.load(file)
|
1583
|
+
result = wb_class.from_json(json_obj, self)
|
1584
|
+
result._set_artifact_source(self, name)
|
1585
|
+
return result
|
1586
|
+
|
1587
|
+
def get_added_local_path_name(self, local_path: str) -> str | None:
|
1588
|
+
"""Get the artifact relative name of a file added by a local filesystem path.
|
1589
|
+
|
1590
|
+
Args:
|
1591
|
+
local_path: The local path to resolve into an artifact relative name.
|
1592
|
+
|
1593
|
+
Returns:
|
1594
|
+
The artifact relative name.
|
1595
|
+
"""
|
1596
|
+
entry = self._added_local_paths.get(local_path, None)
|
1597
|
+
if entry is None:
|
1598
|
+
return None
|
1599
|
+
return entry.path
|
1600
|
+
|
1601
|
+
def _get_obj_entry(
|
1602
|
+
self, name: str
|
1603
|
+
) -> tuple[ArtifactManifestEntry, Type[WBValue]] | tuple[None, None]: # noqa: UP006 # `type` shadows `Artifact.type`
|
1604
|
+
"""Return an object entry by name, handling any type suffixes.
|
1605
|
+
|
1606
|
+
When objects are added with `.add(obj, name)`, the name is typically changed to
|
1607
|
+
include the suffix of the object type when serializing to JSON. So we need to be
|
1608
|
+
able to resolve a name, without tasking the user with appending .THING.json.
|
1609
|
+
This method returns an entry if it exists by a suffixed name.
|
1610
|
+
|
1611
|
+
Args:
|
1612
|
+
name: name used when adding
|
1613
|
+
"""
|
1614
|
+
for wb_class in WBValue.type_mapping().values():
|
1615
|
+
wandb_file_name = wb_class.with_suffix(name)
|
1616
|
+
entry = self.manifest.entries.get(wandb_file_name)
|
1617
|
+
if entry is not None:
|
1618
|
+
return entry, wb_class
|
1619
|
+
return None, None
|
1620
|
+
|
1621
|
+
# Downloading.
|
1622
|
+
|
1623
|
+
@ensure_logged
|
1624
|
+
def download(
|
1625
|
+
self,
|
1626
|
+
root: StrPath | None = None,
|
1627
|
+
allow_missing_references: bool = False,
|
1628
|
+
skip_cache: bool | None = None,
|
1629
|
+
path_prefix: StrPath | None = None,
|
1630
|
+
) -> FilePathStr:
|
1631
|
+
"""Download the contents of the artifact to the specified root directory.
|
1632
|
+
|
1633
|
+
Existing files located within `root` are not modified. Explicitly delete `root`
|
1634
|
+
before you call `download` if you want the contents of `root` to exactly match
|
1635
|
+
the artifact.
|
1636
|
+
|
1637
|
+
Args:
|
1638
|
+
root: The directory W&B stores the artifact's files.
|
1639
|
+
allow_missing_references: If set to `True`, any invalid reference paths
|
1640
|
+
will be ignored while downloading referenced files.
|
1641
|
+
skip_cache: If set to `True`, the artifact cache will be skipped when
|
1642
|
+
downloading and W&B will download each file into the default root or
|
1643
|
+
specified download directory.
|
1644
|
+
path_prefix: If specified, only files with a path that starts with the given
|
1645
|
+
prefix will be downloaded. Uses unix format (forward slashes).
|
1646
|
+
|
1647
|
+
Returns:
|
1648
|
+
The path to the downloaded contents.
|
1649
|
+
|
1650
|
+
Raises:
|
1651
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
1652
|
+
RuntimeError: If the artifact is attempted to be downloaded in offline mode.
|
1653
|
+
"""
|
1654
|
+
root = FilePathStr(str(root or self._default_root()))
|
1655
|
+
self._add_download_root(root)
|
1656
|
+
|
1657
|
+
# TODO: we need a better way to check for offline mode across the app, as this is an anti-pattern
|
1658
|
+
if env.is_offline() or util._is_offline():
|
1659
|
+
raise RuntimeError("Cannot download artifacts in offline mode.")
|
1660
|
+
|
1661
|
+
# TODO: download artifacts using core when implemented
|
1662
|
+
# if is_require_core():
|
1663
|
+
# return self._download_using_core(
|
1664
|
+
# root=root,
|
1665
|
+
# allow_missing_references=allow_missing_references,
|
1666
|
+
# skip_cache=bool(skip_cache),
|
1667
|
+
# path_prefix=path_prefix,
|
1668
|
+
# )
|
1669
|
+
return self._download(
|
1670
|
+
root=root,
|
1671
|
+
allow_missing_references=allow_missing_references,
|
1672
|
+
skip_cache=skip_cache,
|
1673
|
+
path_prefix=path_prefix,
|
1674
|
+
)
|
1675
|
+
|
1676
|
+
def _download_using_core(
|
1677
|
+
self,
|
1678
|
+
root: str,
|
1679
|
+
allow_missing_references: bool = False,
|
1680
|
+
skip_cache: bool = False,
|
1681
|
+
path_prefix: StrPath | None = None,
|
1682
|
+
) -> FilePathStr:
|
1683
|
+
import pathlib
|
1684
|
+
|
1685
|
+
from wandb.sdk.backend.backend import Backend
|
1686
|
+
|
1687
|
+
if wandb.run is None:
|
1688
|
+
# ensure wandb-core is up and running
|
1689
|
+
from wandb.sdk import wandb_setup
|
1690
|
+
|
1691
|
+
wl = wandb_setup.setup()
|
1692
|
+
assert wl is not None
|
1693
|
+
|
1694
|
+
stream_id = generate_id()
|
1695
|
+
|
1696
|
+
settings = wl.settings.to_proto()
|
1697
|
+
# TODO: remove this
|
1698
|
+
tmp_dir = pathlib.Path(tempfile.mkdtemp())
|
1699
|
+
|
1700
|
+
settings.sync_dir.value = str(tmp_dir)
|
1701
|
+
settings.sync_file.value = str(tmp_dir / f"{stream_id}.wandb")
|
1702
|
+
settings.files_dir.value = str(tmp_dir / "files")
|
1703
|
+
settings.run_id.value = stream_id
|
1704
|
+
|
1705
|
+
service = wl.service
|
1706
|
+
assert service
|
1707
|
+
|
1708
|
+
service.inform_init(settings=settings, run_id=stream_id)
|
1709
|
+
|
1710
|
+
mailbox = Mailbox()
|
1711
|
+
backend = Backend(
|
1712
|
+
settings=wl.settings,
|
1713
|
+
service=service,
|
1714
|
+
mailbox=mailbox,
|
1715
|
+
)
|
1716
|
+
backend.ensure_launched()
|
1717
|
+
|
1718
|
+
assert backend.interface
|
1719
|
+
backend.interface._stream_id = stream_id # type: ignore
|
1720
|
+
|
1721
|
+
mailbox.enable_keepalive()
|
1722
|
+
else:
|
1723
|
+
assert wandb.run._backend
|
1724
|
+
backend = wandb.run._backend
|
1725
|
+
|
1726
|
+
assert backend.interface
|
1727
|
+
handle = backend.interface.deliver_download_artifact(
|
1728
|
+
self.id, # type: ignore
|
1729
|
+
root,
|
1730
|
+
allow_missing_references,
|
1731
|
+
skip_cache,
|
1732
|
+
path_prefix, # type: ignore
|
1733
|
+
)
|
1734
|
+
# TODO: Start the download process in the user process too, to handle reference downloads
|
1735
|
+
self._download(
|
1736
|
+
root=root,
|
1737
|
+
allow_missing_references=allow_missing_references,
|
1738
|
+
skip_cache=skip_cache,
|
1739
|
+
path_prefix=path_prefix,
|
1740
|
+
)
|
1741
|
+
result = handle.wait(timeout=-1)
|
1742
|
+
|
1743
|
+
if result is None:
|
1744
|
+
handle.abandon()
|
1745
|
+
assert result is not None
|
1746
|
+
response = result.response.download_artifact_response
|
1747
|
+
if response.error_message:
|
1748
|
+
raise ValueError(f"Error downloading artifact: {response.error_message}")
|
1749
|
+
|
1750
|
+
return FilePathStr(root)
|
1751
|
+
|
1752
|
+
def _download(
|
1753
|
+
self,
|
1754
|
+
root: str,
|
1755
|
+
allow_missing_references: bool = False,
|
1756
|
+
skip_cache: bool | None = None,
|
1757
|
+
path_prefix: StrPath | None = None,
|
1758
|
+
) -> FilePathStr:
|
1759
|
+
nfiles = len(self.manifest.entries)
|
1760
|
+
size = sum(e.size or 0 for e in self.manifest.entries.values())
|
1761
|
+
log = False
|
1762
|
+
if nfiles > 5000 or size > 50 * 1024 * 1024:
|
1763
|
+
log = True
|
1764
|
+
termlog(
|
1765
|
+
"Downloading large artifact {}, {:.2f}MB. {} files... ".format(
|
1766
|
+
self.name, size / (1024 * 1024), nfiles
|
1767
|
+
),
|
1768
|
+
)
|
1769
|
+
start_time = datetime.now()
|
1770
|
+
download_logger = ArtifactDownloadLogger(nfiles=nfiles)
|
1771
|
+
|
1772
|
+
def _download_entry(
|
1773
|
+
entry: ArtifactManifestEntry,
|
1774
|
+
api_key: str | None,
|
1775
|
+
cookies: dict | None,
|
1776
|
+
headers: dict | None,
|
1777
|
+
) -> None:
|
1778
|
+
_thread_local_api_settings.api_key = api_key
|
1779
|
+
_thread_local_api_settings.cookies = cookies
|
1780
|
+
_thread_local_api_settings.headers = headers
|
1781
|
+
|
1782
|
+
try:
|
1783
|
+
entry.download(root, skip_cache=skip_cache)
|
1784
|
+
except FileNotFoundError as e:
|
1785
|
+
if allow_missing_references:
|
1786
|
+
wandb.termwarn(str(e))
|
1787
|
+
return
|
1788
|
+
raise
|
1789
|
+
except _GCSIsADirectoryError as e:
|
1790
|
+
logger.debug(str(e))
|
1791
|
+
return
|
1792
|
+
download_logger.notify_downloaded()
|
1793
|
+
|
1794
|
+
download_entry = partial(
|
1795
|
+
_download_entry,
|
1796
|
+
api_key=_thread_local_api_settings.api_key,
|
1797
|
+
cookies=_thread_local_api_settings.cookies,
|
1798
|
+
headers=_thread_local_api_settings.headers,
|
1799
|
+
)
|
1800
|
+
|
1801
|
+
with concurrent.futures.ThreadPoolExecutor(64) as executor:
|
1802
|
+
active_futures = set()
|
1803
|
+
has_next_page = True
|
1804
|
+
cursor = None
|
1805
|
+
while has_next_page:
|
1806
|
+
fetch_url_batch_size = env.get_artifact_fetch_file_url_batch_size()
|
1807
|
+
attrs = self._fetch_file_urls(cursor, fetch_url_batch_size)
|
1808
|
+
has_next_page = attrs["pageInfo"]["hasNextPage"]
|
1809
|
+
cursor = attrs["pageInfo"]["endCursor"]
|
1810
|
+
for edge in attrs["edges"]:
|
1811
|
+
entry = self.get_entry(edge["node"]["name"])
|
1812
|
+
# TODO: uncomment once artifact downloads are supported in core
|
1813
|
+
# if require_core and entry.ref is None:
|
1814
|
+
# # Handled by core
|
1815
|
+
# continue
|
1816
|
+
entry._download_url = edge["node"]["directUrl"]
|
1817
|
+
if (not path_prefix) or entry.path.startswith(str(path_prefix)):
|
1818
|
+
active_futures.add(executor.submit(download_entry, entry))
|
1819
|
+
# Wait for download threads to catch up.
|
1820
|
+
max_backlog = fetch_url_batch_size
|
1821
|
+
if len(active_futures) > max_backlog:
|
1822
|
+
for future in concurrent.futures.as_completed(active_futures):
|
1823
|
+
future.result() # check for errors
|
1824
|
+
active_futures.remove(future)
|
1825
|
+
if len(active_futures) <= max_backlog:
|
1826
|
+
break
|
1827
|
+
# Check for errors.
|
1828
|
+
for future in concurrent.futures.as_completed(active_futures):
|
1829
|
+
future.result()
|
1830
|
+
|
1831
|
+
if log:
|
1832
|
+
now = datetime.now()
|
1833
|
+
delta = abs((now - start_time).total_seconds())
|
1834
|
+
hours = int(delta // 3600)
|
1835
|
+
minutes = int((delta - hours * 3600) // 60)
|
1836
|
+
seconds = delta - hours * 3600 - minutes * 60
|
1837
|
+
termlog(
|
1838
|
+
f"Done. {hours}:{minutes}:{seconds:.1f}",
|
1839
|
+
prefix=False,
|
1840
|
+
)
|
1841
|
+
return FilePathStr(root)
|
1842
|
+
|
1843
|
+
@retry.retriable(
|
1844
|
+
retry_timedelta=timedelta(minutes=3),
|
1845
|
+
retryable_exceptions=(requests.RequestException),
|
1846
|
+
)
|
1847
|
+
def _fetch_file_urls(self, cursor: str | None, per_page: int | None = 5000) -> Any:
|
1848
|
+
query = gql(
|
1849
|
+
"""
|
1850
|
+
query ArtifactFileURLs($id: ID!, $cursor: String, $perPage: Int) {
|
1851
|
+
artifact(id: $id) {
|
1852
|
+
files(after: $cursor, first: $perPage) {
|
1853
|
+
pageInfo {
|
1854
|
+
hasNextPage
|
1855
|
+
endCursor
|
1856
|
+
}
|
1857
|
+
edges {
|
1858
|
+
node {
|
1859
|
+
name
|
1860
|
+
directUrl
|
1861
|
+
}
|
1862
|
+
}
|
1863
|
+
}
|
1864
|
+
}
|
1865
|
+
}
|
1866
|
+
"""
|
1867
|
+
)
|
1868
|
+
assert self._client is not None
|
1869
|
+
response = self._client.execute(
|
1870
|
+
query,
|
1871
|
+
variable_values={"id": self.id, "cursor": cursor, "perPage": per_page},
|
1872
|
+
timeout=60,
|
1873
|
+
)
|
1874
|
+
return response["artifact"]["files"]
|
1875
|
+
|
1876
|
+
@ensure_logged
|
1877
|
+
def checkout(self, root: str | None = None) -> str:
|
1878
|
+
"""Replace the specified root directory with the contents of the artifact.
|
1879
|
+
|
1880
|
+
WARNING: This will delete all files in `root` that are not included in the
|
1881
|
+
artifact.
|
1882
|
+
|
1883
|
+
Args:
|
1884
|
+
root: The directory to replace with this artifact's files.
|
1885
|
+
|
1886
|
+
Returns:
|
1887
|
+
The path of the checked out contents.
|
1888
|
+
|
1889
|
+
Raises:
|
1890
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
1891
|
+
"""
|
1892
|
+
root = root or self._default_root(include_version=False)
|
1893
|
+
|
1894
|
+
for dirpath, _, files in os.walk(root):
|
1895
|
+
for file in files:
|
1896
|
+
full_path = os.path.join(dirpath, file)
|
1897
|
+
artifact_path = os.path.relpath(full_path, start=root)
|
1898
|
+
try:
|
1899
|
+
self.get_entry(artifact_path)
|
1900
|
+
except KeyError:
|
1901
|
+
# File is not part of the artifact, remove it.
|
1902
|
+
os.remove(full_path)
|
1903
|
+
|
1904
|
+
return self.download(root=root)
|
1905
|
+
|
1906
|
+
@ensure_logged
|
1907
|
+
def verify(self, root: str | None = None) -> None:
|
1908
|
+
"""Verify that the contents of an artifact match the manifest.
|
1909
|
+
|
1910
|
+
All files in the directory are checksummed and the checksums are then
|
1911
|
+
cross-referenced against the artifact's manifest. References are not verified.
|
1912
|
+
|
1913
|
+
Args:
|
1914
|
+
root: The directory to verify. If None artifact will be downloaded to
|
1915
|
+
'./artifacts/self.name/'
|
1916
|
+
|
1917
|
+
Raises:
|
1918
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
1919
|
+
ValueError: If the verification fails.
|
1920
|
+
"""
|
1921
|
+
root = root or self._default_root()
|
1922
|
+
|
1923
|
+
for dirpath, _, files in os.walk(root):
|
1924
|
+
for file in files:
|
1925
|
+
full_path = os.path.join(dirpath, file)
|
1926
|
+
artifact_path = os.path.relpath(full_path, start=root)
|
1927
|
+
try:
|
1928
|
+
self.get_entry(artifact_path)
|
1929
|
+
except KeyError:
|
1930
|
+
raise ValueError(
|
1931
|
+
"Found file {} which is not a member of artifact {}".format(
|
1932
|
+
full_path, self.name
|
1933
|
+
)
|
1934
|
+
)
|
1935
|
+
|
1936
|
+
ref_count = 0
|
1937
|
+
for entry in self.manifest.entries.values():
|
1938
|
+
if entry.ref is None:
|
1939
|
+
if md5_file_b64(os.path.join(root, entry.path)) != entry.digest:
|
1940
|
+
raise ValueError("Digest mismatch for file: {}".format(entry.path))
|
1941
|
+
else:
|
1942
|
+
ref_count += 1
|
1943
|
+
if ref_count > 0:
|
1944
|
+
print("Warning: skipped verification of {} refs".format(ref_count))
|
1945
|
+
|
1946
|
+
@ensure_logged
|
1947
|
+
def file(self, root: str | None = None) -> StrPath:
|
1948
|
+
"""Download a single file artifact to the directory you specify with `root`.
|
1949
|
+
|
1950
|
+
Args:
|
1951
|
+
root: The root directory to store the file. Defaults to
|
1952
|
+
'./artifacts/self.name/'.
|
1953
|
+
|
1954
|
+
Returns:
|
1955
|
+
The full path of the downloaded file.
|
1956
|
+
|
1957
|
+
Raises:
|
1958
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
1959
|
+
ValueError: If the artifact contains more than one file.
|
1960
|
+
"""
|
1961
|
+
if root is None:
|
1962
|
+
root = os.path.join(".", "artifacts", self.name)
|
1963
|
+
|
1964
|
+
if len(self.manifest.entries) > 1:
|
1965
|
+
raise ValueError(
|
1966
|
+
"This artifact contains more than one file, call `.download()` to get "
|
1967
|
+
'all files or call .get_entry("filename").download()'
|
1968
|
+
)
|
1969
|
+
|
1970
|
+
return self.get_entry(list(self.manifest.entries)[0]).download(root)
|
1971
|
+
|
1972
|
+
@ensure_logged
|
1973
|
+
def files(
|
1974
|
+
self, names: list[str] | None = None, per_page: int = 50
|
1975
|
+
) -> ArtifactFiles:
|
1976
|
+
"""Iterate over all files stored in this artifact.
|
1977
|
+
|
1978
|
+
Args:
|
1979
|
+
names: The filename paths relative to the root of the artifact you wish to
|
1980
|
+
list.
|
1981
|
+
per_page: The number of files to return per request.
|
1982
|
+
|
1983
|
+
Returns:
|
1984
|
+
An iterator containing `File` objects.
|
1985
|
+
|
1986
|
+
Raises:
|
1987
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
1988
|
+
"""
|
1989
|
+
return ArtifactFiles(self._client, self, names, per_page)
|
1990
|
+
|
1991
|
+
def _default_root(self, include_version: bool = True) -> FilePathStr:
|
1992
|
+
name = self.source_name if include_version else self.source_name.split(":")[0]
|
1993
|
+
root = os.path.join(env.get_artifact_dir(), name)
|
1994
|
+
# In case we're on a system where the artifact dir has a name corresponding to
|
1995
|
+
# an unexpected filesystem, we'll check for alternate roots. If one exists we'll
|
1996
|
+
# use that, otherwise we'll fall back to the system-preferred path.
|
1997
|
+
path = filesystem.check_exists(root) or filesystem.system_preferred_path(root)
|
1998
|
+
return FilePathStr(str(path))
|
1999
|
+
|
2000
|
+
def _add_download_root(self, dir_path: str) -> None:
|
2001
|
+
self._download_roots.add(os.path.abspath(dir_path))
|
2002
|
+
|
2003
|
+
def _local_path_to_name(self, file_path: str) -> str | None:
|
2004
|
+
"""Convert a local file path to a path entry in the artifact."""
|
2005
|
+
abs_file_path = os.path.abspath(file_path)
|
2006
|
+
abs_file_parts = abs_file_path.split(os.sep)
|
2007
|
+
for i in range(len(abs_file_parts) + 1):
|
2008
|
+
if os.path.join(os.sep, *abs_file_parts[:i]) in self._download_roots:
|
2009
|
+
return os.path.join(*abs_file_parts[i:])
|
2010
|
+
return None
|
2011
|
+
|
2012
|
+
# Others.
|
2013
|
+
|
2014
|
+
@ensure_logged
|
2015
|
+
def delete(self, delete_aliases: bool = False) -> None:
|
2016
|
+
"""Delete an artifact and its files.
|
2017
|
+
|
2018
|
+
If called on a linked artifact (i.e. a member of a portfolio collection): only the link is deleted, and the
|
2019
|
+
source artifact is unaffected.
|
2020
|
+
|
2021
|
+
Args:
|
2022
|
+
delete_aliases: If set to `True`, deletes all aliases associated with the artifact.
|
2023
|
+
Otherwise, this raises an exception if the artifact has existing
|
2024
|
+
aliases.
|
2025
|
+
This parameter is ignored if the artifact is linked (i.e. a member of a portfolio collection).
|
2026
|
+
|
2027
|
+
Raises:
|
2028
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
2029
|
+
"""
|
2030
|
+
if self.collection.is_sequence():
|
2031
|
+
self._delete(delete_aliases)
|
2032
|
+
else:
|
2033
|
+
self._unlink()
|
2034
|
+
|
2035
|
+
@normalize_exceptions
|
2036
|
+
def _delete(self, delete_aliases: bool = False) -> None:
|
2037
|
+
mutation = gql(
|
2038
|
+
"""
|
2039
|
+
mutation DeleteArtifact($artifactID: ID!, $deleteAliases: Boolean) {
|
2040
|
+
deleteArtifact(input: {
|
2041
|
+
artifactID: $artifactID
|
2042
|
+
deleteAliases: $deleteAliases
|
2043
|
+
}) {
|
2044
|
+
artifact {
|
2045
|
+
id
|
2046
|
+
}
|
2047
|
+
}
|
2048
|
+
}
|
2049
|
+
"""
|
2050
|
+
)
|
2051
|
+
assert self._client is not None
|
2052
|
+
self._client.execute(
|
2053
|
+
mutation,
|
2054
|
+
variable_values={
|
2055
|
+
"artifactID": self.id,
|
2056
|
+
"deleteAliases": delete_aliases,
|
2057
|
+
},
|
2058
|
+
)
|
2059
|
+
|
2060
|
+
@normalize_exceptions
|
2061
|
+
def link(self, target_path: str, aliases: list[str] | None = None) -> None:
|
2062
|
+
"""Link this artifact to a portfolio (a promoted collection of artifacts).
|
2063
|
+
|
2064
|
+
Args:
|
2065
|
+
target_path: The path to the portfolio inside a project.
|
2066
|
+
The target path must adhere to one of the following
|
2067
|
+
schemas `{portfolio}`, `{project}/{portfolio}` or
|
2068
|
+
`{entity}/{project}/{portfolio}`.
|
2069
|
+
To link the artifact to the Model Registry, rather than to a generic
|
2070
|
+
portfolio inside a project, set `target_path` to the following
|
2071
|
+
schema `{"model-registry"}/{Registered Model Name}` or
|
2072
|
+
`{entity}/{"model-registry"}/{Registered Model Name}`.
|
2073
|
+
aliases: A list of strings that uniquely identifies the artifact inside the
|
2074
|
+
specified portfolio.
|
2075
|
+
|
2076
|
+
Raises:
|
2077
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
2078
|
+
"""
|
2079
|
+
if wandb.run is None:
|
2080
|
+
with wandb.init( # type: ignore
|
2081
|
+
entity=self._source_entity,
|
2082
|
+
project=self._source_project,
|
2083
|
+
job_type="auto",
|
2084
|
+
settings=wandb.Settings(silent="true"),
|
2085
|
+
) as run:
|
2086
|
+
run.link_artifact(self, target_path, aliases)
|
2087
|
+
else:
|
2088
|
+
wandb.run.link_artifact(self, target_path, aliases)
|
2089
|
+
|
2090
|
+
@ensure_logged
|
2091
|
+
def unlink(self) -> None:
|
2092
|
+
"""Unlink this artifact if it is currently a member of a portfolio (a promoted collection of artifacts).
|
2093
|
+
|
2094
|
+
Raises:
|
2095
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
2096
|
+
ValueError: If the artifact is not linked, i.e. it is not a member of a portfolio collection.
|
2097
|
+
"""
|
2098
|
+
# Fail early if this isn't a linked artifact to begin with
|
2099
|
+
if self.collection.is_sequence():
|
2100
|
+
raise ValueError(
|
2101
|
+
f"Artifact {self.qualified_name!r} is not a linked artifact and cannot be unlinked. "
|
2102
|
+
f"To delete it, use {self.delete.__qualname__!r} instead."
|
2103
|
+
)
|
2104
|
+
|
2105
|
+
self._unlink()
|
2106
|
+
|
2107
|
+
@normalize_exceptions
|
2108
|
+
def _unlink(self) -> None:
|
2109
|
+
mutation = gql(
|
2110
|
+
"""
|
2111
|
+
mutation UnlinkArtifact($artifactID: ID!, $artifactPortfolioID: ID!) {
|
2112
|
+
unlinkArtifact(
|
2113
|
+
input: { artifactID: $artifactID, artifactPortfolioID: $artifactPortfolioID }
|
2114
|
+
) {
|
2115
|
+
artifactID
|
2116
|
+
success
|
2117
|
+
clientMutationId
|
2118
|
+
}
|
2119
|
+
}
|
2120
|
+
"""
|
2121
|
+
)
|
2122
|
+
assert self._client is not None
|
2123
|
+
self._client.execute(
|
2124
|
+
mutation,
|
2125
|
+
variable_values={
|
2126
|
+
"artifactID": self.id,
|
2127
|
+
"artifactPortfolioID": self.collection.id,
|
2128
|
+
},
|
2129
|
+
)
|
2130
|
+
|
2131
|
+
@ensure_logged
|
2132
|
+
def used_by(self) -> list[Run]:
|
2133
|
+
"""Get a list of the runs that have used this artifact.
|
2134
|
+
|
2135
|
+
Returns:
|
2136
|
+
A list of `Run` objects.
|
2137
|
+
|
2138
|
+
Raises:
|
2139
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
2140
|
+
"""
|
2141
|
+
query = gql(
|
2142
|
+
"""
|
2143
|
+
query ArtifactUsedBy(
|
2144
|
+
$id: ID!,
|
2145
|
+
) {
|
2146
|
+
artifact(id: $id) {
|
2147
|
+
usedBy {
|
2148
|
+
edges {
|
2149
|
+
node {
|
2150
|
+
name
|
2151
|
+
project {
|
2152
|
+
name
|
2153
|
+
entityName
|
2154
|
+
}
|
2155
|
+
}
|
2156
|
+
}
|
2157
|
+
}
|
2158
|
+
}
|
2159
|
+
}
|
2160
|
+
"""
|
2161
|
+
)
|
2162
|
+
assert self._client is not None
|
2163
|
+
response = self._client.execute(
|
2164
|
+
query,
|
2165
|
+
variable_values={"id": self.id},
|
2166
|
+
)
|
2167
|
+
return [
|
2168
|
+
Run(
|
2169
|
+
self._client,
|
2170
|
+
edge["node"]["project"]["entityName"],
|
2171
|
+
edge["node"]["project"]["name"],
|
2172
|
+
edge["node"]["name"],
|
2173
|
+
)
|
2174
|
+
for edge in response.get("artifact", {}).get("usedBy", {}).get("edges", [])
|
2175
|
+
]
|
2176
|
+
|
2177
|
+
@ensure_logged
|
2178
|
+
def logged_by(self) -> Run | None:
|
2179
|
+
"""Get the W&B run that originally logged the artifact.
|
2180
|
+
|
2181
|
+
Returns:
|
2182
|
+
The name of the W&B run that originally logged the artifact.
|
2183
|
+
|
2184
|
+
Raises:
|
2185
|
+
ArtifactNotLoggedError: If the artifact is not logged.
|
2186
|
+
"""
|
2187
|
+
query = gql(
|
2188
|
+
"""
|
2189
|
+
query ArtifactCreatedBy(
|
2190
|
+
$id: ID!
|
2191
|
+
) {
|
2192
|
+
artifact(id: $id) {
|
2193
|
+
createdBy {
|
2194
|
+
... on Run {
|
2195
|
+
name
|
2196
|
+
project {
|
2197
|
+
name
|
2198
|
+
entityName
|
2199
|
+
}
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
}
|
2203
|
+
}
|
2204
|
+
"""
|
2205
|
+
)
|
2206
|
+
assert self._client is not None
|
2207
|
+
response = self._client.execute(
|
2208
|
+
query,
|
2209
|
+
variable_values={"id": self.id},
|
2210
|
+
)
|
2211
|
+
creator = response.get("artifact", {}).get("createdBy", {})
|
2212
|
+
if creator.get("name") is None:
|
2213
|
+
return None
|
2214
|
+
return Run(
|
2215
|
+
self._client,
|
2216
|
+
creator["project"]["entityName"],
|
2217
|
+
creator["project"]["name"],
|
2218
|
+
creator["name"],
|
2219
|
+
)
|
2220
|
+
|
2221
|
+
@ensure_logged
|
2222
|
+
def json_encode(self) -> dict[str, Any]:
|
2223
|
+
"""Returns the artifact encoded to the JSON format.
|
2224
|
+
|
2225
|
+
Returns:
|
2226
|
+
A `dict` with `string` keys representing attributes of the artifact.
|
2227
|
+
"""
|
2228
|
+
return util.artifact_to_json(self)
|
2229
|
+
|
2230
|
+
@staticmethod
|
2231
|
+
def _expected_type(
|
2232
|
+
entity_name: str, project_name: str, name: str, client: RetryingClient
|
2233
|
+
) -> str | None:
|
2234
|
+
"""Returns the expected type for a given artifact name and project."""
|
2235
|
+
query = gql(
|
2236
|
+
"""
|
2237
|
+
query ArtifactType(
|
2238
|
+
$entityName: String,
|
2239
|
+
$projectName: String,
|
2240
|
+
$name: String!
|
2241
|
+
) {
|
2242
|
+
project(name: $projectName, entityName: $entityName) {
|
2243
|
+
artifact(name: $name) {
|
2244
|
+
artifactType {
|
2245
|
+
name
|
2246
|
+
}
|
2247
|
+
}
|
2248
|
+
}
|
2249
|
+
}
|
2250
|
+
"""
|
2251
|
+
)
|
2252
|
+
if ":" not in name:
|
2253
|
+
name += ":latest"
|
2254
|
+
response = client.execute(
|
2255
|
+
query,
|
2256
|
+
variable_values={
|
2257
|
+
"entityName": entity_name,
|
2258
|
+
"projectName": project_name,
|
2259
|
+
"name": name,
|
2260
|
+
},
|
2261
|
+
)
|
2262
|
+
return (
|
2263
|
+
((response.get("project") or {}).get("artifact") or {}).get("artifactType")
|
2264
|
+
or {}
|
2265
|
+
).get("name")
|
2266
|
+
|
2267
|
+
@staticmethod
|
2268
|
+
def _normalize_metadata(metadata: dict[str, Any] | None) -> dict[str, Any]:
|
2269
|
+
if metadata is None:
|
2270
|
+
return {}
|
2271
|
+
if not isinstance(metadata, dict):
|
2272
|
+
raise TypeError(f"metadata must be dict, not {type(metadata)}")
|
2273
|
+
return cast(
|
2274
|
+
Dict[str, Any], json.loads(json.dumps(util.json_friendly_val(metadata)))
|
2275
|
+
)
|
2276
|
+
|
2277
|
+
def _load_manifest(self, url: str) -> ArtifactManifest:
|
2278
|
+
with requests.get(url) as response:
|
2279
|
+
response.raise_for_status()
|
2280
|
+
return ArtifactManifest.from_manifest_json(response.json())
|
2281
|
+
|
2282
|
+
def _ttl_duration_seconds_to_gql(self) -> int | None:
|
2283
|
+
# Set artifact ttl value to ttl_duration_seconds if the user set a value
|
2284
|
+
# otherwise use ttl_status to indicate the backend INHERIT(-1) or DISABLED(-2) when the TTL is None
|
2285
|
+
# When ttl_change = None its a no op since nothing changed
|
2286
|
+
INHERIT = -1 # noqa: N806
|
2287
|
+
DISABLED = -2 # noqa: N806
|
2288
|
+
|
2289
|
+
if not self._ttl_changed:
|
2290
|
+
return None
|
2291
|
+
if self._ttl_is_inherited:
|
2292
|
+
return INHERIT
|
2293
|
+
return self._ttl_duration_seconds or DISABLED
|
2294
|
+
|
2295
|
+
|
2296
|
+
def _ttl_duration_seconds_from_gql(gql_ttl_duration_seconds: int | None) -> int | None:
|
2297
|
+
# If gql_ttl_duration_seconds is not positive, its indicating that TTL is DISABLED(-2)
|
2298
|
+
# gql_ttl_duration_seconds only returns None if the server is not compatible with setting Artifact TTLs
|
2299
|
+
if gql_ttl_duration_seconds and gql_ttl_duration_seconds > 0:
|
2300
|
+
return gql_ttl_duration_seconds
|
2301
|
+
return None
|
2302
|
+
|
2303
|
+
|
2304
|
+
def _gql_artifact_fragment() -> str:
|
2305
|
+
"""Return a GraphQL query fragment with all parseable Artifact attributes."""
|
2306
|
+
allowed_fields = set(InternalApi().server_artifact_introspection())
|
2307
|
+
|
2308
|
+
supports_ttl = "ttlIsInherited" in allowed_fields
|
2309
|
+
supports_tags = "tags" in allowed_fields
|
2310
|
+
|
2311
|
+
ttl_duration_seconds = "ttlDurationSeconds" if supports_ttl else ""
|
2312
|
+
ttl_is_inherited = "ttlIsInherited" if supports_ttl else ""
|
2313
|
+
|
2314
|
+
tags = "tags {name}" if supports_tags else ""
|
2315
|
+
|
2316
|
+
return f"""
|
2317
|
+
fragment ArtifactFragment on Artifact {{
|
2318
|
+
id
|
2319
|
+
artifactSequence {{
|
2320
|
+
project {{
|
2321
|
+
entityName
|
2322
|
+
name
|
2323
|
+
}}
|
2324
|
+
name
|
2325
|
+
}}
|
2326
|
+
versionIndex
|
2327
|
+
artifactType {{
|
2328
|
+
name
|
2329
|
+
}}
|
2330
|
+
description
|
2331
|
+
metadata
|
2332
|
+
{ttl_duration_seconds}
|
2333
|
+
{ttl_is_inherited}
|
2334
|
+
aliases {{
|
2335
|
+
artifactCollection {{
|
2336
|
+
project {{
|
2337
|
+
entityName
|
2338
|
+
name
|
2339
|
+
}}
|
2340
|
+
name
|
2341
|
+
}}
|
2342
|
+
alias
|
2343
|
+
}}
|
2344
|
+
{tags}
|
2345
|
+
state
|
2346
|
+
currentManifest {{
|
2347
|
+
file {{
|
2348
|
+
directUrl
|
2349
|
+
}}
|
2350
|
+
}}
|
2351
|
+
commitHash
|
2352
|
+
fileCount
|
2353
|
+
createdAt
|
2354
|
+
updatedAt
|
2355
|
+
}}
|
2356
|
+
"""
|
2357
|
+
|
2358
|
+
|
2359
|
+
class _ArtifactVersionType(WBType):
|
2360
|
+
name = "artifactVersion"
|
2361
|
+
types = [Artifact]
|
2362
|
+
|
2363
|
+
|
2364
|
+
TypeRegistry.add(_ArtifactVersionType)
|