Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update mx.random.normal calls #643

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/mlx/nn/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def normal(
"""

def initializer(a: mx.array) -> mx.array:
return std * mx.random.normal(shape=a.shape, dtype=dtype) + mean
return mx.random.normal(shape=a.shape, scale=std, loc=mean, dtype=dtype)

return initializer

Expand Down Expand Up @@ -184,7 +184,7 @@ def glorot_normal(
def initializer(a: mx.array, gain: float = 1.0) -> mx.array:
fan_in, fan_out = _calculate_fan_in_fan_out(a)
std = gain * math.sqrt(2.0 / (fan_in + fan_out))
return mx.random.normal(shape=a.shape, dtype=dtype) * std
return mx.random.normal(shape=a.shape, scale=std, dtype=dtype)

return initializer

Expand Down Expand Up @@ -285,7 +285,7 @@ def initializer(
raise ValueError(f"Invalid mode: {mode}. Valid modes are: fan_in, fan_out")

std = gain / math.sqrt(fan)
return mx.random.normal(shape=a.shape, dtype=dtype) * std
return mx.random.normal(shape=a.shape, scale=std, dtype=dtype)

return initializer

Expand Down
2 changes: 1 addition & 1 deletion python/mlx/nn/layers/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Embedding(Module):
def __init__(self, num_embeddings: int, dims: int):
super().__init__()
scale = math.sqrt(1 / dims)
self.weight = mx.random.normal((num_embeddings, dims)) * scale
self.weight = mx.random.normal(shape=(num_embeddings, dims), scale=scale)

def _extra_repr(self):
return f"{self.weight.shape[0]}, {self.weight.shape[1]}"
Expand Down