Skip to content

Commit

Permalink
Update for pyo3 0.21.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Apr 1, 2024
1 parent 5522bbc commit 64e0534
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 87 deletions.
2 changes: 1 addition & 1 deletion candle-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hf-hub = { workspace = true, features = ["tokio"] }
image = { workspace = true }
intel-mkl-src = { workspace = true, optional = true }
num-traits = { workspace = true }
pyo3 = { version = "0.20.0", features = ["auto-initialize"], optional = true }
pyo3 = { version = "0.21.0", features = ["auto-initialize"], optional = true }
rayon = { workspace = true }
rubato = { version = "0.15.0", optional = true }
safetensors = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions candle-pyo3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ candle-nn = { workspace = true }
candle-onnx = { workspace = true, optional = true }
half = { workspace = true }
intel-mkl-src = { workspace = true, optional = true }
pyo3 = { version = "0.20.0", features = ["extension-module", "abi3-py38"] }
pyo3 = { version = "0.21.0", features = ["extension-module", "abi3-py38"] }

[build-dependencies]
pyo3-build-config = "0.20"
pyo3-build-config = "0.21"

[features]
default = []
Expand Down
45 changes: 7 additions & 38 deletions candle-pyo3/py_src/candle/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ class i64(DType):
pass

@staticmethod
def ones(*shape: Shape, dtype: Optional[DType] = None, device: Optional[Device] = None) -> Tensor:
def ones(shape: Sequence[int], dtype: Optional[DType] = None, device: Optional[Device] = None) -> Tensor:
"""
Creates a new tensor filled with ones.
"""
pass

@staticmethod
def rand(*shape: Shape, device: Optional[Device] = None) -> Tensor:
def rand(shape: Sequence[int], device: Optional[Device] = None) -> Tensor:
"""
Creates a new tensor with random values.
"""
pass

@staticmethod
def randn(*shape: Shape, device: Optional[Device] = None) -> Tensor:
def randn(shape: Sequence[int], device: Optional[Device] = None) -> Tensor:
"""
Creates a new tensor with random values from a normal distribution.
"""
Expand All @@ -67,7 +67,7 @@ class u8(DType):
pass

@staticmethod
def zeros(*shape: Shape, dtype: Optional[DType] = None, device: Optional[Device] = None) -> Tensor:
def zeros(shape: Sequence[int], dtype: Optional[DType] = None, device: Optional[Device] = None) -> Tensor:
"""
Creates a new tensor filled with zeros.
"""
Expand Down Expand Up @@ -208,12 +208,6 @@ class Tensor:
"""
pass

def abs(self) -> Tensor:
"""
Performs the `abs` operation on the tensor.
"""
pass

def argmax_keepdim(self, dim: int) -> Tensor:
"""
Returns the indices of the maximum value(s) across the selected dimension.
Expand All @@ -232,7 +226,7 @@ class Tensor:
"""
pass

def broadcast_as(self, *shape: Shape) -> Tensor:
def broadcast_as(self, shape: Sequence[int]) -> Tensor:
"""
Broadcasts the tensor to the given shape.
"""
Expand All @@ -244,7 +238,7 @@ class Tensor:
"""
pass

def broadcast_left(self, *shape: Shape) -> Tensor:
def broadcast_left(self, shape: Sequence[int]) -> Tensor:
"""
Broadcasts the tensor to the given shape, adding new dimensions on the left.
"""
Expand Down Expand Up @@ -324,12 +318,6 @@ class Tensor:
"""
pass

def gather(self, index, dim):
"""
Gathers values along an axis specified by dim.
"""
pass

def get(self, index: int) -> Tensor:
"""
Gets the value at the specified index.
Expand Down Expand Up @@ -397,13 +385,6 @@ class Tensor:
"""
pass

@property
def nelement(self) -> int:
"""
Gets the tensor's element count.
"""
pass

def powf(self, p: float) -> Tensor:
"""
Performs the `pow` operation on the tensor with the given exponent.
Expand All @@ -429,7 +410,7 @@ class Tensor:
"""
pass

def reshape(self, *shape: Shape) -> Tensor:
def reshape(self, shape: Sequence[int]) -> Tensor:
"""
Reshapes the tensor to the given shape.
"""
Expand Down Expand Up @@ -491,12 +472,6 @@ class Tensor:
"""
pass

def to(self, *args, **kwargs) -> Tensor:
"""
Performs Tensor dtype and/or device conversion.
"""
pass

def to_device(self, device: Union[str, Device]) -> Tensor:
"""
Move the tensor to a new device.
Expand All @@ -509,12 +484,6 @@ class Tensor:
"""
pass

def to_torch(self) -> torch.Tensor:
"""
Converts candle's tensor to pytorch's tensor
"""
pass

def transpose(self, dim1: int, dim2: int) -> Tensor:
"""
Returns a tensor that is a transposed version of the input, the given dimensions are swapped.
Expand Down
19 changes: 19 additions & 0 deletions candle-pyo3/py_src/candle/nn/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated content DO NOT EDIT
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, Sequence
from os import PathLike
from candle.typing import _ArrayLike, Device, Scalar, Index, Shape
from candle import Tensor, DType, QTensor

@staticmethod
def silu(tensor: Tensor) -> Tensor:
"""
Applies the Sigmoid Linear Unit (SiLU) function to a given tensor.
"""
pass

@staticmethod
def softmax(tensor: Tensor, dim: int) -> Tensor:
"""
Applies the Softmax function to a given tensor.#
"""
pass
8 changes: 2 additions & 6 deletions candle-pyo3/py_src/candle/utils/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ def has_mkl() -> bool:
pass

@staticmethod
def load_ggml(
path: Union[str, PathLike], device: Optional[Device] = None
) -> Tuple[Dict[str, QTensor], Dict[str, Any], List[str]]:
def load_ggml(path: Union[str, PathLike]) -> Tuple[Dict[str, QTensor], Dict[str, Any], List[str]]:
"""
Load a GGML file. Returns a tuple of three objects: a dictionary mapping tensor names to tensors,
a dictionary mapping hyperparameter names to hyperparameter values, and a vocabulary.
"""
pass

@staticmethod
def load_gguf(
path: Union[str, PathLike], device: Optional[Device] = None
) -> Tuple[Dict[str, QTensor], Dict[str, Any]]:
def load_gguf(path: Union[str, PathLike]) -> Tuple[Dict[str, QTensor], Dict[str, Any]]:
"""
Loads a GGUF file. Returns a tuple of two dictionaries: the first maps tensor names to tensors,
and the second maps metadata keys to metadata values.
Expand Down
Loading

0 comments on commit 64e0534

Please sign in to comment.