Skip to content

Commit

Permalink
[CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye Gomez authored and Kye Gomez committed Sep 1, 2024
1 parent 98d2739 commit 7b742a0
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 131 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,24 +485,24 @@ from zeta.rl import DPO

# Define a simple policy model
class PolicyModel(nn.Module):
def __init__(self, input_dim, output_dim):
def __init__(self, dim, output_dim):
super().__init__()
self.fc = nn.Linear(input_dim, output_dim)
self.fc = nn.Linear(dim, output_dim)

def forward(self, x):
return self.fc(x)


input_dim = 10
dim = 10
output_dim = 5
policy_model = PolicyModel(input_dim, output_dim)
policy_model = PolicyModel(dim, output_dim)

# Initialize DPO with the policy model
dpo_model = DPO(model=policy_model, beta=0.1)

# Sample preferred and unpreferred sequences
preferred_seq = torch.randint(0, output_dim, (3, input_dim))
unpreferred_seq = torch.randint(0, output_dim, (3, input_dim))
preferred_seq = torch.randint(0, output_dim, (3, dim))
unpreferred_seq = torch.randint(0, output_dim, (3, dim))

# Compute loss
loss = dpo_model(preferred_seq, unpreferred_seq)
Expand Down
16 changes: 8 additions & 8 deletions docs/zeta/nn/modules/hebbian.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class BasicHebbianGRUModel(nn.Module):
A basic Hebbian learning model combined with a GRU for text-based tasks.
Parameters:
- input_dim (int): Dimension of the input features.
- dim (int): Dimension of the input features.
- hidden_dim (int): Dimension of the hidden state in the GRU.
- output_dim (int): Dimension of the output features.
"""
```

The `BasicHebbianGRUModel` class has the following attributes and methods:

- `input_dim` (int): Dimension of the input features.
- `dim` (int): Dimension of the input features.
- `hidden_dim` (int): Dimension of the hidden state in the GRU.
- `output_dim` (int): Dimension of the output features.

Expand All @@ -53,10 +53,10 @@ The `BasicHebbianGRUModel` class has the following attributes and methods:
To create an instance of the `BasicHebbianGRUModel`, you need to specify the dimensions of input, hidden state, and output features. Here's how you can initialize the model:

```python
input_dim = 512 # Dimension of the input features
dim = 512 # Dimension of the input features
hidden_dim = 256 # Dimension of the hidden state in the GRU
output_dim = 128 # Dimension of the output features
model = BasicHebbianGRUModel(input_dim, hidden_dim, output_dim)
model = BasicHebbianGRUModel(dim, hidden_dim, output_dim)
```

---
Expand All @@ -73,7 +73,7 @@ The forward pass of the model processes input data through several stages:
Here's how to perform a forward pass:

```python
# Assuming input_tensor is a 3D tensor of shape (B, Seqlen, input_dim)
# Assuming input_tensor is a 3D tensor of shape (B, Seqlen, dim)
output = model(input_tensor)
```

Expand All @@ -84,16 +84,16 @@ output = model(input_tensor)
### Example 1: Model Initialization

```python
input_dim = 512
dim = 512
hidden_dim = 256
output_dim = 128
model = BasicHebbianGRUModel(input_dim, hidden_dim, output_dim)
model = BasicHebbianGRUModel(dim, hidden_dim, output_dim)
```

### Example 2: Forward Pass

```python
# Assuming input_tensor is a 3D tensor of shape (B, Seqlen, input_dim)
# Assuming input_tensor is a 3D tensor of shape (B, Seqlen, dim)
output = model(input_tensor)
```

Expand Down
22 changes: 11 additions & 11 deletions docs/zeta/nn/modules/mmfusionffn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
The `MMFusionFFN` module represents a positionwise feedforward layer and is used in the context of multi-modal image and text processing.

#### Class Definition
- `MMFusionFFN(input_dim, hidden_dim, dropout=0.0)`
- `MMFusionFFN(dim, hidden_dim, dropout=0.0)`

#### Args
| Name | Type | Description | Default |
|--------------|-------|---------------------------------------|-----------|
| input_dim | int | Input dimension | - |
| dim | int | Input dimension | - |
| hidden_dim | int | Hidden dimension | - |
| output_dim | int | Output dimension | - |
| dropout | float | Dropout probability. | 0.1 |
Expand All @@ -32,34 +32,34 @@ from torch import nn
from zeta.nn import MMFusionFFN

# Define the input and hidden dimensions
input_dim = 512
dim = 512
hidden_dim = 1024
output_dim = 512
dropout = 0.1

# Create an instance of MMFusionFFN
ffn = MMFusionFFN(input_dim, hidden_dim, output_dim, dropout)
ffn = MMFusionFFN(dim, hidden_dim, output_dim, dropout)

# Example 1 - Forward pass with random input data
input_data = torch.randn(
5, 32, input_dim
) # Random input data of shape (5, 32, input_dim)
5, 32, dim
) # Random input data of shape (5, 32, dim)
output = ffn(input_data)
print(output.shape) # Output tensor shape

# Example 2 - Create an instance with default dropout
ffn_default_dropout = MMFusionFFN(input_dim, hidden_dim, output_dim)
ffn_default_dropout = MMFusionFFN(dim, hidden_dim, output_dim)

# Example 3 - Forward pass with another input data
input_data2 = torch.randn(
8, 16, input_dim
) # Random input data of shape (8, 16, input_dim)
8, 16, dim
) # Random input data of shape (8, 16, dim)
output2 = ffn_default_dropout(input_data2)
print(output2.shape) # Output tensor shape
```
#### Additional Information and Tips
- The `MMFusionFFN` module is commonly used in multimodal machine learning applications to process multi-dimensional input data from different modalities, such as image and text.
- The most important parameters to consider when creating an instance of `MMFusionFFN` are `input_dim` and `hidden_dim`. These parameters can be adjusted based on the specifics of the input data and the desired level of transformation.
- The most important parameters to consider when creating an instance of `MMFusionFFN` are `dim` and `hidden_dim`. These parameters can be adjusted based on the specifics of the input data and the desired level of transformation.
- The `dropout` parameter controls the probability of an element to be zeroed in the forward pass, which can help prevent overfitting.

#### References and Resources
Expand All @@ -68,4 +68,4 @@ print(output2.shape) # Output tensor shape

This comprehensive documentation provides a detailed overview of the `MMFusionFFN` module, including its purpose, architecture, usage examples, and additional information. Developers can now use this documentation to effectively utilize the module in their applications.

The examples illustrate how to create instances of `MMFusionFFN`, perform forward passes, and handle different input shapes, providing a practical guide for utilizing the module. Additionally, important attributes, such as `input_dim`, `hidden_dim`, and `dropout`, are explained in the class definition table for easy reference and understanding.
The examples illustrate how to create instances of `MMFusionFFN`, perform forward passes, and handle different input shapes, providing a practical guide for utilizing the module. Additionally, important attributes, such as `dim`, `hidden_dim`, and `dropout`, are explained in the class definition table for easy reference and understanding.
20 changes: 10 additions & 10 deletions docs/zeta/nn/modules/postnorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ from zeta.nn import PostNorm

# Define a simple model
class SimpleModel(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
def __init__(self, dim, hidden_dim, output_dim):
super().__init__()

self.hidden_layer = nn.Linear(input_dim, hidden_dim)
self.hidden_layer = nn.Linear(dim, hidden_dim)
self.postnorm_layer = PostNorm(hidden_dim, nn.Linear(hidden_dim, output_dim))

def forward(self, x):
Expand All @@ -41,9 +41,9 @@ class SimpleModel(nn.Module):


# Usage:
input_dim, hidden_dim, output_dim = 10, 20, 2
model = SimpleModel(input_dim, hidden_dim, output_dim)
inputs = torch.randn(64, input_dim)
dim, hidden_dim, output_dim = 10, 20, 2
model = SimpleModel(dim, hidden_dim, output_dim)
inputs = torch.randn(64, dim)
outputs = model(inputs)

print(f"Input Shape: {inputs.shape}\nOutput Shape: {outputs.shape}")
Expand All @@ -60,9 +60,9 @@ from zeta.nn import PostNorm

# Define a model architecture for image data
class ImageModel(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
def __init__(self, dim, hidden_dim, output_dim):
super().__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc1 = nn.Linear(dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, output_dim)
self.postnorm = PostNorm(output_dim, nn.ReLU())

Expand All @@ -73,9 +73,9 @@ class ImageModel(nn.Module):


# Usage:
input_dim, hidden_dim, output_dim = 784, 256, 10 # Applicable for MNIST data
model = ImageModel(input_dim, hidden_dim, output_dim)
inputs = torch.randn(64, input_dim)
dim, hidden_dim, output_dim = 784, 256, 10 # Applicable for MNIST data
model = ImageModel(dim, hidden_dim, output_dim)
inputs = torch.randn(64, dim)
outputs = model(inputs)

print(f"Input Shape: {inputs.shape}\nOutput Shape: {outputs.shape}")
Expand Down
8 changes: 4 additions & 4 deletions docs/zeta/nn/modules/vittransformerblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ Parameters:
import torch
import torch.nn as nn

input_dim = 256
dim = 256
num_heads = 3
dim_head = 64
feedforward_dim = 512
expansion_factor = 3
dropout_rate = 0.1

transformer_block = VitTransformerBlock(
input_dim, num_heads, dim_head, feedforward_dim, expansion_factor, dropout_rate
dim, num_heads, dim_head, feedforward_dim, expansion_factor, dropout_rate
)
input_tensor = torch.randn(
1, 3, 256, 512
) # Batch size of 5, sequence length of 256, input dimension of 256
output = transformer_block(input_tensor)

# Usage example 2:
input_dim = 256
dim = 256
num_heads = 4
dim_head = 64
feedforward_dim = 512
expansion_factor = 3
dropout_rate = 0.1
transformer_block = VitTransformerBlock(
input_dim, num_heads, dim_head, feedforward_dim, expansion_factor, dropout_rate
dim, num_heads, dim_head, feedforward_dim, expansion_factor, dropout_rate
)
input_tensor = torch.randn(
1, 4, 64, 256
Expand Down
8 changes: 4 additions & 4 deletions docs/zeta/rl/dpo.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ from zeta.rl import DPO

# Define a simple policy model
class PolicyModel(nn.Module):
def __init__(self, input_dim, output_dim):
def __init__(self, dim, output_dim):
super().__init__()
self.fc = nn.Linear(input_dim, output_dim)
self.fc = nn.Linear(dim, output_dim)

def forward(self, x):
return self.fc(x)


input_dim = 10
dim = 10
output_dim = 5
policy_model = PolicyModel(input_dim, output_dim)
policy_model = PolicyModel(dim, output_dim)

# Initialize DPO with the policy model
dpo_model = DPO(model=policy_model, beta=0.1)
Expand Down
4 changes: 2 additions & 2 deletions docs/zeta/utils/save_load.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ from zeta.utils import save_load
@save_load()
class MyModel(Module):

def __init__(self, input_dim, output_dim):
def __init__(self, dim, output_dim):
super().__init__()
self.layer = Linear(input_dim, output_dim)
self.layer = Linear(dim, output_dim)

def forward(self, x):
return self.layer(x)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zetascale"
version = "2.7.0"
version = "2.7.1"
description = "Rapidly Build, Optimize, and Train SOTA AI Models"
authors = ["Zeta Team <[email protected]>"]
license = "MIT"
Expand Down
8 changes: 4 additions & 4 deletions tests/nn/attentions/test_xc_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def test_xc_attention_with_different_heads():
)


def test_xc_attention_with_different_input_dims():
def test_xc_attention_with_different_dims():
"""Test case to check if XCAttention handles different input dimensions correctly."""
input_dims = [128, 256, 512]
dims = [128, 256, 512]

for dim in input_dims:
for dim in dims:
model = XCAttention(dim=dim, cond_dim=64, heads=8)
assert isinstance(model, XCAttention)
assert model.to_qkv[0].in_features == dim
Expand All @@ -81,7 +81,7 @@ def test_xc_attention_with_different_cond_dims():
assert model.film[0].in_features == cond_dim * 2


def test_xc_attention_negative_input_dim():
def test_xc_attention_negative_dim():
"""Test case to check if XCAttention handles negative input dimensions correctly."""
with pytest.raises(ValueError):
XCAttention(dim=-256, cond_dim=64, heads=8)
Expand Down
4 changes: 2 additions & 2 deletions tests/nn/embeddings/test_patch_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_embedding_layers():


# Test case for different input dimensions
def test_different_input_dimensions():
def test_different_dimensions():
dim_in = 3
dim_out = 4
seq_len = 5
Expand All @@ -63,7 +63,7 @@ def test_different_input_dimensions():


# Test case for large input dimensions
def test_large_input_dimensions():
def test_large_dimensions():
dim_in = 256
dim_out = 512
seq_len = 16
Expand Down
8 changes: 4 additions & 4 deletions tests/nn/modules/test_alr_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ def test_alrblock_forward(sample_input, alrblock_model):

# Parameterized testing for various input dimensions and dropout rates
@pytest.mark.parametrize(
"input_dim, hidden_dim, dropout",
"dim, hidden_dim, dropout",
[
(256, 1024, 0.2),
(512, 2048, 0.0),
(128, 512, 0.3),
],
)
def test_feedforward_parameterized(input_dim, hidden_dim, dropout):
model = FeedForward(input_dim, hidden_dim, dropout)
input_tensor = torch.randn(1, 1024, input_dim)
def test_feedforward_parameterized(dim, hidden_dim, dropout):
model = FeedForward(dim, hidden_dim, dropout)
input_tensor = torch.randn(1, 1024, dim)
output = model(input_tensor)
assert output.shape == input_tensor.shape

Expand Down
Loading

0 comments on commit 7b742a0

Please sign in to comment.