mirror of
https://github.com/hanzoai/ml.git
synced 2026-11-20 23:08:29 +00:00
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import hanzo
|
|
from hanzo import Tensor
|
|
from hanzo.nn import Linear
|
|
|
|
|
|
def test_linear_layer_can_be_constructed():
|
|
linear = Linear(10, 10)
|
|
assert linear is not None
|
|
|
|
|
|
def test_linear_layer_can_forward_a_singular_input():
|
|
linear = Linear(384, 1536)
|
|
input_tensor = hanzo.randn((8, 384))
|
|
output = linear.forward(input_tensor)
|
|
assert output.shape == (8, 1536)
|
|
|
|
|
|
def test_linear_layer_can_forward_a_batched_input():
|
|
linear = Linear(384, 1536)
|
|
input_tensor = hanzo.randn((16, 8, 384))
|
|
output = linear.forward(input_tensor)
|
|
assert output.shape == (16, 8, 1536)
|
|
|
|
|
|
def test_quantized_linear_layer_can_forward_a_singular_input():
|
|
linear = Linear(384, 1536)
|
|
linear.weight = linear.weight.quantize("q4_0")
|
|
input_tensor = hanzo.randn((8, 384))
|
|
output = linear.forward(input_tensor)
|
|
assert output.shape == (8, 1536)
|
|
|
|
|
|
def test_quantized_linear_layer_can_forward_a_batched_input():
|
|
linear = Linear(384, 1536)
|
|
linear.weight = linear.weight.quantize("q4_0")
|
|
input_tensor = hanzo.randn((16, 8, 384))
|
|
output = linear.forward(input_tensor)
|
|
assert output.shape == (16, 8, 1536)
|