Typing the dropout. (#1479)

This commit is contained in:
LastWhisper 2024-10-15 21:45:46 +08:00 committed by GitHub
parent 0ab8e099e8
commit 2b8ace6a03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,10 +23,10 @@ class Dropout(Module):
self._p_1 = 1 - p
def _extra_repr(self):
def _extra_repr(self) -> str:
return f"p={1-self._p_1}"
def __call__(self, x):
def __call__(self, x: mx.array) -> mx.array:
if self._p_1 == 1 or not self.training:
return x
@ -66,10 +66,10 @@ class Dropout2d(Module):
self._p_1 = 1 - p
def _extra_repr(self):
def _extra_repr(self) -> str:
return f"p={1-self._p_1}"
def __call__(self, x):
def __call__(self, x: mx.array) -> mx.array:
if x.ndim not in (3, 4):
raise ValueError(
f"Received input with {x.ndim} dimensions. Expected 3 or 4 dimensions."
@ -115,10 +115,10 @@ class Dropout3d(Module):
self._p_1 = 1 - p
def _extra_repr(self):
def _extra_repr(self) -> str:
return f"p={1-self._p_1}"
def __call__(self, x):
def __call__(self, x: mx.array) -> mx.array:
if x.ndim not in (4, 5):
raise ValueError(
f"Received input with {x.ndim} dimensions. Expected 4 or 5 dimensions."