You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-1Lines changed: 46 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,51 @@ FlagGems can be installed either as a pure Python package or as a package with C
98
98
99
99
For a quick start with installing and using flag_gems, please refer to the documentation [GetStart](docs/get_start_with_flaggems.md).
100
100
101
+
## Usage
102
+
103
+
FlagGems supports two common usage patterns: patching PyTorch ATen ops (recommended) and calling FlagGems ops explicitly.
104
+
105
+
### (1) Enable FlagGems globally (patch ATen ops)
106
+
107
+
After `flag_gems.enable()`, supported `torch.*` / `torch.nn.functional.*` calls will be dispatched to FlagGems implementations automatically.
108
+
109
+
```python
110
+
import torch
111
+
import flag_gems
112
+
113
+
flag_gems.enable()
114
+
115
+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
116
+
y = torch.mm(x, x)
117
+
```
118
+
119
+
If you only want FlagGems inside a scope (e.g., for benchmarking), use the context manager:
120
+
121
+
```python
122
+
import torch
123
+
import flag_gems
124
+
125
+
with flag_gems.use_gems():
126
+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
127
+
y = torch.mm(x, x)
128
+
```
129
+
130
+
### (2) Explicitly call FlagGems ops
131
+
132
+
You can also bypass PyTorch dispatch and call operators from `flag_gems.ops` directly (no `enable()` required):
133
+
134
+
```python
135
+
import torch
136
+
from flag_gems import ops
137
+
import flag_gems
138
+
139
+
a = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
140
+
b = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
141
+
c = ops.mm(a, b)
142
+
```
143
+
144
+
For more details and advanced options (disabling specific ops, runtime logging,e.g.), see [`how_to_use_flaggems`](docs/how_to_use_flaggems.md).
145
+
101
146
## Supported Operators
102
147
103
148
Operators will be implemented according to [OperatorList](docs/operator_list.md).
@@ -128,7 +173,7 @@ Operators will be implemented according to [OperatorList](docs/operator_list.md)
128
173
129
174
The following chart shows the speedup of FlagGems compared with PyTorch ATen library in eager mode. The speedup is calculated by averaging the speedup on each shape, representing the overall performance of the operator.
0 commit comments