mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-24 09:21:16 +08:00
Typing the dropout. (#1479)
This commit is contained in:
parent
0ab8e099e8
commit
2b8ace6a03
@ -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."
|
||||
|
Loading…
Reference in New Issue
Block a user