mirror of
https://github.com/huggingface/kernels.git
synced 2025-10-20 20:56:31 +08:00
Merge pull request #3 from huggingface/improve_readme
Improving README.
This commit is contained in:
14
README.md
14
README.md
@ -8,12 +8,14 @@ import torch
|
||||
from kernels import get_kernel
|
||||
|
||||
# Download optimized kernels from the Hugging Face hub
|
||||
layer_norm_kernels = get_kernel("kernels-community/layer-norm")
|
||||
activation = get_kernel("kernels-community/activation")
|
||||
|
||||
# Initialize torch Module
|
||||
optimized_layer_norm_layer = layer_norm_kernels.DropoutAddLayerNorm(128).cuda()
|
||||
# Random tensor
|
||||
x = torch.randn((10, 10), dtype=torch.float16, device="cuda")
|
||||
|
||||
# Forward
|
||||
x = torch.randn(128).cuda()
|
||||
print(optimized_layer_norm_layer(x))
|
||||
# Run the kernel
|
||||
y = torch.empty_like(x)
|
||||
activation.gelu_fast(y, x)
|
||||
|
||||
print(y)
|
||||
```
|
||||
|
Reference in New Issue
Block a user