-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
from .linear import Linear, LinearBitKernel, quantize, de_quantize | ||
from .linear import ( | ||
Linear as Linear, | ||
LinearBitKernel as LinearBitKernel, | ||
quantize as quantize, | ||
de_quantize as de_quantize, | ||
quantize_params as quantize_params, | ||
de_quantize_params as de_quantize_params, | ||
Conv as Conv, | ||
Embed as Embed, | ||
promote_dtype as promote_dtype | ||
) | ||
|
||
__all__ = ( | ||
"Linear", | ||
"LinearBitKernel", | ||
"quantize", | ||
"de_quantize", | ||
"quantize_params", | ||
"de_quantize_params", | ||
"Conv", | ||
"Embed", | ||
"promote_dtype" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import jax.random | ||
from jax import numpy as jnp | ||
import src.fjformer.linen as nn | ||
from src.fjformer import GenerateRNG | ||
|
||
|
||
def main(): | ||
rng_gen = GenerateRNG(42) | ||
neuron = nn.Linear( | ||
4, | ||
use_bias=True | ||
) | ||
|
||
params = neuron.init( | ||
rng_gen.rng, | ||
jax.random.normal(rng_gen.rng, (1, 68, 4)) | ||
) | ||
|
||
quantized_params = nn.quantize_params(params) | ||
|
||
inputs = jax.random.normal(rng_gen.rng, (1, 1, 4)) | ||
|
||
org_pred = neuron.apply(params, inputs) | ||
qun_pred = neuron.apply(quantized_params, inputs) | ||
print(jnp.allclose(org_pred, qun_pred, rtol=1e-2, atol=1e-8)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |