Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_autocast_to_reduced_precision_compositeimplicitautograd_dispatch.h +23 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Float.h +30 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_rowwise_prune_ops.h +28 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_softmax_backward_data_native.h +23 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_use_cudnn_ctc_loss_cuda_dispatch.h +24 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_validate_sparse_csr_tensor_args_ops.h +28 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/atan2_meta_dispatch.h +26 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/col_indices_copy_compositeexplicitautograd_dispatch.h +24 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/exponential_ops.h +50 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/int_repr_compositeexplicitautograd_dispatch.h +24 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/log1p_meta_dispatch.h +26 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/logdet_native.h +21 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/max_pool2d_with_indices_cpu_dispatch.h +25 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/neg_meta_dispatch.h +26 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/norm_cpu_dispatch.h +28 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/norm_except_dim_native.h +21 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/row_indices_ops.h +28 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_modified_bessel_k1_compositeexplicitautogradnonfunctional_dispatch.h +23 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_shifted_chebyshev_polynomial_t_compositeexplicitautograd_dispatch.h +28 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/_validators.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_file_cache.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_instance_cache.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_manifest_entry.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/storage_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/_validators.py +121 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact.py +2358 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_instance_cache.py +17 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.py +75 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest_entry.py +249 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/artifact_manifest_v1.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +92 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_saver.py +265 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_state.py +11 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_ttl.py +7 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/exceptions.py +57 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/staging.py +25 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handler.py +62 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/azure_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/gcs_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/http_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/local_file_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/multi_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/s3_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/tracking_handler.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/wb_artifact_handler.cpython-310.pyc +0 -0
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_autocast_to_reduced_precision_compositeimplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeimplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _autocast_to_reduced_precision(const at::Tensor & self, bool cuda_enabled, bool cpu_enabled, at::ScalarType cuda_dtype, at::ScalarType cpu_dtype);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeimplicitautograd
|
| 23 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Float.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_cast_Float_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_cast_Float(Tensor self, bool non_blocking=False) -> Tensor
|
| 26 |
+
inline at::Tensor _cast_Float(const at::Tensor & self, bool non_blocking=false) {
|
| 27 |
+
return at::_ops::_cast_Float::call(self, non_blocking);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_rowwise_prune_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _rowwise_prune {
|
| 18 |
+
using schema = ::std::tuple<at::Tensor,at::Tensor> (const at::Tensor &, const at::Tensor &, at::ScalarType);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_rowwise_prune")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_rowwise_prune(Tensor weight, Tensor mask, ScalarType compressed_indices_dtype) -> (Tensor, Tensor)")
|
| 24 |
+
static ::std::tuple<at::Tensor,at::Tensor> call(const at::Tensor & weight, const at::Tensor & mask, at::ScalarType compressed_indices_dtype);
|
| 25 |
+
static ::std::tuple<at::Tensor,at::Tensor> redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & weight, const at::Tensor & mask, at::ScalarType compressed_indices_dtype);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_softmax_backward_data_native.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor & _sparse_softmax_backward_data_out(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self, at::Tensor & out);
|
| 20 |
+
TORCH_API at::Tensor softmax_backward_sparse_cpu(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor softmax_backward_sparse_cuda(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
|
| 22 |
+
} // namespace native
|
| 23 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_use_cudnn_ctc_loss_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API bool _use_cudnn_ctc_loss(const at::Tensor & log_probs, const at::Tensor & targets, at::IntArrayRef input_lengths, at::IntArrayRef target_lengths, int64_t blank);
|
| 21 |
+
TORCH_API bool _use_cudnn_ctc_loss(const at::Tensor & log_probs, const at::Tensor & targets, const at::Tensor & input_lengths, const at::Tensor & target_lengths, int64_t blank);
|
| 22 |
+
|
| 23 |
+
} // namespace cuda
|
| 24 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_validate_sparse_csr_tensor_args_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _validate_sparse_csr_tensor_args {
|
| 18 |
+
using schema = void (const at::Tensor &, const at::Tensor &, const at::Tensor &, at::IntArrayRef);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_validate_sparse_csr_tensor_args")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_validate_sparse_csr_tensor_args(Tensor crow_indices, Tensor col_indices, Tensor values, int[] size) -> ()")
|
| 24 |
+
static void call(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size);
|
| 25 |
+
static void redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/atan2_meta_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor atan2(const at::Tensor & self, const at::Tensor & other);
|
| 21 |
+
TORCH_API at::Tensor & atan2_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other);
|
| 22 |
+
TORCH_API at::Tensor & atan2_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & atan2_(at::Tensor & self, const at::Tensor & other);
|
| 24 |
+
|
| 25 |
+
} // namespace meta
|
| 26 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/col_indices_copy_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & col_indices_copy_out(at::Tensor & out, const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & col_indices_copy_outf(const at::Tensor & self, at::Tensor & out);
|
| 22 |
+
|
| 23 |
+
} // namespace compositeexplicitautograd
|
| 24 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/exponential_ops.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API exponential_ {
|
| 18 |
+
using schema = at::Tensor & (at::Tensor &, double, c10::optional<at::Generator>);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::exponential_")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "exponential_(Tensor(a!) self, float lambd=1, *, Generator? generator=None) -> Tensor(a!)")
|
| 24 |
+
static at::Tensor & call(at::Tensor & self, double lambd, c10::optional<at::Generator> generator);
|
| 25 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, double lambd, c10::optional<at::Generator> generator);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API exponential_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, double, c10::optional<at::Generator>, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::exponential")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "exponential.out(Tensor self, float lambd=1, *, Generator? generator=None, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & self, double lambd, c10::optional<at::Generator> generator, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, double lambd, c10::optional<at::Generator> generator, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
struct TORCH_API exponential {
|
| 40 |
+
using schema = at::Tensor (const at::Tensor &, double, c10::optional<at::Generator>);
|
| 41 |
+
using ptr_schema = schema*;
|
| 42 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 43 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::exponential")
|
| 44 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 45 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "exponential(Tensor self, float lambd=1, *, Generator? generator=None) -> Tensor")
|
| 46 |
+
static at::Tensor call(const at::Tensor & self, double lambd, c10::optional<at::Generator> generator);
|
| 47 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, double lambd, c10::optional<at::Generator> generator);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
}} // namespace at::_ops
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/int_repr_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & int_repr_out(at::Tensor & out, const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & int_repr_outf(const at::Tensor & self, at::Tensor & out);
|
| 22 |
+
|
| 23 |
+
} // namespace compositeexplicitautograd
|
| 24 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/log1p_meta_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor log1p(const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & log1p_out(at::Tensor & out, const at::Tensor & self);
|
| 22 |
+
TORCH_API at::Tensor & log1p_outf(const at::Tensor & self, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & log1p_(at::Tensor & self);
|
| 24 |
+
|
| 25 |
+
} // namespace meta
|
| 26 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/logdet_native.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor logdet(const at::Tensor & self);
|
| 20 |
+
} // namespace native
|
| 21 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/max_pool2d_with_indices_cpu_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cpu {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor> max_pool2d_with_indices(const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride={}, at::IntArrayRef padding=0, at::IntArrayRef dilation=1, bool ceil_mode=false);
|
| 21 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> max_pool2d_with_indices_out(at::Tensor & out, at::Tensor & indices, const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride={}, at::IntArrayRef padding=0, at::IntArrayRef dilation=1, bool ceil_mode=false);
|
| 22 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> max_pool2d_with_indices_outf(const at::Tensor & self, at::IntArrayRef kernel_size, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool ceil_mode, at::Tensor & out, at::Tensor & indices);
|
| 23 |
+
|
| 24 |
+
} // namespace cpu
|
| 25 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/neg_meta_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor neg(const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & neg_out(at::Tensor & out, const at::Tensor & self);
|
| 22 |
+
TORCH_API at::Tensor & neg_outf(const at::Tensor & self, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & neg_(at::Tensor & self);
|
| 24 |
+
|
| 25 |
+
} // namespace meta
|
| 26 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/norm_cpu_dispatch.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cpu {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor norm(const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim, at::ScalarType dtype);
|
| 21 |
+
TORCH_API at::Tensor & norm_out(at::Tensor & out, const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim, at::ScalarType dtype);
|
| 22 |
+
TORCH_API at::Tensor & norm_outf(const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim, at::ScalarType dtype, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor norm(const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim=false);
|
| 24 |
+
TORCH_API at::Tensor & norm_out(at::Tensor & out, const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim=false);
|
| 25 |
+
TORCH_API at::Tensor & norm_outf(const at::Tensor & self, const c10::optional<at::Scalar> & p, at::IntArrayRef dim, bool keepdim, at::Tensor & out);
|
| 26 |
+
|
| 27 |
+
} // namespace cpu
|
| 28 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/norm_except_dim_native.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor norm_except_dim(const at::Tensor & v, int64_t pow=2, int64_t dim=0);
|
| 20 |
+
} // namespace native
|
| 21 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/row_indices_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API row_indices {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::row_indices")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "row_indices(Tensor(a) self) -> Tensor(a)")
|
| 24 |
+
static at::Tensor call(const at::Tensor & self);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_modified_bessel_k1_compositeexplicitautogradnonfunctional_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautogradnonfunctional {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor special_modified_bessel_k1(const at::Tensor & self);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeexplicitautogradnonfunctional
|
| 23 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_shifted_chebyshev_polynomial_t_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor special_shifted_chebyshev_polynomial_t(const at::Scalar & x, const at::Tensor & n);
|
| 21 |
+
TORCH_API at::Tensor & special_shifted_chebyshev_polynomial_t_out(at::Tensor & out, const at::Scalar & x, const at::Tensor & n);
|
| 22 |
+
TORCH_API at::Tensor & special_shifted_chebyshev_polynomial_t_outf(const at::Scalar & x, const at::Tensor & n, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor special_shifted_chebyshev_polynomial_t(const at::Tensor & x, const at::Scalar & n);
|
| 24 |
+
TORCH_API at::Tensor & special_shifted_chebyshev_polynomial_t_out(at::Tensor & out, const at::Tensor & x, const at::Scalar & n);
|
| 25 |
+
TORCH_API at::Tensor & special_shifted_chebyshev_polynomial_t_outf(const at::Tensor & x, const at::Scalar & n, at::Tensor & out);
|
| 26 |
+
|
| 27 |
+
} // namespace compositeexplicitautograd
|
| 28 |
+
} // namespace at
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (169 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/_validators.cpython-310.pyc
ADDED
|
Binary file (4.83 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_file_cache.cpython-310.pyc
ADDED
|
Binary file (8.35 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_instance_cache.cpython-310.pyc
ADDED
|
Binary file (663 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/artifact_manifest_entry.cpython-310.pyc
ADDED
|
Binary file (7.49 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/__pycache__/storage_handler.cpython-310.pyc
ADDED
|
Binary file (2.41 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/_validators.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Internal validation utilities that are specific to artifacts."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from functools import wraps
|
| 7 |
+
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast, overload
|
| 8 |
+
|
| 9 |
+
from wandb.sdk.artifacts.exceptions import (
|
| 10 |
+
ArtifactFinalizedError,
|
| 11 |
+
ArtifactNotLoggedError,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from typing import Collection, Final, Iterable, Union
|
| 16 |
+
|
| 17 |
+
from wandb.sdk.artifacts.artifact import Artifact
|
| 18 |
+
|
| 19 |
+
ArtifactT = TypeVar("ArtifactT", bound=Artifact)
|
| 20 |
+
T = TypeVar("T")
|
| 21 |
+
ClassInfo = Union[type[T], tuple[type[T], ...]]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
REGISTRY_PREFIX: Final[str] = "wandb-registry-"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# For mypy checks
|
| 28 |
+
@overload
|
| 29 |
+
def always_list(obj: Iterable[T], base_type: ClassInfo = ...) -> list[T]: ...
|
| 30 |
+
@overload
|
| 31 |
+
def always_list(obj: T, base_type: ClassInfo = ...) -> list[T]: ...
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def always_list(obj: Any, base_type: Any = (str, bytes)) -> list[T]:
|
| 35 |
+
"""Return a guaranteed list of objects from a single instance OR iterable of such objects.
|
| 36 |
+
|
| 37 |
+
By default, assume the returned list should have string-like elements (i.e. `str`/`bytes`).
|
| 38 |
+
|
| 39 |
+
Adapted from `more_itertools.always_iterable`, but simplified for internal use. See:
|
| 40 |
+
https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_iterable
|
| 41 |
+
"""
|
| 42 |
+
return [obj] if isinstance(obj, base_type) else list(obj)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def validate_aliases(aliases: Collection[str] | str) -> list[str]:
|
| 46 |
+
"""Validate the artifact aliases and return them as a list.
|
| 47 |
+
|
| 48 |
+
Raises:
|
| 49 |
+
ValueError: If any of the aliases contain invalid characters.
|
| 50 |
+
"""
|
| 51 |
+
aliases_list = always_list(aliases)
|
| 52 |
+
|
| 53 |
+
invalid_chars = ("/", ":")
|
| 54 |
+
if any(char in alias for alias in aliases_list for char in invalid_chars):
|
| 55 |
+
raise ValueError(
|
| 56 |
+
f"Aliases must not contain any of the following characters: {', '.join(invalid_chars)}"
|
| 57 |
+
)
|
| 58 |
+
return aliases_list
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
_VALID_TAG_PATTERN: re.Pattern[str] = re.compile(r"^[-\w]+( +[-\w]+)*$")
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def validate_tags(tags: Collection[str] | str) -> list[str]:
|
| 65 |
+
"""Validate the artifact tag names and return them as a deduped list.
|
| 66 |
+
|
| 67 |
+
In the case of duplicates, only keep the first tag, and otherwise maintain the order of appearance.
|
| 68 |
+
|
| 69 |
+
Raises:
|
| 70 |
+
ValueError: If any of the tags contain invalid characters.
|
| 71 |
+
"""
|
| 72 |
+
tags_list = always_list(tags)
|
| 73 |
+
|
| 74 |
+
if any(not _VALID_TAG_PATTERN.match(tag) for tag in tags_list):
|
| 75 |
+
raise ValueError(
|
| 76 |
+
"Invalid tag(s). "
|
| 77 |
+
"Tags must only contain alphanumeric characters separated by hyphens, underscores, and/or spaces."
|
| 78 |
+
)
|
| 79 |
+
return list(dict.fromkeys(tags_list))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
DecoratedF = TypeVar("DecoratedF", bound=Callable[..., Any])
|
| 83 |
+
"""Type hint for a decorated function that'll preserve its signature (e.g. for arg autocompletion in IDEs)."""
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def ensure_logged(method: DecoratedF) -> DecoratedF:
|
| 87 |
+
"""Decorator to ensure that an Artifact method can only be called if the artifact has been logged.
|
| 88 |
+
|
| 89 |
+
If the method is called on an artifact that's not logged, `ArtifactNotLoggedError` is raised.
|
| 90 |
+
"""
|
| 91 |
+
# For clarity, use the qualified (full) name of the method
|
| 92 |
+
method_fullname = method.__qualname__
|
| 93 |
+
|
| 94 |
+
@wraps(method)
|
| 95 |
+
def wrapper(self: ArtifactT, *args: Any, **kwargs: Any) -> Any:
|
| 96 |
+
if self.is_draft():
|
| 97 |
+
raise ArtifactNotLoggedError(fullname=method_fullname, obj=self)
|
| 98 |
+
return method(self, *args, **kwargs)
|
| 99 |
+
|
| 100 |
+
return cast(DecoratedF, wrapper)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def ensure_not_finalized(method: DecoratedF) -> DecoratedF:
|
| 104 |
+
"""Decorator to ensure that an `Artifact` method can only be called if the artifact isn't finalized.
|
| 105 |
+
|
| 106 |
+
If the method is called on an artifact that's not logged, `ArtifactFinalizedError` is raised.
|
| 107 |
+
"""
|
| 108 |
+
# For clarity, use the qualified (full) name of the method
|
| 109 |
+
method_fullname = method.__qualname__
|
| 110 |
+
|
| 111 |
+
@wraps(method)
|
| 112 |
+
def wrapper(self: ArtifactT, *args: Any, **kwargs: Any) -> Any:
|
| 113 |
+
if self._final:
|
| 114 |
+
raise ArtifactFinalizedError(fullname=method_fullname, obj=self)
|
| 115 |
+
return method(self, *args, **kwargs)
|
| 116 |
+
|
| 117 |
+
return cast(DecoratedF, wrapper)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def is_artifact_registry_project(project: str) -> bool:
|
| 121 |
+
return project.startswith(REGISTRY_PREFIX)
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact.py
ADDED
|
@@ -0,0 +1,2358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
wl = wandb.setup()
|
| 1689 |
+
|
| 1690 |
+
stream_id = generate_id()
|
| 1691 |
+
|
| 1692 |
+
settings = wl.settings.to_proto()
|
| 1693 |
+
# TODO: remove this
|
| 1694 |
+
tmp_dir = pathlib.Path(tempfile.mkdtemp())
|
| 1695 |
+
|
| 1696 |
+
settings.sync_dir.value = str(tmp_dir)
|
| 1697 |
+
settings.sync_file.value = str(tmp_dir / f"{stream_id}.wandb")
|
| 1698 |
+
settings.files_dir.value = str(tmp_dir / "files")
|
| 1699 |
+
settings.run_id.value = stream_id
|
| 1700 |
+
|
| 1701 |
+
service = wl.ensure_service()
|
| 1702 |
+
service.inform_init(settings=settings, run_id=stream_id)
|
| 1703 |
+
|
| 1704 |
+
mailbox = Mailbox()
|
| 1705 |
+
backend = Backend(
|
| 1706 |
+
settings=wl.settings,
|
| 1707 |
+
service=service,
|
| 1708 |
+
mailbox=mailbox,
|
| 1709 |
+
)
|
| 1710 |
+
backend.ensure_launched()
|
| 1711 |
+
|
| 1712 |
+
assert backend.interface
|
| 1713 |
+
backend.interface._stream_id = stream_id # type: ignore
|
| 1714 |
+
|
| 1715 |
+
mailbox.enable_keepalive()
|
| 1716 |
+
else:
|
| 1717 |
+
assert wandb.run._backend
|
| 1718 |
+
backend = wandb.run._backend
|
| 1719 |
+
|
| 1720 |
+
assert backend.interface
|
| 1721 |
+
handle = backend.interface.deliver_download_artifact(
|
| 1722 |
+
self.id, # type: ignore
|
| 1723 |
+
root,
|
| 1724 |
+
allow_missing_references,
|
| 1725 |
+
skip_cache,
|
| 1726 |
+
path_prefix, # type: ignore
|
| 1727 |
+
)
|
| 1728 |
+
# TODO: Start the download process in the user process too, to handle reference downloads
|
| 1729 |
+
self._download(
|
| 1730 |
+
root=root,
|
| 1731 |
+
allow_missing_references=allow_missing_references,
|
| 1732 |
+
skip_cache=skip_cache,
|
| 1733 |
+
path_prefix=path_prefix,
|
| 1734 |
+
)
|
| 1735 |
+
result = handle.wait(timeout=-1)
|
| 1736 |
+
|
| 1737 |
+
if result is None:
|
| 1738 |
+
handle.abandon()
|
| 1739 |
+
assert result is not None
|
| 1740 |
+
response = result.response.download_artifact_response
|
| 1741 |
+
if response.error_message:
|
| 1742 |
+
raise ValueError(f"Error downloading artifact: {response.error_message}")
|
| 1743 |
+
|
| 1744 |
+
return FilePathStr(root)
|
| 1745 |
+
|
| 1746 |
+
def _download(
|
| 1747 |
+
self,
|
| 1748 |
+
root: str,
|
| 1749 |
+
allow_missing_references: bool = False,
|
| 1750 |
+
skip_cache: bool | None = None,
|
| 1751 |
+
path_prefix: StrPath | None = None,
|
| 1752 |
+
) -> FilePathStr:
|
| 1753 |
+
nfiles = len(self.manifest.entries)
|
| 1754 |
+
size = sum(e.size or 0 for e in self.manifest.entries.values())
|
| 1755 |
+
log = False
|
| 1756 |
+
if nfiles > 5000 or size > 50 * 1024 * 1024:
|
| 1757 |
+
log = True
|
| 1758 |
+
termlog(
|
| 1759 |
+
"Downloading large artifact {}, {:.2f}MB. {} files... ".format(
|
| 1760 |
+
self.name, size / (1024 * 1024), nfiles
|
| 1761 |
+
),
|
| 1762 |
+
)
|
| 1763 |
+
start_time = datetime.now()
|
| 1764 |
+
download_logger = ArtifactDownloadLogger(nfiles=nfiles)
|
| 1765 |
+
|
| 1766 |
+
def _download_entry(
|
| 1767 |
+
entry: ArtifactManifestEntry,
|
| 1768 |
+
api_key: str | None,
|
| 1769 |
+
cookies: dict | None,
|
| 1770 |
+
headers: dict | None,
|
| 1771 |
+
) -> None:
|
| 1772 |
+
_thread_local_api_settings.api_key = api_key
|
| 1773 |
+
_thread_local_api_settings.cookies = cookies
|
| 1774 |
+
_thread_local_api_settings.headers = headers
|
| 1775 |
+
|
| 1776 |
+
try:
|
| 1777 |
+
entry.download(root, skip_cache=skip_cache)
|
| 1778 |
+
except FileNotFoundError as e:
|
| 1779 |
+
if allow_missing_references:
|
| 1780 |
+
wandb.termwarn(str(e))
|
| 1781 |
+
return
|
| 1782 |
+
raise
|
| 1783 |
+
except _GCSIsADirectoryError as e:
|
| 1784 |
+
logger.debug(str(e))
|
| 1785 |
+
return
|
| 1786 |
+
download_logger.notify_downloaded()
|
| 1787 |
+
|
| 1788 |
+
download_entry = partial(
|
| 1789 |
+
_download_entry,
|
| 1790 |
+
api_key=_thread_local_api_settings.api_key,
|
| 1791 |
+
cookies=_thread_local_api_settings.cookies,
|
| 1792 |
+
headers=_thread_local_api_settings.headers,
|
| 1793 |
+
)
|
| 1794 |
+
|
| 1795 |
+
with concurrent.futures.ThreadPoolExecutor(64) as executor:
|
| 1796 |
+
active_futures = set()
|
| 1797 |
+
has_next_page = True
|
| 1798 |
+
cursor = None
|
| 1799 |
+
while has_next_page:
|
| 1800 |
+
fetch_url_batch_size = env.get_artifact_fetch_file_url_batch_size()
|
| 1801 |
+
attrs = self._fetch_file_urls(cursor, fetch_url_batch_size)
|
| 1802 |
+
has_next_page = attrs["pageInfo"]["hasNextPage"]
|
| 1803 |
+
cursor = attrs["pageInfo"]["endCursor"]
|
| 1804 |
+
for edge in attrs["edges"]:
|
| 1805 |
+
entry = self.get_entry(edge["node"]["name"])
|
| 1806 |
+
# TODO: uncomment once artifact downloads are supported in core
|
| 1807 |
+
# if require_core and entry.ref is None:
|
| 1808 |
+
# # Handled by core
|
| 1809 |
+
# continue
|
| 1810 |
+
entry._download_url = edge["node"]["directUrl"]
|
| 1811 |
+
if (not path_prefix) or entry.path.startswith(str(path_prefix)):
|
| 1812 |
+
active_futures.add(executor.submit(download_entry, entry))
|
| 1813 |
+
# Wait for download threads to catch up.
|
| 1814 |
+
max_backlog = fetch_url_batch_size
|
| 1815 |
+
if len(active_futures) > max_backlog:
|
| 1816 |
+
for future in concurrent.futures.as_completed(active_futures):
|
| 1817 |
+
future.result() # check for errors
|
| 1818 |
+
active_futures.remove(future)
|
| 1819 |
+
if len(active_futures) <= max_backlog:
|
| 1820 |
+
break
|
| 1821 |
+
# Check for errors.
|
| 1822 |
+
for future in concurrent.futures.as_completed(active_futures):
|
| 1823 |
+
future.result()
|
| 1824 |
+
|
| 1825 |
+
if log:
|
| 1826 |
+
now = datetime.now()
|
| 1827 |
+
delta = abs((now - start_time).total_seconds())
|
| 1828 |
+
hours = int(delta // 3600)
|
| 1829 |
+
minutes = int((delta - hours * 3600) // 60)
|
| 1830 |
+
seconds = delta - hours * 3600 - minutes * 60
|
| 1831 |
+
termlog(
|
| 1832 |
+
f"Done. {hours}:{minutes}:{seconds:.1f}",
|
| 1833 |
+
prefix=False,
|
| 1834 |
+
)
|
| 1835 |
+
return FilePathStr(root)
|
| 1836 |
+
|
| 1837 |
+
@retry.retriable(
|
| 1838 |
+
retry_timedelta=timedelta(minutes=3),
|
| 1839 |
+
retryable_exceptions=(requests.RequestException),
|
| 1840 |
+
)
|
| 1841 |
+
def _fetch_file_urls(self, cursor: str | None, per_page: int | None = 5000) -> Any:
|
| 1842 |
+
query = gql(
|
| 1843 |
+
"""
|
| 1844 |
+
query ArtifactFileURLs($id: ID!, $cursor: String, $perPage: Int) {
|
| 1845 |
+
artifact(id: $id) {
|
| 1846 |
+
files(after: $cursor, first: $perPage) {
|
| 1847 |
+
pageInfo {
|
| 1848 |
+
hasNextPage
|
| 1849 |
+
endCursor
|
| 1850 |
+
}
|
| 1851 |
+
edges {
|
| 1852 |
+
node {
|
| 1853 |
+
name
|
| 1854 |
+
directUrl
|
| 1855 |
+
}
|
| 1856 |
+
}
|
| 1857 |
+
}
|
| 1858 |
+
}
|
| 1859 |
+
}
|
| 1860 |
+
"""
|
| 1861 |
+
)
|
| 1862 |
+
assert self._client is not None
|
| 1863 |
+
response = self._client.execute(
|
| 1864 |
+
query,
|
| 1865 |
+
variable_values={"id": self.id, "cursor": cursor, "perPage": per_page},
|
| 1866 |
+
timeout=60,
|
| 1867 |
+
)
|
| 1868 |
+
return response["artifact"]["files"]
|
| 1869 |
+
|
| 1870 |
+
@ensure_logged
|
| 1871 |
+
def checkout(self, root: str | None = None) -> str:
|
| 1872 |
+
"""Replace the specified root directory with the contents of the artifact.
|
| 1873 |
+
|
| 1874 |
+
WARNING: This will delete all files in `root` that are not included in the
|
| 1875 |
+
artifact.
|
| 1876 |
+
|
| 1877 |
+
Args:
|
| 1878 |
+
root: The directory to replace with this artifact's files.
|
| 1879 |
+
|
| 1880 |
+
Returns:
|
| 1881 |
+
The path of the checked out contents.
|
| 1882 |
+
|
| 1883 |
+
Raises:
|
| 1884 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 1885 |
+
"""
|
| 1886 |
+
root = root or self._default_root(include_version=False)
|
| 1887 |
+
|
| 1888 |
+
for dirpath, _, files in os.walk(root):
|
| 1889 |
+
for file in files:
|
| 1890 |
+
full_path = os.path.join(dirpath, file)
|
| 1891 |
+
artifact_path = os.path.relpath(full_path, start=root)
|
| 1892 |
+
try:
|
| 1893 |
+
self.get_entry(artifact_path)
|
| 1894 |
+
except KeyError:
|
| 1895 |
+
# File is not part of the artifact, remove it.
|
| 1896 |
+
os.remove(full_path)
|
| 1897 |
+
|
| 1898 |
+
return self.download(root=root)
|
| 1899 |
+
|
| 1900 |
+
@ensure_logged
|
| 1901 |
+
def verify(self, root: str | None = None) -> None:
|
| 1902 |
+
"""Verify that the contents of an artifact match the manifest.
|
| 1903 |
+
|
| 1904 |
+
All files in the directory are checksummed and the checksums are then
|
| 1905 |
+
cross-referenced against the artifact's manifest. References are not verified.
|
| 1906 |
+
|
| 1907 |
+
Args:
|
| 1908 |
+
root: The directory to verify. If None artifact will be downloaded to
|
| 1909 |
+
'./artifacts/self.name/'
|
| 1910 |
+
|
| 1911 |
+
Raises:
|
| 1912 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 1913 |
+
ValueError: If the verification fails.
|
| 1914 |
+
"""
|
| 1915 |
+
root = root or self._default_root()
|
| 1916 |
+
|
| 1917 |
+
for dirpath, _, files in os.walk(root):
|
| 1918 |
+
for file in files:
|
| 1919 |
+
full_path = os.path.join(dirpath, file)
|
| 1920 |
+
artifact_path = os.path.relpath(full_path, start=root)
|
| 1921 |
+
try:
|
| 1922 |
+
self.get_entry(artifact_path)
|
| 1923 |
+
except KeyError:
|
| 1924 |
+
raise ValueError(
|
| 1925 |
+
"Found file {} which is not a member of artifact {}".format(
|
| 1926 |
+
full_path, self.name
|
| 1927 |
+
)
|
| 1928 |
+
)
|
| 1929 |
+
|
| 1930 |
+
ref_count = 0
|
| 1931 |
+
for entry in self.manifest.entries.values():
|
| 1932 |
+
if entry.ref is None:
|
| 1933 |
+
if md5_file_b64(os.path.join(root, entry.path)) != entry.digest:
|
| 1934 |
+
raise ValueError("Digest mismatch for file: {}".format(entry.path))
|
| 1935 |
+
else:
|
| 1936 |
+
ref_count += 1
|
| 1937 |
+
if ref_count > 0:
|
| 1938 |
+
termwarn(f"skipped verification of {ref_count} refs")
|
| 1939 |
+
|
| 1940 |
+
@ensure_logged
|
| 1941 |
+
def file(self, root: str | None = None) -> StrPath:
|
| 1942 |
+
"""Download a single file artifact to the directory you specify with `root`.
|
| 1943 |
+
|
| 1944 |
+
Args:
|
| 1945 |
+
root: The root directory to store the file. Defaults to
|
| 1946 |
+
'./artifacts/self.name/'.
|
| 1947 |
+
|
| 1948 |
+
Returns:
|
| 1949 |
+
The full path of the downloaded file.
|
| 1950 |
+
|
| 1951 |
+
Raises:
|
| 1952 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 1953 |
+
ValueError: If the artifact contains more than one file.
|
| 1954 |
+
"""
|
| 1955 |
+
if root is None:
|
| 1956 |
+
root = os.path.join(".", "artifacts", self.name)
|
| 1957 |
+
|
| 1958 |
+
if len(self.manifest.entries) > 1:
|
| 1959 |
+
raise ValueError(
|
| 1960 |
+
"This artifact contains more than one file, call `.download()` to get "
|
| 1961 |
+
'all files or call .get_entry("filename").download()'
|
| 1962 |
+
)
|
| 1963 |
+
|
| 1964 |
+
return self.get_entry(list(self.manifest.entries)[0]).download(root)
|
| 1965 |
+
|
| 1966 |
+
@ensure_logged
|
| 1967 |
+
def files(
|
| 1968 |
+
self, names: list[str] | None = None, per_page: int = 50
|
| 1969 |
+
) -> ArtifactFiles:
|
| 1970 |
+
"""Iterate over all files stored in this artifact.
|
| 1971 |
+
|
| 1972 |
+
Args:
|
| 1973 |
+
names: The filename paths relative to the root of the artifact you wish to
|
| 1974 |
+
list.
|
| 1975 |
+
per_page: The number of files to return per request.
|
| 1976 |
+
|
| 1977 |
+
Returns:
|
| 1978 |
+
An iterator containing `File` objects.
|
| 1979 |
+
|
| 1980 |
+
Raises:
|
| 1981 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 1982 |
+
"""
|
| 1983 |
+
return ArtifactFiles(self._client, self, names, per_page)
|
| 1984 |
+
|
| 1985 |
+
def _default_root(self, include_version: bool = True) -> FilePathStr:
|
| 1986 |
+
name = self.source_name if include_version else self.source_name.split(":")[0]
|
| 1987 |
+
root = os.path.join(env.get_artifact_dir(), name)
|
| 1988 |
+
# In case we're on a system where the artifact dir has a name corresponding to
|
| 1989 |
+
# an unexpected filesystem, we'll check for alternate roots. If one exists we'll
|
| 1990 |
+
# use that, otherwise we'll fall back to the system-preferred path.
|
| 1991 |
+
path = filesystem.check_exists(root) or filesystem.system_preferred_path(root)
|
| 1992 |
+
return FilePathStr(str(path))
|
| 1993 |
+
|
| 1994 |
+
def _add_download_root(self, dir_path: str) -> None:
|
| 1995 |
+
self._download_roots.add(os.path.abspath(dir_path))
|
| 1996 |
+
|
| 1997 |
+
def _local_path_to_name(self, file_path: str) -> str | None:
|
| 1998 |
+
"""Convert a local file path to a path entry in the artifact."""
|
| 1999 |
+
abs_file_path = os.path.abspath(file_path)
|
| 2000 |
+
abs_file_parts = abs_file_path.split(os.sep)
|
| 2001 |
+
for i in range(len(abs_file_parts) + 1):
|
| 2002 |
+
if os.path.join(os.sep, *abs_file_parts[:i]) in self._download_roots:
|
| 2003 |
+
return os.path.join(*abs_file_parts[i:])
|
| 2004 |
+
return None
|
| 2005 |
+
|
| 2006 |
+
# Others.
|
| 2007 |
+
|
| 2008 |
+
@ensure_logged
|
| 2009 |
+
def delete(self, delete_aliases: bool = False) -> None:
|
| 2010 |
+
"""Delete an artifact and its files.
|
| 2011 |
+
|
| 2012 |
+
If called on a linked artifact (i.e. a member of a portfolio collection): only the link is deleted, and the
|
| 2013 |
+
source artifact is unaffected.
|
| 2014 |
+
|
| 2015 |
+
Args:
|
| 2016 |
+
delete_aliases: If set to `True`, deletes all aliases associated with the artifact.
|
| 2017 |
+
Otherwise, this raises an exception if the artifact has existing
|
| 2018 |
+
aliases.
|
| 2019 |
+
This parameter is ignored if the artifact is linked (i.e. a member of a portfolio collection).
|
| 2020 |
+
|
| 2021 |
+
Raises:
|
| 2022 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 2023 |
+
"""
|
| 2024 |
+
if self.collection.is_sequence():
|
| 2025 |
+
self._delete(delete_aliases)
|
| 2026 |
+
else:
|
| 2027 |
+
self._unlink()
|
| 2028 |
+
|
| 2029 |
+
@normalize_exceptions
|
| 2030 |
+
def _delete(self, delete_aliases: bool = False) -> None:
|
| 2031 |
+
mutation = gql(
|
| 2032 |
+
"""
|
| 2033 |
+
mutation DeleteArtifact($artifactID: ID!, $deleteAliases: Boolean) {
|
| 2034 |
+
deleteArtifact(input: {
|
| 2035 |
+
artifactID: $artifactID
|
| 2036 |
+
deleteAliases: $deleteAliases
|
| 2037 |
+
}) {
|
| 2038 |
+
artifact {
|
| 2039 |
+
id
|
| 2040 |
+
}
|
| 2041 |
+
}
|
| 2042 |
+
}
|
| 2043 |
+
"""
|
| 2044 |
+
)
|
| 2045 |
+
assert self._client is not None
|
| 2046 |
+
self._client.execute(
|
| 2047 |
+
mutation,
|
| 2048 |
+
variable_values={
|
| 2049 |
+
"artifactID": self.id,
|
| 2050 |
+
"deleteAliases": delete_aliases,
|
| 2051 |
+
},
|
| 2052 |
+
)
|
| 2053 |
+
|
| 2054 |
+
@normalize_exceptions
|
| 2055 |
+
def link(self, target_path: str, aliases: list[str] | None = None) -> None:
|
| 2056 |
+
"""Link this artifact to a portfolio (a promoted collection of artifacts).
|
| 2057 |
+
|
| 2058 |
+
Args:
|
| 2059 |
+
target_path: The path to the portfolio inside a project.
|
| 2060 |
+
The target path must adhere to one of the following
|
| 2061 |
+
schemas `{portfolio}`, `{project}/{portfolio}` or
|
| 2062 |
+
`{entity}/{project}/{portfolio}`.
|
| 2063 |
+
To link the artifact to the Model Registry, rather than to a generic
|
| 2064 |
+
portfolio inside a project, set `target_path` to the following
|
| 2065 |
+
schema `{"model-registry"}/{Registered Model Name}` or
|
| 2066 |
+
`{entity}/{"model-registry"}/{Registered Model Name}`.
|
| 2067 |
+
aliases: A list of strings that uniquely identifies the artifact inside the
|
| 2068 |
+
specified portfolio.
|
| 2069 |
+
|
| 2070 |
+
Raises:
|
| 2071 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 2072 |
+
"""
|
| 2073 |
+
if wandb.run is None:
|
| 2074 |
+
with wandb.init( # type: ignore
|
| 2075 |
+
entity=self._source_entity,
|
| 2076 |
+
project=self._source_project,
|
| 2077 |
+
job_type="auto",
|
| 2078 |
+
settings=wandb.Settings(silent="true"),
|
| 2079 |
+
) as run:
|
| 2080 |
+
run.link_artifact(self, target_path, aliases)
|
| 2081 |
+
else:
|
| 2082 |
+
wandb.run.link_artifact(self, target_path, aliases)
|
| 2083 |
+
|
| 2084 |
+
@ensure_logged
|
| 2085 |
+
def unlink(self) -> None:
|
| 2086 |
+
"""Unlink this artifact if it is currently a member of a portfolio (a promoted collection of artifacts).
|
| 2087 |
+
|
| 2088 |
+
Raises:
|
| 2089 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 2090 |
+
ValueError: If the artifact is not linked, i.e. it is not a member of a portfolio collection.
|
| 2091 |
+
"""
|
| 2092 |
+
# Fail early if this isn't a linked artifact to begin with
|
| 2093 |
+
if self.collection.is_sequence():
|
| 2094 |
+
raise ValueError(
|
| 2095 |
+
f"Artifact {self.qualified_name!r} is not a linked artifact and cannot be unlinked. "
|
| 2096 |
+
f"To delete it, use {self.delete.__qualname__!r} instead."
|
| 2097 |
+
)
|
| 2098 |
+
|
| 2099 |
+
self._unlink()
|
| 2100 |
+
|
| 2101 |
+
@normalize_exceptions
|
| 2102 |
+
def _unlink(self) -> None:
|
| 2103 |
+
mutation = gql(
|
| 2104 |
+
"""
|
| 2105 |
+
mutation UnlinkArtifact($artifactID: ID!, $artifactPortfolioID: ID!) {
|
| 2106 |
+
unlinkArtifact(
|
| 2107 |
+
input: { artifactID: $artifactID, artifactPortfolioID: $artifactPortfolioID }
|
| 2108 |
+
) {
|
| 2109 |
+
artifactID
|
| 2110 |
+
success
|
| 2111 |
+
clientMutationId
|
| 2112 |
+
}
|
| 2113 |
+
}
|
| 2114 |
+
"""
|
| 2115 |
+
)
|
| 2116 |
+
assert self._client is not None
|
| 2117 |
+
self._client.execute(
|
| 2118 |
+
mutation,
|
| 2119 |
+
variable_values={
|
| 2120 |
+
"artifactID": self.id,
|
| 2121 |
+
"artifactPortfolioID": self.collection.id,
|
| 2122 |
+
},
|
| 2123 |
+
)
|
| 2124 |
+
|
| 2125 |
+
@ensure_logged
|
| 2126 |
+
def used_by(self) -> list[Run]:
|
| 2127 |
+
"""Get a list of the runs that have used this artifact.
|
| 2128 |
+
|
| 2129 |
+
Returns:
|
| 2130 |
+
A list of `Run` objects.
|
| 2131 |
+
|
| 2132 |
+
Raises:
|
| 2133 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 2134 |
+
"""
|
| 2135 |
+
query = gql(
|
| 2136 |
+
"""
|
| 2137 |
+
query ArtifactUsedBy(
|
| 2138 |
+
$id: ID!,
|
| 2139 |
+
) {
|
| 2140 |
+
artifact(id: $id) {
|
| 2141 |
+
usedBy {
|
| 2142 |
+
edges {
|
| 2143 |
+
node {
|
| 2144 |
+
name
|
| 2145 |
+
project {
|
| 2146 |
+
name
|
| 2147 |
+
entityName
|
| 2148 |
+
}
|
| 2149 |
+
}
|
| 2150 |
+
}
|
| 2151 |
+
}
|
| 2152 |
+
}
|
| 2153 |
+
}
|
| 2154 |
+
"""
|
| 2155 |
+
)
|
| 2156 |
+
assert self._client is not None
|
| 2157 |
+
response = self._client.execute(
|
| 2158 |
+
query,
|
| 2159 |
+
variable_values={"id": self.id},
|
| 2160 |
+
)
|
| 2161 |
+
return [
|
| 2162 |
+
Run(
|
| 2163 |
+
self._client,
|
| 2164 |
+
edge["node"]["project"]["entityName"],
|
| 2165 |
+
edge["node"]["project"]["name"],
|
| 2166 |
+
edge["node"]["name"],
|
| 2167 |
+
)
|
| 2168 |
+
for edge in response.get("artifact", {}).get("usedBy", {}).get("edges", [])
|
| 2169 |
+
]
|
| 2170 |
+
|
| 2171 |
+
@ensure_logged
|
| 2172 |
+
def logged_by(self) -> Run | None:
|
| 2173 |
+
"""Get the W&B run that originally logged the artifact.
|
| 2174 |
+
|
| 2175 |
+
Returns:
|
| 2176 |
+
The name of the W&B run that originally logged the artifact.
|
| 2177 |
+
|
| 2178 |
+
Raises:
|
| 2179 |
+
ArtifactNotLoggedError: If the artifact is not logged.
|
| 2180 |
+
"""
|
| 2181 |
+
query = gql(
|
| 2182 |
+
"""
|
| 2183 |
+
query ArtifactCreatedBy(
|
| 2184 |
+
$id: ID!
|
| 2185 |
+
) {
|
| 2186 |
+
artifact(id: $id) {
|
| 2187 |
+
createdBy {
|
| 2188 |
+
... on Run {
|
| 2189 |
+
name
|
| 2190 |
+
project {
|
| 2191 |
+
name
|
| 2192 |
+
entityName
|
| 2193 |
+
}
|
| 2194 |
+
}
|
| 2195 |
+
}
|
| 2196 |
+
}
|
| 2197 |
+
}
|
| 2198 |
+
"""
|
| 2199 |
+
)
|
| 2200 |
+
assert self._client is not None
|
| 2201 |
+
response = self._client.execute(
|
| 2202 |
+
query,
|
| 2203 |
+
variable_values={"id": self.id},
|
| 2204 |
+
)
|
| 2205 |
+
creator = response.get("artifact", {}).get("createdBy", {})
|
| 2206 |
+
if creator.get("name") is None:
|
| 2207 |
+
return None
|
| 2208 |
+
return Run(
|
| 2209 |
+
self._client,
|
| 2210 |
+
creator["project"]["entityName"],
|
| 2211 |
+
creator["project"]["name"],
|
| 2212 |
+
creator["name"],
|
| 2213 |
+
)
|
| 2214 |
+
|
| 2215 |
+
@ensure_logged
|
| 2216 |
+
def json_encode(self) -> dict[str, Any]:
|
| 2217 |
+
"""Returns the artifact encoded to the JSON format.
|
| 2218 |
+
|
| 2219 |
+
Returns:
|
| 2220 |
+
A `dict` with `string` keys representing attributes of the artifact.
|
| 2221 |
+
"""
|
| 2222 |
+
return util.artifact_to_json(self)
|
| 2223 |
+
|
| 2224 |
+
@staticmethod
|
| 2225 |
+
def _expected_type(
|
| 2226 |
+
entity_name: str, project_name: str, name: str, client: RetryingClient
|
| 2227 |
+
) -> str | None:
|
| 2228 |
+
"""Returns the expected type for a given artifact name and project."""
|
| 2229 |
+
query = gql(
|
| 2230 |
+
"""
|
| 2231 |
+
query ArtifactType(
|
| 2232 |
+
$entityName: String,
|
| 2233 |
+
$projectName: String,
|
| 2234 |
+
$name: String!
|
| 2235 |
+
) {
|
| 2236 |
+
project(name: $projectName, entityName: $entityName) {
|
| 2237 |
+
artifact(name: $name) {
|
| 2238 |
+
artifactType {
|
| 2239 |
+
name
|
| 2240 |
+
}
|
| 2241 |
+
}
|
| 2242 |
+
}
|
| 2243 |
+
}
|
| 2244 |
+
"""
|
| 2245 |
+
)
|
| 2246 |
+
if ":" not in name:
|
| 2247 |
+
name += ":latest"
|
| 2248 |
+
response = client.execute(
|
| 2249 |
+
query,
|
| 2250 |
+
variable_values={
|
| 2251 |
+
"entityName": entity_name,
|
| 2252 |
+
"projectName": project_name,
|
| 2253 |
+
"name": name,
|
| 2254 |
+
},
|
| 2255 |
+
)
|
| 2256 |
+
return (
|
| 2257 |
+
((response.get("project") or {}).get("artifact") or {}).get("artifactType")
|
| 2258 |
+
or {}
|
| 2259 |
+
).get("name")
|
| 2260 |
+
|
| 2261 |
+
@staticmethod
|
| 2262 |
+
def _normalize_metadata(metadata: dict[str, Any] | None) -> dict[str, Any]:
|
| 2263 |
+
if metadata is None:
|
| 2264 |
+
return {}
|
| 2265 |
+
if not isinstance(metadata, dict):
|
| 2266 |
+
raise TypeError(f"metadata must be dict, not {type(metadata)}")
|
| 2267 |
+
return cast(
|
| 2268 |
+
Dict[str, Any], json.loads(json.dumps(util.json_friendly_val(metadata)))
|
| 2269 |
+
)
|
| 2270 |
+
|
| 2271 |
+
def _load_manifest(self, url: str) -> ArtifactManifest:
|
| 2272 |
+
with requests.get(url) as response:
|
| 2273 |
+
response.raise_for_status()
|
| 2274 |
+
return ArtifactManifest.from_manifest_json(response.json())
|
| 2275 |
+
|
| 2276 |
+
def _ttl_duration_seconds_to_gql(self) -> int | None:
|
| 2277 |
+
# Set artifact ttl value to ttl_duration_seconds if the user set a value
|
| 2278 |
+
# otherwise use ttl_status to indicate the backend INHERIT(-1) or DISABLED(-2) when the TTL is None
|
| 2279 |
+
# When ttl_change = None its a no op since nothing changed
|
| 2280 |
+
INHERIT = -1 # noqa: N806
|
| 2281 |
+
DISABLED = -2 # noqa: N806
|
| 2282 |
+
|
| 2283 |
+
if not self._ttl_changed:
|
| 2284 |
+
return None
|
| 2285 |
+
if self._ttl_is_inherited:
|
| 2286 |
+
return INHERIT
|
| 2287 |
+
return self._ttl_duration_seconds or DISABLED
|
| 2288 |
+
|
| 2289 |
+
|
| 2290 |
+
def _ttl_duration_seconds_from_gql(gql_ttl_duration_seconds: int | None) -> int | None:
|
| 2291 |
+
# If gql_ttl_duration_seconds is not positive, its indicating that TTL is DISABLED(-2)
|
| 2292 |
+
# gql_ttl_duration_seconds only returns None if the server is not compatible with setting Artifact TTLs
|
| 2293 |
+
if gql_ttl_duration_seconds and gql_ttl_duration_seconds > 0:
|
| 2294 |
+
return gql_ttl_duration_seconds
|
| 2295 |
+
return None
|
| 2296 |
+
|
| 2297 |
+
|
| 2298 |
+
def _gql_artifact_fragment() -> str:
|
| 2299 |
+
"""Return a GraphQL query fragment with all parseable Artifact attributes."""
|
| 2300 |
+
allowed_fields = set(InternalApi().server_artifact_introspection())
|
| 2301 |
+
|
| 2302 |
+
supports_ttl = "ttlIsInherited" in allowed_fields
|
| 2303 |
+
supports_tags = "tags" in allowed_fields
|
| 2304 |
+
|
| 2305 |
+
ttl_duration_seconds = "ttlDurationSeconds" if supports_ttl else ""
|
| 2306 |
+
ttl_is_inherited = "ttlIsInherited" if supports_ttl else ""
|
| 2307 |
+
|
| 2308 |
+
tags = "tags {name}" if supports_tags else ""
|
| 2309 |
+
|
| 2310 |
+
return f"""
|
| 2311 |
+
fragment ArtifactFragment on Artifact {{
|
| 2312 |
+
id
|
| 2313 |
+
artifactSequence {{
|
| 2314 |
+
project {{
|
| 2315 |
+
entityName
|
| 2316 |
+
name
|
| 2317 |
+
}}
|
| 2318 |
+
name
|
| 2319 |
+
}}
|
| 2320 |
+
versionIndex
|
| 2321 |
+
artifactType {{
|
| 2322 |
+
name
|
| 2323 |
+
}}
|
| 2324 |
+
description
|
| 2325 |
+
metadata
|
| 2326 |
+
{ttl_duration_seconds}
|
| 2327 |
+
{ttl_is_inherited}
|
| 2328 |
+
aliases {{
|
| 2329 |
+
artifactCollection {{
|
| 2330 |
+
project {{
|
| 2331 |
+
entityName
|
| 2332 |
+
name
|
| 2333 |
+
}}
|
| 2334 |
+
name
|
| 2335 |
+
}}
|
| 2336 |
+
alias
|
| 2337 |
+
}}
|
| 2338 |
+
{tags}
|
| 2339 |
+
state
|
| 2340 |
+
currentManifest {{
|
| 2341 |
+
file {{
|
| 2342 |
+
directUrl
|
| 2343 |
+
}}
|
| 2344 |
+
}}
|
| 2345 |
+
commitHash
|
| 2346 |
+
fileCount
|
| 2347 |
+
createdAt
|
| 2348 |
+
updatedAt
|
| 2349 |
+
}}
|
| 2350 |
+
"""
|
| 2351 |
+
|
| 2352 |
+
|
| 2353 |
+
class _ArtifactVersionType(WBType):
|
| 2354 |
+
name = "artifactVersion"
|
| 2355 |
+
types = [Artifact]
|
| 2356 |
+
|
| 2357 |
+
|
| 2358 |
+
TypeRegistry.add(_ArtifactVersionType)
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_instance_cache.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Recent Artifact storage.
|
| 2 |
+
|
| 3 |
+
Artifacts are registered in the cache to ensure they won't be immediately garbage
|
| 4 |
+
collected and can be retrieved by their ID.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
from typing import TYPE_CHECKING
|
| 10 |
+
|
| 11 |
+
from wandb.sdk.lib.capped_dict import CappedDict
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from wandb.sdk.artifacts.artifact import Artifact
|
| 15 |
+
|
| 16 |
+
# There is nothing special about the artifact cache, it's just a global capped dict.
|
| 17 |
+
artifact_instance_cache: dict[str, Artifact] = CappedDict(100)
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact manifest."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import TYPE_CHECKING, Mapping
|
| 6 |
+
|
| 7 |
+
from wandb.sdk.internal.internal_api import Api as InternalApi
|
| 8 |
+
from wandb.sdk.lib.hashutil import HexMD5
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry
|
| 12 |
+
from wandb.sdk.artifacts.storage_policy import StoragePolicy
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class ArtifactManifest:
|
| 16 |
+
entries: dict[str, ArtifactManifestEntry]
|
| 17 |
+
|
| 18 |
+
@classmethod
|
| 19 |
+
def from_manifest_json(
|
| 20 |
+
cls, manifest_json: dict, api: InternalApi | None = None
|
| 21 |
+
) -> ArtifactManifest:
|
| 22 |
+
if "version" not in manifest_json:
|
| 23 |
+
raise ValueError("Invalid manifest format. Must contain version field.")
|
| 24 |
+
version = manifest_json["version"]
|
| 25 |
+
for sub in cls.__subclasses__():
|
| 26 |
+
if sub.version() == version:
|
| 27 |
+
return sub.from_manifest_json(manifest_json, api=api)
|
| 28 |
+
raise ValueError("Invalid manifest version.")
|
| 29 |
+
|
| 30 |
+
@classmethod
|
| 31 |
+
def version(cls) -> int:
|
| 32 |
+
raise NotImplementedError
|
| 33 |
+
|
| 34 |
+
def __init__(
|
| 35 |
+
self,
|
| 36 |
+
storage_policy: StoragePolicy,
|
| 37 |
+
entries: Mapping[str, ArtifactManifestEntry] | None = None,
|
| 38 |
+
) -> None:
|
| 39 |
+
self.storage_policy = storage_policy
|
| 40 |
+
self.entries = dict(entries) if entries else {}
|
| 41 |
+
|
| 42 |
+
def __len__(self) -> int:
|
| 43 |
+
return len(self.entries)
|
| 44 |
+
|
| 45 |
+
def to_manifest_json(self) -> dict:
|
| 46 |
+
raise NotImplementedError
|
| 47 |
+
|
| 48 |
+
def digest(self) -> HexMD5:
|
| 49 |
+
raise NotImplementedError
|
| 50 |
+
|
| 51 |
+
def add_entry(self, entry: ArtifactManifestEntry, overwrite: bool = False) -> None:
|
| 52 |
+
path = entry.path
|
| 53 |
+
if not overwrite:
|
| 54 |
+
prev_entry = self.entries.get(path)
|
| 55 |
+
if prev_entry and (entry.digest != prev_entry.digest):
|
| 56 |
+
raise ValueError(f"Cannot add the same path twice: {path!r}")
|
| 57 |
+
self.entries[path] = entry
|
| 58 |
+
|
| 59 |
+
def remove_entry(self, entry: ArtifactManifestEntry) -> None:
|
| 60 |
+
try:
|
| 61 |
+
del self.entries[entry.path]
|
| 62 |
+
except LookupError:
|
| 63 |
+
raise FileNotFoundError(f"Cannot remove missing entry: '{entry.path}'")
|
| 64 |
+
|
| 65 |
+
def get_entry_by_path(self, path: str) -> ArtifactManifestEntry | None:
|
| 66 |
+
return self.entries.get(path)
|
| 67 |
+
|
| 68 |
+
def get_entries_in_directory(self, directory: str) -> list[ArtifactManifestEntry]:
|
| 69 |
+
return [
|
| 70 |
+
self.entries[entry_key]
|
| 71 |
+
for entry_key in self.entries
|
| 72 |
+
if entry_key.startswith(
|
| 73 |
+
directory + "/"
|
| 74 |
+
) # entries use forward slash even for windows
|
| 75 |
+
]
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest_entry.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact manifest entry."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import TYPE_CHECKING
|
| 10 |
+
from urllib.parse import urlparse
|
| 11 |
+
|
| 12 |
+
from wandb.sdk.lib import filesystem
|
| 13 |
+
from wandb.sdk.lib.deprecate import Deprecated, deprecate
|
| 14 |
+
from wandb.sdk.lib.hashutil import (
|
| 15 |
+
B64MD5,
|
| 16 |
+
ETag,
|
| 17 |
+
b64_to_hex_id,
|
| 18 |
+
hex_to_b64_id,
|
| 19 |
+
md5_file_b64,
|
| 20 |
+
)
|
| 21 |
+
from wandb.sdk.lib.paths import FilePathStr, LogicalPath, StrPath, URIStr
|
| 22 |
+
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
if TYPE_CHECKING:
|
| 26 |
+
from typing_extensions import TypedDict
|
| 27 |
+
|
| 28 |
+
from wandb.sdk.artifacts.artifact import Artifact
|
| 29 |
+
|
| 30 |
+
class ArtifactManifestEntryDict(TypedDict, total=False):
|
| 31 |
+
path: str
|
| 32 |
+
digest: str
|
| 33 |
+
skip_cache: bool
|
| 34 |
+
ref: str
|
| 35 |
+
birthArtifactID: str
|
| 36 |
+
size: int
|
| 37 |
+
extra: dict
|
| 38 |
+
local_path: str
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class ArtifactManifestEntry:
|
| 42 |
+
"""A single entry in an artifact manifest."""
|
| 43 |
+
|
| 44 |
+
path: LogicalPath
|
| 45 |
+
digest: B64MD5 | URIStr | FilePathStr | ETag
|
| 46 |
+
skip_cache: bool
|
| 47 |
+
ref: FilePathStr | URIStr | None
|
| 48 |
+
birth_artifact_id: str | None
|
| 49 |
+
size: int | None
|
| 50 |
+
extra: dict
|
| 51 |
+
local_path: str | None
|
| 52 |
+
|
| 53 |
+
_parent_artifact: Artifact | None = None
|
| 54 |
+
_download_url: str | None = None
|
| 55 |
+
|
| 56 |
+
def __init__(
|
| 57 |
+
self,
|
| 58 |
+
path: StrPath,
|
| 59 |
+
digest: B64MD5 | URIStr | FilePathStr | ETag,
|
| 60 |
+
skip_cache: bool | None = False,
|
| 61 |
+
ref: FilePathStr | URIStr | None = None,
|
| 62 |
+
birth_artifact_id: str | None = None,
|
| 63 |
+
size: int | None = None,
|
| 64 |
+
extra: dict | None = None,
|
| 65 |
+
local_path: StrPath | None = None,
|
| 66 |
+
) -> None:
|
| 67 |
+
self.path = LogicalPath(path)
|
| 68 |
+
self.digest = digest
|
| 69 |
+
self.ref = ref
|
| 70 |
+
self.birth_artifact_id = birth_artifact_id
|
| 71 |
+
self.size = size
|
| 72 |
+
self.extra = extra or {}
|
| 73 |
+
self.local_path = str(local_path) if local_path else None
|
| 74 |
+
if self.local_path and self.size is None:
|
| 75 |
+
self.size = Path(self.local_path).stat().st_size
|
| 76 |
+
self.skip_cache = skip_cache or False
|
| 77 |
+
|
| 78 |
+
def __repr__(self) -> str:
|
| 79 |
+
cls = self.__class__.__name__
|
| 80 |
+
ref = f", ref={self.ref!r}" if self.ref is not None else ""
|
| 81 |
+
birth_artifact_id = (
|
| 82 |
+
f", birth_artifact_id={self.birth_artifact_id!r}"
|
| 83 |
+
if self.birth_artifact_id is not None
|
| 84 |
+
else ""
|
| 85 |
+
)
|
| 86 |
+
size = f", size={self.size}" if self.size is not None else ""
|
| 87 |
+
extra = f", extra={json.dumps(self.extra)}" if self.extra else ""
|
| 88 |
+
local_path = f", local_path={self.local_path!r}" if self.local_path else ""
|
| 89 |
+
skip_cache = f", skip_cache={self.skip_cache}"
|
| 90 |
+
others = ref + birth_artifact_id + size + extra + local_path + skip_cache
|
| 91 |
+
return f"{cls}(path={self.path!r}, digest={self.digest!r}{others})"
|
| 92 |
+
|
| 93 |
+
def __eq__(self, other: object) -> bool:
|
| 94 |
+
"""Strict equality, comparing all public fields.
|
| 95 |
+
|
| 96 |
+
ArtifactManifestEntries for the same file may not compare equal if they were
|
| 97 |
+
added in different ways or created for different parent artifacts.
|
| 98 |
+
"""
|
| 99 |
+
if not isinstance(other, ArtifactManifestEntry):
|
| 100 |
+
return False
|
| 101 |
+
return (
|
| 102 |
+
self.path == other.path
|
| 103 |
+
and self.digest == other.digest
|
| 104 |
+
and self.ref == other.ref
|
| 105 |
+
and self.birth_artifact_id == other.birth_artifact_id
|
| 106 |
+
and self.size == other.size
|
| 107 |
+
and self.extra == other.extra
|
| 108 |
+
and self.local_path == other.local_path
|
| 109 |
+
and self.skip_cache == other.skip_cache
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
@property
|
| 113 |
+
def name(self) -> LogicalPath:
|
| 114 |
+
"""Deprecated; use `path` instead."""
|
| 115 |
+
deprecate(
|
| 116 |
+
field_name=Deprecated.artifactmanifestentry__name,
|
| 117 |
+
warning_message="ArtifactManifestEntry.name is deprecated, use .path instead.",
|
| 118 |
+
)
|
| 119 |
+
return self.path
|
| 120 |
+
|
| 121 |
+
def parent_artifact(self) -> Artifact:
|
| 122 |
+
"""Get the artifact to which this artifact entry belongs.
|
| 123 |
+
|
| 124 |
+
Returns:
|
| 125 |
+
(PublicArtifact): The parent artifact
|
| 126 |
+
"""
|
| 127 |
+
if self._parent_artifact is None:
|
| 128 |
+
raise NotImplementedError
|
| 129 |
+
return self._parent_artifact
|
| 130 |
+
|
| 131 |
+
def download(
|
| 132 |
+
self, root: str | None = None, skip_cache: bool | None = None
|
| 133 |
+
) -> FilePathStr:
|
| 134 |
+
"""Download this artifact entry to the specified root path.
|
| 135 |
+
|
| 136 |
+
Args:
|
| 137 |
+
root: (str, optional) The root path in which to download this
|
| 138 |
+
artifact entry. Defaults to the artifact's root.
|
| 139 |
+
|
| 140 |
+
Returns:
|
| 141 |
+
(str): The path of the downloaded artifact entry.
|
| 142 |
+
"""
|
| 143 |
+
if self._parent_artifact is None:
|
| 144 |
+
raise NotImplementedError
|
| 145 |
+
|
| 146 |
+
root = root or self._parent_artifact._default_root()
|
| 147 |
+
self._parent_artifact._add_download_root(root)
|
| 148 |
+
path = str(Path(self.path))
|
| 149 |
+
dest_path = os.path.join(root, path)
|
| 150 |
+
|
| 151 |
+
if skip_cache:
|
| 152 |
+
override_cache_path = dest_path
|
| 153 |
+
else:
|
| 154 |
+
override_cache_path = None
|
| 155 |
+
|
| 156 |
+
# Skip checking the cache (and possibly downloading) if the file already exists
|
| 157 |
+
# and has the digest we're expecting.
|
| 158 |
+
try:
|
| 159 |
+
md5_hash = md5_file_b64(dest_path)
|
| 160 |
+
except (FileNotFoundError, IsADirectoryError):
|
| 161 |
+
logger.debug(f"unable to find {dest_path}, skip searching for file")
|
| 162 |
+
else:
|
| 163 |
+
if self.digest == md5_hash:
|
| 164 |
+
return FilePathStr(dest_path)
|
| 165 |
+
|
| 166 |
+
if self.ref is not None:
|
| 167 |
+
cache_path = self._parent_artifact.manifest.storage_policy.load_reference(
|
| 168 |
+
self, local=True, dest_path=override_cache_path
|
| 169 |
+
)
|
| 170 |
+
else:
|
| 171 |
+
cache_path = self._parent_artifact.manifest.storage_policy.load_file(
|
| 172 |
+
self._parent_artifact, self, dest_path=override_cache_path
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
if skip_cache:
|
| 176 |
+
return FilePathStr(dest_path)
|
| 177 |
+
else:
|
| 178 |
+
return FilePathStr(
|
| 179 |
+
str(filesystem.copy_or_overwrite_changed(cache_path, dest_path))
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
def ref_target(self) -> FilePathStr | URIStr:
|
| 183 |
+
"""Get the reference URL that is targeted by this artifact entry.
|
| 184 |
+
|
| 185 |
+
Returns:
|
| 186 |
+
(str): The reference URL of this artifact entry.
|
| 187 |
+
|
| 188 |
+
Raises:
|
| 189 |
+
ValueError: If this artifact entry was not a reference.
|
| 190 |
+
"""
|
| 191 |
+
if self.ref is None:
|
| 192 |
+
raise ValueError("Only reference entries support ref_target().")
|
| 193 |
+
if self._parent_artifact is None:
|
| 194 |
+
return self.ref
|
| 195 |
+
return self._parent_artifact.manifest.storage_policy.load_reference(
|
| 196 |
+
self._parent_artifact.manifest.entries[self.path], local=False
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
def ref_url(self) -> str:
|
| 200 |
+
"""Get a URL to this artifact entry.
|
| 201 |
+
|
| 202 |
+
These URLs can be referenced by another artifact.
|
| 203 |
+
|
| 204 |
+
Returns:
|
| 205 |
+
(str): A URL representing this artifact entry.
|
| 206 |
+
|
| 207 |
+
Examples:
|
| 208 |
+
Basic usage
|
| 209 |
+
```
|
| 210 |
+
ref_url = source_artifact.get_entry("file.txt").ref_url()
|
| 211 |
+
derived_artifact.add_reference(ref_url)
|
| 212 |
+
```
|
| 213 |
+
"""
|
| 214 |
+
if self._parent_artifact is None:
|
| 215 |
+
raise NotImplementedError
|
| 216 |
+
assert self._parent_artifact.id is not None
|
| 217 |
+
return (
|
| 218 |
+
"wandb-artifact://"
|
| 219 |
+
+ b64_to_hex_id(B64MD5(self._parent_artifact.id))
|
| 220 |
+
+ "/"
|
| 221 |
+
+ self.path
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
def to_json(self) -> ArtifactManifestEntryDict:
|
| 225 |
+
contents: ArtifactManifestEntryDict = {
|
| 226 |
+
"path": self.path,
|
| 227 |
+
"digest": self.digest,
|
| 228 |
+
}
|
| 229 |
+
if self.size is not None:
|
| 230 |
+
contents["size"] = self.size
|
| 231 |
+
if self.ref:
|
| 232 |
+
contents["ref"] = self.ref
|
| 233 |
+
if self.birth_artifact_id:
|
| 234 |
+
contents["birthArtifactID"] = self.birth_artifact_id
|
| 235 |
+
if self.local_path:
|
| 236 |
+
contents["local_path"] = self.local_path
|
| 237 |
+
if self.skip_cache:
|
| 238 |
+
contents["skip_cache"] = self.skip_cache
|
| 239 |
+
if self.extra:
|
| 240 |
+
contents["extra"] = self.extra
|
| 241 |
+
return contents
|
| 242 |
+
|
| 243 |
+
def _is_artifact_reference(self) -> bool:
|
| 244 |
+
return self.ref is not None and urlparse(self.ref).scheme == "wandb-artifact"
|
| 245 |
+
|
| 246 |
+
def _referenced_artifact_id(self) -> str | None:
|
| 247 |
+
if not self._is_artifact_reference():
|
| 248 |
+
return None
|
| 249 |
+
return hex_to_b64_id(urlparse(self.ref).netloc)
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (188 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/__pycache__/artifact_manifest_v1.cpython-310.pyc
ADDED
|
Binary file (3.84 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact manifest v1."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Mapping
|
| 6 |
+
|
| 7 |
+
from wandb.sdk.artifacts.artifact_manifest import ArtifactManifest
|
| 8 |
+
from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry
|
| 9 |
+
from wandb.sdk.artifacts.storage_policy import StoragePolicy
|
| 10 |
+
from wandb.sdk.internal.internal_api import Api as InternalApi
|
| 11 |
+
from wandb.sdk.lib.hashutil import HexMD5, _md5
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class ArtifactManifestV1(ArtifactManifest):
|
| 15 |
+
@classmethod
|
| 16 |
+
def version(cls) -> int:
|
| 17 |
+
return 1
|
| 18 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def from_manifest_json(
|
| 21 |
+
cls, manifest_json: dict, api: InternalApi | None = None
|
| 22 |
+
) -> ArtifactManifestV1:
|
| 23 |
+
if manifest_json["version"] != cls.version():
|
| 24 |
+
raise ValueError(
|
| 25 |
+
"Expected manifest version 1, got {}".format(manifest_json["version"])
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
storage_policy_name = manifest_json["storagePolicy"]
|
| 29 |
+
storage_policy_config = manifest_json.get("storagePolicyConfig", {})
|
| 30 |
+
storage_policy_cls = StoragePolicy.lookup_by_name(storage_policy_name)
|
| 31 |
+
|
| 32 |
+
entries: Mapping[str, ArtifactManifestEntry]
|
| 33 |
+
entries = {
|
| 34 |
+
name: ArtifactManifestEntry(
|
| 35 |
+
path=name,
|
| 36 |
+
digest=val["digest"],
|
| 37 |
+
birth_artifact_id=val.get("birthArtifactID"),
|
| 38 |
+
ref=val.get("ref"),
|
| 39 |
+
size=val.get("size"),
|
| 40 |
+
extra=val.get("extra"),
|
| 41 |
+
local_path=val.get("local_path"),
|
| 42 |
+
skip_cache=val.get("skip_cache"),
|
| 43 |
+
)
|
| 44 |
+
for name, val in manifest_json["contents"].items()
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return cls(
|
| 48 |
+
storage_policy_cls.from_config(storage_policy_config, api=api), entries
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def __init__(
|
| 52 |
+
self,
|
| 53 |
+
storage_policy: StoragePolicy,
|
| 54 |
+
entries: Mapping[str, ArtifactManifestEntry] | None = None,
|
| 55 |
+
) -> None:
|
| 56 |
+
super().__init__(storage_policy, entries=entries)
|
| 57 |
+
|
| 58 |
+
def to_manifest_json(self) -> dict:
|
| 59 |
+
"""This is the JSON that's stored in wandb_manifest.json.
|
| 60 |
+
|
| 61 |
+
If include_local is True we also include the local paths to files. This is
|
| 62 |
+
used to represent an artifact that's waiting to be saved on the current
|
| 63 |
+
system. We don't need to include the local paths in the artifact manifest
|
| 64 |
+
contents.
|
| 65 |
+
"""
|
| 66 |
+
contents = {}
|
| 67 |
+
for entry in sorted(self.entries.values(), key=lambda k: k.path):
|
| 68 |
+
json_entry: dict[str, Any] = {
|
| 69 |
+
"digest": entry.digest,
|
| 70 |
+
}
|
| 71 |
+
if entry.birth_artifact_id:
|
| 72 |
+
json_entry["birthArtifactID"] = entry.birth_artifact_id
|
| 73 |
+
if entry.ref:
|
| 74 |
+
json_entry["ref"] = entry.ref
|
| 75 |
+
if entry.extra:
|
| 76 |
+
json_entry["extra"] = entry.extra
|
| 77 |
+
if entry.size is not None:
|
| 78 |
+
json_entry["size"] = entry.size
|
| 79 |
+
contents[entry.path] = json_entry
|
| 80 |
+
return {
|
| 81 |
+
"version": self.__class__.version(),
|
| 82 |
+
"storagePolicy": self.storage_policy.name(),
|
| 83 |
+
"storagePolicyConfig": self.storage_policy.config() or {},
|
| 84 |
+
"contents": contents,
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
def digest(self) -> HexMD5:
|
| 88 |
+
hasher = _md5()
|
| 89 |
+
hasher.update(b"wandb-artifact-manifest-v1\n")
|
| 90 |
+
for name, entry in sorted(self.entries.items(), key=lambda kv: kv[0]):
|
| 91 |
+
hasher.update(f"{name}:{entry.digest}\n".encode())
|
| 92 |
+
return HexMD5(hasher.hexdigest())
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_saver.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact saver."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import concurrent.futures
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
+
import tempfile
|
| 9 |
+
from typing import TYPE_CHECKING, Awaitable, Sequence
|
| 10 |
+
|
| 11 |
+
import wandb
|
| 12 |
+
import wandb.filesync.step_prepare
|
| 13 |
+
from wandb import util
|
| 14 |
+
from wandb.sdk.artifacts.artifact_manifest import ArtifactManifest
|
| 15 |
+
from wandb.sdk.lib.hashutil import B64MD5, b64_to_hex_id, md5_file_b64
|
| 16 |
+
from wandb.sdk.lib.paths import URIStr
|
| 17 |
+
|
| 18 |
+
if TYPE_CHECKING:
|
| 19 |
+
from typing import Protocol
|
| 20 |
+
|
| 21 |
+
from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry
|
| 22 |
+
from wandb.sdk.internal.file_pusher import FilePusher
|
| 23 |
+
from wandb.sdk.internal.internal_api import Api as InternalApi
|
| 24 |
+
from wandb.sdk.internal.progress import ProgressFn
|
| 25 |
+
|
| 26 |
+
class SaveFn(Protocol):
|
| 27 |
+
def __call__(
|
| 28 |
+
self, entry: ArtifactManifestEntry, progress_callback: ProgressFn
|
| 29 |
+
) -> bool:
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
class SaveFnAsync(Protocol):
|
| 33 |
+
def __call__(
|
| 34 |
+
self, entry: ArtifactManifestEntry, progress_callback: ProgressFn
|
| 35 |
+
) -> Awaitable[bool]:
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class ArtifactSaver:
|
| 40 |
+
_server_artifact: dict | None # TODO better define this dict
|
| 41 |
+
|
| 42 |
+
def __init__(
|
| 43 |
+
self,
|
| 44 |
+
api: InternalApi,
|
| 45 |
+
digest: str,
|
| 46 |
+
manifest_json: dict,
|
| 47 |
+
file_pusher: FilePusher,
|
| 48 |
+
is_user_created: bool = False,
|
| 49 |
+
) -> None:
|
| 50 |
+
self._api = api
|
| 51 |
+
self._file_pusher = file_pusher
|
| 52 |
+
self._digest = digest
|
| 53 |
+
self._manifest = ArtifactManifest.from_manifest_json(
|
| 54 |
+
manifest_json,
|
| 55 |
+
api=self._api,
|
| 56 |
+
)
|
| 57 |
+
self._is_user_created = is_user_created
|
| 58 |
+
self._server_artifact = None
|
| 59 |
+
|
| 60 |
+
def save(
|
| 61 |
+
self,
|
| 62 |
+
type: str,
|
| 63 |
+
name: str,
|
| 64 |
+
client_id: str,
|
| 65 |
+
sequence_client_id: str,
|
| 66 |
+
distributed_id: str | None = None,
|
| 67 |
+
finalize: bool = True,
|
| 68 |
+
metadata: dict | None = None,
|
| 69 |
+
ttl_duration_seconds: int | None = None,
|
| 70 |
+
description: str | None = None,
|
| 71 |
+
aliases: Sequence[str] | None = None,
|
| 72 |
+
tags: Sequence[str] | None = None,
|
| 73 |
+
use_after_commit: bool = False,
|
| 74 |
+
incremental: bool = False,
|
| 75 |
+
history_step: int | None = None,
|
| 76 |
+
base_id: str | None = None,
|
| 77 |
+
) -> dict | None:
|
| 78 |
+
return self._save_internal(
|
| 79 |
+
type,
|
| 80 |
+
name,
|
| 81 |
+
client_id,
|
| 82 |
+
sequence_client_id,
|
| 83 |
+
distributed_id,
|
| 84 |
+
finalize,
|
| 85 |
+
metadata,
|
| 86 |
+
ttl_duration_seconds,
|
| 87 |
+
description,
|
| 88 |
+
aliases,
|
| 89 |
+
tags,
|
| 90 |
+
use_after_commit,
|
| 91 |
+
incremental,
|
| 92 |
+
history_step,
|
| 93 |
+
base_id,
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
def _save_internal(
|
| 97 |
+
self,
|
| 98 |
+
type: str,
|
| 99 |
+
name: str,
|
| 100 |
+
client_id: str,
|
| 101 |
+
sequence_client_id: str,
|
| 102 |
+
distributed_id: str | None = None,
|
| 103 |
+
finalize: bool = True,
|
| 104 |
+
metadata: dict | None = None,
|
| 105 |
+
ttl_duration_seconds: int | None = None,
|
| 106 |
+
description: str | None = None,
|
| 107 |
+
aliases: Sequence[str] | None = None,
|
| 108 |
+
tags: Sequence[str] | None = None,
|
| 109 |
+
use_after_commit: bool = False,
|
| 110 |
+
incremental: bool = False,
|
| 111 |
+
history_step: int | None = None,
|
| 112 |
+
base_id: str | None = None,
|
| 113 |
+
) -> dict | None:
|
| 114 |
+
alias_specs = []
|
| 115 |
+
for alias in aliases or []:
|
| 116 |
+
alias_specs.append({"artifactCollectionName": name, "alias": alias})
|
| 117 |
+
|
| 118 |
+
tag_specs = [{"tagName": tag} for tag in tags or []]
|
| 119 |
+
|
| 120 |
+
"""Returns the server artifact."""
|
| 121 |
+
self._server_artifact, latest = self._api.create_artifact(
|
| 122 |
+
type,
|
| 123 |
+
name,
|
| 124 |
+
self._digest,
|
| 125 |
+
metadata=metadata,
|
| 126 |
+
ttl_duration_seconds=ttl_duration_seconds,
|
| 127 |
+
aliases=alias_specs,
|
| 128 |
+
tags=tag_specs,
|
| 129 |
+
description=description,
|
| 130 |
+
is_user_created=self._is_user_created,
|
| 131 |
+
distributed_id=distributed_id,
|
| 132 |
+
client_id=client_id,
|
| 133 |
+
sequence_client_id=sequence_client_id,
|
| 134 |
+
history_step=history_step,
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
assert self._server_artifact is not None # mypy optionality unwrapper
|
| 138 |
+
artifact_id = self._server_artifact["id"]
|
| 139 |
+
if base_id is None and latest:
|
| 140 |
+
base_id = latest["id"]
|
| 141 |
+
if self._server_artifact["state"] == "COMMITTED":
|
| 142 |
+
if use_after_commit:
|
| 143 |
+
self._api.use_artifact(artifact_id)
|
| 144 |
+
return self._server_artifact
|
| 145 |
+
if (
|
| 146 |
+
self._server_artifact["state"] != "PENDING"
|
| 147 |
+
# For old servers, see https://github.com/wandb/wandb/pull/6190
|
| 148 |
+
and self._server_artifact["state"] != "DELETED"
|
| 149 |
+
):
|
| 150 |
+
raise Exception(
|
| 151 |
+
'Unknown artifact state "{}"'.format(self._server_artifact["state"])
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
manifest_type = "FULL"
|
| 155 |
+
manifest_filename = "wandb_manifest.json"
|
| 156 |
+
if incremental:
|
| 157 |
+
manifest_type = "INCREMENTAL"
|
| 158 |
+
manifest_filename = "wandb_manifest.incremental.json"
|
| 159 |
+
elif distributed_id:
|
| 160 |
+
manifest_type = "PATCH"
|
| 161 |
+
manifest_filename = "wandb_manifest.patch.json"
|
| 162 |
+
artifact_manifest_id, _ = self._api.create_artifact_manifest(
|
| 163 |
+
manifest_filename,
|
| 164 |
+
"",
|
| 165 |
+
artifact_id,
|
| 166 |
+
base_artifact_id=base_id,
|
| 167 |
+
include_upload=False,
|
| 168 |
+
type=manifest_type,
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
step_prepare = wandb.filesync.step_prepare.StepPrepare(
|
| 172 |
+
self._api, 0.1, 0.01, 1000
|
| 173 |
+
) # TODO: params
|
| 174 |
+
step_prepare.start()
|
| 175 |
+
|
| 176 |
+
# Upload Artifact "L1" files, the actual artifact contents
|
| 177 |
+
self._file_pusher.store_manifest_files(
|
| 178 |
+
self._manifest,
|
| 179 |
+
artifact_id,
|
| 180 |
+
lambda entry, progress_callback: self._manifest.storage_policy.store_file(
|
| 181 |
+
artifact_id,
|
| 182 |
+
artifact_manifest_id,
|
| 183 |
+
entry,
|
| 184 |
+
step_prepare,
|
| 185 |
+
progress_callback=progress_callback,
|
| 186 |
+
),
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
def before_commit() -> None:
|
| 190 |
+
self._resolve_client_id_manifest_references()
|
| 191 |
+
with tempfile.NamedTemporaryFile("w+", suffix=".json", delete=False) as fp:
|
| 192 |
+
path = os.path.abspath(fp.name)
|
| 193 |
+
json.dump(self._manifest.to_manifest_json(), fp, indent=4)
|
| 194 |
+
digest = md5_file_b64(path)
|
| 195 |
+
if distributed_id or incremental:
|
| 196 |
+
# If we're in the distributed flow, we want to update the
|
| 197 |
+
# patch manifest we created with our finalized digest.
|
| 198 |
+
_, resp = self._api.update_artifact_manifest(
|
| 199 |
+
artifact_manifest_id,
|
| 200 |
+
digest=digest,
|
| 201 |
+
)
|
| 202 |
+
else:
|
| 203 |
+
# In the regular flow, we can recreate the full manifest with the
|
| 204 |
+
# updated digest.
|
| 205 |
+
#
|
| 206 |
+
# NOTE: We do this for backwards compatibility with older backends
|
| 207 |
+
# that don't support the 'updateArtifactManifest' API.
|
| 208 |
+
_, resp = self._api.create_artifact_manifest(
|
| 209 |
+
manifest_filename,
|
| 210 |
+
digest,
|
| 211 |
+
artifact_id,
|
| 212 |
+
base_artifact_id=base_id,
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
# We're duplicating the file upload logic a little, which isn't great.
|
| 216 |
+
upload_url = resp["uploadUrl"]
|
| 217 |
+
upload_headers = resp["uploadHeaders"]
|
| 218 |
+
extra_headers = {}
|
| 219 |
+
for upload_header in upload_headers:
|
| 220 |
+
key, val = upload_header.split(":", 1)
|
| 221 |
+
extra_headers[key] = val
|
| 222 |
+
with open(path, "rb") as fp2:
|
| 223 |
+
self._api.upload_file_retry(
|
| 224 |
+
upload_url,
|
| 225 |
+
fp2,
|
| 226 |
+
extra_headers=extra_headers,
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
commit_result: concurrent.futures.Future[None] = concurrent.futures.Future()
|
| 230 |
+
|
| 231 |
+
# This will queue the commit. It will only happen after all the file uploads are done
|
| 232 |
+
self._file_pusher.commit_artifact(
|
| 233 |
+
artifact_id,
|
| 234 |
+
finalize=finalize,
|
| 235 |
+
before_commit=before_commit,
|
| 236 |
+
result_future=commit_result,
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
# Block until all artifact files are uploaded and the
|
| 240 |
+
# artifact is committed.
|
| 241 |
+
try:
|
| 242 |
+
commit_result.result()
|
| 243 |
+
finally:
|
| 244 |
+
step_prepare.shutdown()
|
| 245 |
+
|
| 246 |
+
if finalize and use_after_commit:
|
| 247 |
+
self._api.use_artifact(artifact_id)
|
| 248 |
+
|
| 249 |
+
return self._server_artifact
|
| 250 |
+
|
| 251 |
+
def _resolve_client_id_manifest_references(self) -> None:
|
| 252 |
+
for entry_path in self._manifest.entries:
|
| 253 |
+
entry = self._manifest.entries[entry_path]
|
| 254 |
+
if entry.ref is not None:
|
| 255 |
+
if entry.ref.startswith("wandb-client-artifact:"):
|
| 256 |
+
client_id = util.host_from_path(entry.ref)
|
| 257 |
+
artifact_file_path = util.uri_from_path(entry.ref)
|
| 258 |
+
artifact_id = self._api._resolve_client_id(client_id)
|
| 259 |
+
if artifact_id is None:
|
| 260 |
+
raise RuntimeError(f"Could not resolve client id {client_id}")
|
| 261 |
+
entry.ref = URIStr(
|
| 262 |
+
"wandb-artifact://{}/{}".format(
|
| 263 |
+
b64_to_hex_id(B64MD5(artifact_id)), artifact_file_path
|
| 264 |
+
)
|
| 265 |
+
)
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_state.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact state."""
|
| 2 |
+
|
| 3 |
+
from enum import Enum
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ArtifactState(Enum):
|
| 7 |
+
PENDING = "PENDING"
|
| 8 |
+
COMMITTED = "COMMITTED"
|
| 9 |
+
DELETED = "DELETED"
|
| 10 |
+
GARBAGE_COLLECTED = "GARBAGE_COLLECTED"
|
| 11 |
+
PENDING_DELETION = "PENDING_DELETION"
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_ttl.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact TTL."""
|
| 2 |
+
|
| 3 |
+
from enum import Enum
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ArtifactTTL(Enum):
|
| 7 |
+
INHERIT = 0
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/exceptions.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Artifact exceptions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import TYPE_CHECKING, TypeVar
|
| 6 |
+
|
| 7 |
+
from wandb import errors
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
from wandb.sdk.artifacts.artifact import Artifact
|
| 11 |
+
|
| 12 |
+
ArtifactT = TypeVar("ArtifactT", bound=Artifact)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class ArtifactStatusError(AttributeError):
|
| 16 |
+
"""Raised when an artifact is in an invalid state for the requested operation."""
|
| 17 |
+
|
| 18 |
+
def __init__(
|
| 19 |
+
self,
|
| 20 |
+
msg: str = "Artifact is in an invalid state for the requested operation.",
|
| 21 |
+
name: str | None = None,
|
| 22 |
+
obj: ArtifactT | None = None,
|
| 23 |
+
):
|
| 24 |
+
# Follow the same pattern as AttributeError in python 3.10+ by `name/obj` attributes
|
| 25 |
+
# See: https://docs.python.org/3/library/exceptions.html#AttributeError
|
| 26 |
+
try:
|
| 27 |
+
super().__init__(msg, name=name, obj=obj)
|
| 28 |
+
except TypeError:
|
| 29 |
+
# The `name`/`obj` keyword args and attributes were only added in python >= 3.10
|
| 30 |
+
super().__init__(msg)
|
| 31 |
+
self.name = name or ""
|
| 32 |
+
self.obj = obj
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class ArtifactNotLoggedError(ArtifactStatusError):
|
| 36 |
+
"""Raised for Artifact methods or attributes only available after logging."""
|
| 37 |
+
|
| 38 |
+
def __init__(self, fullname: str, obj: ArtifactT):
|
| 39 |
+
*_, name = fullname.split(".")
|
| 40 |
+
msg = (
|
| 41 |
+
f"{fullname!r} used prior to logging artifact or while in offline mode. "
|
| 42 |
+
f"Call {type(obj).wait.__qualname__}() before accessing logged artifact properties."
|
| 43 |
+
)
|
| 44 |
+
super().__init__(msg=msg, name=name, obj=obj)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class ArtifactFinalizedError(ArtifactStatusError):
|
| 48 |
+
"""Raised for Artifact methods or attributes that can't be changed after logging."""
|
| 49 |
+
|
| 50 |
+
def __init__(self, fullname: str, obj: ArtifactT):
|
| 51 |
+
*_, name = fullname.split(".")
|
| 52 |
+
msg = f"{fullname!r} used on logged artifact. Can't modify finalized artifact."
|
| 53 |
+
super().__init__(msg=msg, name=name, obj=obj)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class WaitTimeoutError(errors.Error):
|
| 57 |
+
"""Raised when wait() timeout occurs before process is finished."""
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/staging.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Manages artifact file staging.
|
| 2 |
+
|
| 3 |
+
Artifact files are copied to the staging area as soon as they are added to an artifact
|
| 4 |
+
in order to avoid file changes corrupting the artifact. Once the upload is complete, the
|
| 5 |
+
file should be moved to the artifact cache.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
from wandb import env
|
| 11 |
+
from wandb.sdk.lib.filesystem import mkdir_exists_ok
|
| 12 |
+
from wandb.sdk.lib.paths import FilePathStr
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def get_staging_dir() -> FilePathStr:
|
| 16 |
+
path = os.path.join(env.get_data_dir(), "artifacts", "staging")
|
| 17 |
+
try:
|
| 18 |
+
mkdir_exists_ok(path)
|
| 19 |
+
except OSError as e:
|
| 20 |
+
raise PermissionError(
|
| 21 |
+
f"Unable to write staging files to {path}. To fix this problem, please set "
|
| 22 |
+
f"{env.DATA_DIR} to a directory where you have the necessary write access."
|
| 23 |
+
) from e
|
| 24 |
+
|
| 25 |
+
return FilePathStr(os.path.abspath(os.path.expanduser(path)))
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handler.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Storage handler."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import TYPE_CHECKING, Sequence
|
| 6 |
+
|
| 7 |
+
from wandb.sdk.lib.paths import FilePathStr, URIStr
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
from urllib.parse import ParseResult
|
| 11 |
+
|
| 12 |
+
from wandb.sdk.artifacts.artifact import Artifact
|
| 13 |
+
from wandb.sdk.artifacts.artifact_manifest_entry import ArtifactManifestEntry
|
| 14 |
+
|
| 15 |
+
DEFAULT_MAX_OBJECTS = 10**7
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class StorageHandler:
|
| 19 |
+
def can_handle(self, parsed_url: ParseResult) -> bool:
|
| 20 |
+
"""Checks whether this handler can handle the given url.
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
Whether this handler can handle the given url.
|
| 24 |
+
"""
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
def load_path(
|
| 28 |
+
self,
|
| 29 |
+
manifest_entry: ArtifactManifestEntry,
|
| 30 |
+
local: bool = False,
|
| 31 |
+
) -> URIStr | FilePathStr:
|
| 32 |
+
"""Load a file or directory given the corresponding index entry.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
manifest_entry: The index entry to load
|
| 36 |
+
local: Whether to load the file locally or not
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
A path to the file represented by `index_entry`
|
| 40 |
+
"""
|
| 41 |
+
raise NotImplementedError
|
| 42 |
+
|
| 43 |
+
def store_path(
|
| 44 |
+
self,
|
| 45 |
+
artifact: Artifact,
|
| 46 |
+
path: URIStr | FilePathStr,
|
| 47 |
+
name: str | None = None,
|
| 48 |
+
checksum: bool = True,
|
| 49 |
+
max_objects: int | None = None,
|
| 50 |
+
) -> Sequence[ArtifactManifestEntry]:
|
| 51 |
+
"""Store the file or directory at the given path to the specified artifact.
|
| 52 |
+
|
| 53 |
+
Args:
|
| 54 |
+
path: The path to store
|
| 55 |
+
name: If specified, the logical name that should map to `path`
|
| 56 |
+
checksum: Whether to compute the checksum of the file
|
| 57 |
+
max_objects: The maximum number of objects to store
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
A list of manifest entries to store within the artifact
|
| 61 |
+
"""
|
| 62 |
+
raise NotImplementedError
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (186 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/azure_handler.cpython-310.pyc
ADDED
|
Binary file (6.07 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/gcs_handler.cpython-310.pyc
ADDED
|
Binary file (6.54 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/http_handler.cpython-310.pyc
ADDED
|
Binary file (3.84 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/local_file_handler.cpython-310.pyc
ADDED
|
Binary file (4.29 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/multi_handler.cpython-310.pyc
ADDED
|
Binary file (2.31 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/s3_handler.cpython-310.pyc
ADDED
|
Binary file (8 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/tracking_handler.cpython-310.pyc
ADDED
|
Binary file (2.76 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/sdk/artifacts/storage_handlers/__pycache__/wb_artifact_handler.cpython-310.pyc
ADDED
|
Binary file (4.17 kB). View file
|
|
|