8000 merge with main · python/typeshed@8b672df · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b672df

Browse files
committed
merge with main
2 parents fbc0199 + 6c52322 commit 8b672df

File tree

10 files changed

+230
-18
lines changed

10 files changed

+230
-18
lines changed

stubs/tensorflow/@tests/stubtest_allowlist.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ tensorflow._aliases
4848
# but the real module file is completely different name (even package) and dynamically handled.
4949
# tf.initializers at runtime is <module 'keras.api._v2.keras.initializers' from '...'>
5050
tensorflow.initializers
51+
# Other cursed import magic similar to the one above.
52+
tensorflow.keras.layers.preprocessing
53+
tensorflow.keras.layers.preprocessing.index_lookup
5154
# Another cursed import magic similar to the one above.
5255
tensorflow.distribute.experimental.coordinator
5356

@@ -111,8 +114,5 @@ tensorflow.train.ServerDef.*
111114
# python.X
112115
tensorflow.python.*
113116

114-
# The modules below are re-exported from tensorflow.python, and they therefore appear missing to stubtest.
115-
tensorflow.distribute.Strategy
116-
117117
# sigmoid_cross_entropy_with_logits has default values (None), however those values are not valid.
118118
tensorflow.nn.sigmoid_cross_entropy_with_logits

