Kernels
drbh commited on
Commit
3a9af28
·
1 Parent(s): a4c5425

feat: add gelu example

Browse files
Files changed (2) hide show
  1. README.md +8 -1
  2. tests/simple_test.py +15 -3
README.md CHANGED
@@ -7,4 +7,11 @@ tags:
7
 
8
  This kernel is a work in progress and requires more work to correctly add all of the FlashInfer kernels.
9
 
10
- Please see the [generate-source.md](generate-source.md) for instructions on how to generate the source files that are contained in this kernel.
 
 
 
 
 
 
 
 
7
 
8
  This kernel is a work in progress and requires more work to correctly add all of the FlashInfer kernels.
9
 
10
+ Please see the [generate-source.md](generate-source.md) for instructions on how to generate the source files that are contained in this kernel.
11
+
12
+
13
+ ### Run `gelu_and_mul` operation
14
+
15
+ ```bash
16
+ nix develop -L .#test --command python tests/simple_test.py
17
+ ```
tests/simple_test.py CHANGED
@@ -1,9 +1,21 @@
1
  import torch
2
  import flashinfer
3
 
4
- out = torch.empty(3, 3, dtype=torch.float16).cuda()
5
- input_tensor = torch.randn(3, 3, dtype=torch.float16).cuda()
 
 
 
 
6
  enable_pdl = True
7
 
 
 
 
 
 
 
 
8
  flashinfer.gelu_and_mul(out, input_tensor, enable_pdl)
9
- print(out)
 
 
1
  import torch
2
  import flashinfer
3
 
4
+ torch.manual_seed(42)
5
+
6
+ batch_size = 128
7
+ hidden_dim = 4096
8
+ out = torch.empty(batch_size, hidden_dim // 2, dtype=torch.float16)
9
+ input_tensor = torch.randn(batch_size, hidden_dim, dtype=torch.float16)
10
  enable_pdl = True
11
 
12
+ # make sure the output tensor is on the GPU if available
13
+ if torch.cuda.is_available():
14
+ out = out.cuda()
15
+ input_tensor = input_tensor.cuda()
16
+ else:
17
+ raise RuntimeError("CUDA is not available. Please run this on a GPU.")
18
+
19
  flashinfer.gelu_and_mul(out, input_tensor, enable_pdl)
20
+ print("GELU and multiply operation completed. Output shape:", out.shape)
21
+ print("Output tensor sample:", out[:, :5]) # Show first 5 elements