stubs/tensorflow/tensorflow/__init__.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ from tensorflow import (
2121
from tensorflow._aliases import AnyArray, DTypeLike, ShapeLike, Slice, TensorCompatible
2222
from tensorflow.autodiff import GradientTape as GradientTape
2323
from tensorflow.core.protobuf import struct_pb2
24-
25-
# Explicit import of DType is covered by the wildcard, but
26-
# is necessary to avoid a crash in pytype.
2724
from tensorflow.dtypes import *
28-
from tensorflow.dtypes import DType as DType
2925
from tensorflow.experimental.dtensor import Layout
3026
from tensorflow.keras import losses as losses
3127
from tensorflow.linalg import eye as eye

stubs/tensorflow/tensorflow/_aliases.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ from collections.abc import Iterable, Mapping, Sequence
55
from typing import Any, Protocol, TypeVar
66
from typing_extensions import TypeAlias
77

8+
import numpy # pytype needs the unaliased import to resolve DTypeLike
89
import numpy as np
910
import numpy.typing as npt
1011
import tensorflow as tf
12+
from tensorflow.dtypes import DType
1113
from tensorflow.keras.layers import InputSpec
1214

1315
_T = TypeVar("_T")
@@ -29,10 +31,12 @@ KerasSerializable: TypeAlias = KerasSerializable1 | KerasSerializable2
2931

3032
TensorValue: TypeAlias = tf.Tensor # Alias for a 0D Tensor
3133
Integer: TypeAlias = TensorValue | int | IntArray | np.number[Any] # Here IntArray are assumed to be 0D.
34+
Float: TypeAlias = Integer | float | FloatArray
3235
Slice: TypeAlias = int | slice | None
3336
FloatDataSequence: TypeAlias = Sequence[float] | Sequence[FloatDataSequence]
3437
IntDataSequence: TypeAlias = Sequence[int] | Sequence[IntDataSequence]
3538
StrDataSequence: TypeAlias = Sequence[str] | Sequence[StrDataSequence]
39+
DataSequence: TypeAlias = FloatDataSequence | StrDataSequence | IntDataSequence
3640
ScalarTensorCompatible: TypeAlias = tf.Tensor | str | float | np.ndarray[Any, Any] | np.number[Any]
3741
UIntTensorCompatible: TypeAlias = tf.Tensor | int | UIntArray
3842
FloatTensorCompatible: TypeAlias = tf.Tensor | int | IntArray | float | FloatArray | np.number[Any]
@@ -51,7 +55,7 @@ SparseTensorCompatible: TypeAlias = TensorCompatible | tf.SparseTensor
5155
TensorOrArray: TypeAlias = tf.Tensor | AnyArray
5256

5357
ShapeLike: TypeAlias = tf.TensorShape | Iterable[ScalarTensorCompatible | None] | int | tf.Tensor
54-
DTypeLike: TypeAlias = tf.DType | str | np.dtype[Any] | int
58+
DTypeLike: TypeAlias = DType | str | numpy.dtype[Any] | int
5559

5660
ContainerTensors: TypeAlias = ContainerGeneric[tf.Tensor]
5761
ContainerTensorsLike: TypeAlias = ContainerGeneric[TensorLike]

stubs/tensorflow/tensorflow/keras/layers.pyi renamed to stubs/tensorflow/tensorflow/keras/layers/__init__.pyi

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Callable, Iterable, Sequence
3-
from typing import Any, Generic, TypeVar, overload
2+
from collections.abc import Callable, Iterable, Mapping, Sequence
3+
from typing import Any, Generic, Literal, TypeVar, overload
44
from typing_extensions import Self, TypeAlias
55

66
import tensorflow as tf
77
from tensorflow import Tensor, Variable, VariableAggregation, VariableSynchronization
8-
from tensorflow._aliases import AnyArray, DTypeLike, TensorCompatible
8+
from tensorflow._aliases import AnyArray, DTypeLike, TensorCompatible, TensorLike
99
from tensorflow.keras.activations import _Activation
1010
from tensorflow.keras.constraints import Constraint
1111
from tensorflow.keras.initializers import _Initializer
12-
from tensorflow.keras.regularizers import _Regularizer
12+
from tensorflow.keras.layers.preprocessing import IntegerLookup as IntegerLookup, StringLookup as StringLookup
10000 13+
from tensorflow.keras.regularizers import Regularizer, _Regularizer
14+
from tensorflow.python.feature_column.feature_column_v2 import DenseColumn, SequenceDenseColumn
1315

1416
_InputT = TypeVar("_InputT", contravariant=True)
1517
_OutputT = TypeVar("_OutputT", covariant=True)
@@ -127,7 +129,7 @@ class Dense(Layer[tf.Tensor, tf.Tensor]):
127129
kernel_constraint: _Constraint = None,
128130
bias_constraint: _Constraint = None,
129131
trainable: bool = True,
130-
dtype: _LayerDtype = None,
132+
dtype: _LayerDtype | None = None,
131133
dynamic: bool = False,
132134
name: str | None = None,
133135
) -> None: ...
@@ -149,7 +151,7 @@ class BatchNormalization(Layer[tf.Tensor, tf.Tensor]):
149151
beta_constraint: _Constraint = None,
150152
gamma_constraint: _Constraint = None,
151153
trainable: bool = True,
152-
dtype: _LayerDtype = None,
154+
dtype: _LayerDtype | None = None,
153155
dynamic: bool = False,
154156
name: str | None = None,
155157
) -> None: ...
@@ -161,7 +163,7 @@ class ReLU(Layer[tf.Tensor, tf.Tensor]):
161163
negative_slope: float | None = 0.0,
162164
threshold: float | None = 0.0,
163165
trainable: bool = True,
164-
dtype: _LayerDtype = None,
166+
dtype: _LayerDtype | None = None,
165167
dynamic: bool = False,
166168
name: str | None = None,
167169
) -> None: ...
@@ -173,7 +175,7 @@ class Dropout(Layer[tf.Tensor, tf.Tensor]):
173175
noise_shape: TensorCompatible | Sequence[int | None] | None = None,
174176
seed: int | None = None,
175177
trainable: bool = True,
176-
dtype: _LayerDtype = None,
178+
dtype: _LayerDtype | None = None,
177179
dynamic: bool = False,
178180
name: str | None = None,
179181
) -> None: ...
@@ -189,6 +191,133 @@ class Embedding(Layer[tf.Tensor, tf.Tensor]):
189191
mask_zero: bool = False,
190192
input_length: int | None = None,
191193
trainable: bool = True,
194+
dtype: _LayerDtype | None = None,
195+
dynamic: bool = False,
196+
name: str | None = None,
197+
) -> None: ...
198+
199+
class Conv2D(Layer[tf.Tensor, tf.Tensor]):
200+
def __init__(
201+
self,
202+
filters: int,
203+
kernel_size: int | Iterable[int],
204+
strides: int | Iterable[int] = (1, 1),
205+
padding: Literal["valid", "same"] = "valid",
206+
data_format: None | Literal["channels_last", "channels_first"] = None,
207+
dilation_rate: int | Iterable[int] = (1, 1),
208+
groups: int = 1,
209+
activation: _Activation = None,
210+
use_bias: bool = True,
211+
kernel_initializer: _Initializer = "glorot_uniform",
212+
bias_initializer: _Initializer = "zeros",
213+
kernel_regularizer: _Regularizer = None,
214+
bias_regularizer: _Regularizer = None,
215+
activity_regularizer: _Regularizer = None,
216+
kernel_constraint: _Constraint = None,
217+
bias_constraint: _Constraint = None,
218+
trainable: bool = True,
219+
dtype: _LayerDtype | None = None,
220+
dynamic: bool = False,
221+
name: str | None = None,
222+
) -> None: ...
223+
224+
class Identity(Layer[tf.Tensor, tf.Tensor]):
225+
def __init__(
226+
self, trainable: bool = True, dtype: _LayerDtype = None, dynamic: bool = False, name: str | None = None
227+
) -> None: ...
228+
229+
class LayerNormalization(Layer[tf.Tensor, tf.Tensor]):
230+
def __init__(
231+
self,
232+
axis: int = -1,
233+
epsilon: float = 0.001,
234+
center: bool = True,
235+
scale: bool = True,
236+
beta_initializer: _Initializer = "zeros",
237+
gamma_initializer: _Initializer = "ones",
238+
beta_regularizer: _Regularizer = None,
239+
gamma_regularizer: _Regularizer = None,
240+
beta_constraint: _Constraint = None,
241+
gamma_constraint: _Constraint = None,
242+
trainable: bool = True,
243+
dtype: _LayerDtype | None = None,
244+
dynamic: bool = False,
245+
name: str | None = None,
246+
) -> None: ...
247+
248+
class DenseFeatures(Layer[Mapping[str, TensorLike], tf.Tensor]):
249+
def __init__(
250+
self,
251+
feature_columns: Sequence[DenseColumn | SequenceDenseColumn],
252+
trainable: bool = True,
253+
dtype: _LayerDtype = None,
254+
dynamic: bool = False,
255+
name: str | None = None,
256+
) -> None: ...
257+
258+
class MultiHeadAttention(Layer[Any, tf.Tensor]):
259+
def __init__(
260+
self,
261+
num_heads: int,
262+
key_dim: int | None,
263+
value_dim: int | None = None,
264+
dropout: float = 0.0,
265+
use_bias: bool = True,
266+
output_shape: tuple[int, ...] | None = None,
267+
attention_axes: tuple[int, ...] | None = None,
268+
kernel_initialize: _Initializer = "glorot_uniform",
269+
bias_initializer: _Initializer = "zeros",
270+
kernel_regularizer: Regularizer | None = None,
271+
bias_regularizer: _Regularizer | None = None,
272+
activity_regularizer: _Regularizer | None = None,
273+
kernel_constraint: _Constraint | None = None,
274+
bias_constraint: _Constraint | None = None,
275+
trainable: bool = True,
276+
dtype: _LayerDtype | None = None,
277+
dynamic: bool = False,
278+
name: str | None = None,
279+
) -> None: ...
280+
# @override
281+
@overload # type: ignore
282+
def __call__(
283+
self,
284+
query: tf.Tensor,
285+
value: tf.Tensor,
286+
key: tf.Tensor | None,
287+
attention_mask: tf.Tensor | None,
288+
return_attention_scores: Literal[False],
289+
training: bool,
290+
use_causal_mask: bool,
291+
) -> tf.Tensor: ...
292+
@overload
293+
def __call__(
294+
self,
295+
query: tf.Tensor,
296+
value: tf.Tensor,
297+
key: tf.Tensor | None,
298+
attention_mask: tf.Tensor | None,
299+
return_attention_scores: Literal[True],
300+
training: bool,
301+
use_causal_mask: bool,
302+
) -> tuple[tf.Tensor, tf.Tensor]: ...
303+
@overload
304+
def __call__(
305+
self,
306+
query: tf.Tensor,
307+
value: tf.Tensor,
308+
key: tf.Tensor | None = None,
309+
attention_mask: tf.Tensor | None = None,
310+
return_attention_scores: bool = False,
311+
training: bool = False,
312+
use_causal_mask: bool = False,
313+
) -> tuple[tf.Tensor, tf.Tensor] | tf.Tensor: ...
314+
315+
class GaussianDropout(Layer[tf.Tensor, tf.Tensor]):
316+
def __init__(
317+
self,
318+
rate: float,
319+
seed: int | None = None,
320+
trainable: bool = True,
192321
dtype: _LayerDtype = None,
193322
dynamic: bool = False,
194323
name: str | None = None,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import abc
2+
from typing import overload
3+
4+
import tensorflow as tf
5+
from tensorflow._aliases import AnyArray, DataSequence, Float, Integer, TensorCompatible, TensorLike
6+
from tensorflow.keras.layers import Layer
7+
8+
class PreprocessingLayer(Layer[TensorLike, TensorLike], metaclass=abc.ABCMeta):
9+
@property
10+
def is_adapted(self) -> bool: ...
11+
@overload # type: ignore
12+
def __call__(self, inputs: tf.Tensor, *, training: bool = False, mask: TensorCompatible | None = None) -> tf.Tensor: ...
13+
@overload
14+
def __call__(
15+
self, inputs: tf.SparseTensor, *, training: bool = False, mask: TensorCompatible | None = None
16+
) -> tf.SparseTensor: ...
17+
@overload
18+
def __call__(
19+
self, inputs: tf.RaggedTensor, *, training: bool = False, mask: TensorCompatible | None = None
20+
) -> tf.RaggedTensor: ...
21+
def adapt(
22+
self,
23+
data: tf.data.Dataset[TensorLike] | AnyArray | DataSequence,
24+
batch_size: Integer | None = None,
25+
steps: Float | None = None,
26+
) -> None: ...
27+
def compile(self, run_eagerly: bool | None = None, steps_per_execution: Integer | None = None) -> None: ...
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import Literal
2+
3+
from tensorflow._aliases import TensorCompatible
4+
from tensorflow.keras.layers.preprocessing.index_lookup import _IndexLookup
5+
6+
class StringLookup(_IndexLookup):
7+
def __init__(
8+
self,
9+
max_tokens: int | None = None,
10+
num_oov_indices: int = 1,
11+
mask_token: str | None = None,
12+
oov_token: str = "[UNK]",
13+
vocabulary: str | None | TensorCompatible = None,
14+
idf_weights: TensorCompatible | None = None,
15+
encoding: str = "utf-8",
16+
invert: bool = False,
17+
output_mode: Literal["int", "count", "multi_hot", "one_hot", "tf_idf"] = "int",
18+
sparse: bool = False,
19+
pad_to_max_tokens: bool = False,
20+
) -> None: ...
21+
22+
class IntegerLookup(_IndexLookup):
23+
def __init__(
24+
self,
25+
max_tokens: int | None = None,
26+
num_oov_indices: int = 1,
27+
mask_token: int | None = None,
28+
oov_token: int = -1,
29+
vocabulary: str | None | TensorCompatible = None,
30+
vocabulary_dtype: Literal["int64", "int32"] = "int64",
31+
idf_weights: TensorCompatible | None = None,
32+
invert: bool = False,
33+
output_mode: Literal["int", "count", "multi_hot", "one_hot", "tf_idf"] = "int",
34+
sparse: bool = False,
35+
pad_to_max_tokens: bool = False,
36+
) -> None: ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from _typeshed import Incomplete
2+
3+
import tensorflow as tf
4+
from tensorflow.keras.layers.experimental.preprocessing import PreprocessingLayer
5+
6+
class _IndexLookup(PreprocessingLayer):
7+
def compute_output_signature(self, input_spec: Incomplete) -> tf.TensorSpec: ...
8+
def get_vocabulary(self, include_special_tokens: bool = True) -> list[Incomplete]: ...
9+
def vocabulary_size(self) -> int: ...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from _typeshed import Incomplete
2+
3+
from tensorflow.python.trackable.base import Trackable
4+
5+
class _ResourceMetaclass(type): ...
6+
7+
# Internal type that is commonly used as a base class
8+
# it is needed for the public signatures of some APIs.
9+
class CapturableResource(Trackable, metaclass=_ResourceMetaclass): ...
10+
11+
def __getattr__(name: str) -> Incomplete: ...

stubs/tensorflow/tensorflow/saved_model/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SaveOptions:
5757
self,
5858
namespace_whitelist: list[str] | None = None,
5959
save_debug_info: bool = False,
60-
function_aliases: dict[str, tf.types.experimental.GenericFunction[..., object]] | None = None,
60+
function_aliases: Mapping[str, tf.types.experimental.GenericFunction[..., object]] | None = None,
6161
experimental_io_device: str | None = None,
6262
experimental_variable_policy: str | VariablePolicy | None = None,
6363
experimental_custom_gradients: bool = True,

stubs/tensorflow/tensorflow/saved_model/experimental.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing_extensions import Self
44

55
import tensorflow as tf
66
from tensorflow._aliases import Integer, TensorValue
7-
from tensorflow.python.trackable.ressource import CapturableResource
7+
from tensorflow.python.trackable.resource import CapturableResource
88

99
class Fingerprint:
1010
saved_model_checksum: TensorValue | None

0 commit comments

Comments
 (0)
0