-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add INT8 mixed-precision training (#748)
* initial commit * expose some UX. update test * add test. update bench * update test. add doc * fix ngpu * fix FSDP * fix * fix fsdp test * fix * grammar * simplify fsdp test * update benchmark script * update * make claim more conservative * register fused adam * update benchmark script * add more ops * update default * use TorchAOBaseTensor * fix fsdp param_dtype * fix param_dtype * dtype check to prevent unnecessary errors * move checks * add note * fix * simplify script * add module-based UX * fix * use FP8 impl of __torch_dispatch__ * rename _dynamice interface * update test * fix compile on 2.4 * log torch version * make log interval customizable * make naming for explicit * update readme * some change * fix big bug * add docstring. update _get_linear_inserter * add TorchAOBaseTensor back * fix FSDP * update FSDP test. add autocast support * reduce iter * update int8_mm fallback * put leading dims logic to _dynamic_int8_mm
- Loading branch information
1 parent
10d038f
commit 3f7fc14
Showing
9 changed files
with
771 additions
and
175 deletions.
There are no files selected for viewing
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,45 @@ | ||
import pandas as pd | ||
import torch | ||
from triton.testing import do_bench | ||
|
||
from torchao.prototype.quantized_training.int8_mm import int8_mm_dequant | ||
|
||
|
||
def bench_f(f, *args): | ||
return do_bench(lambda: f(*args), fast_flush=False, return_mode="median") | ||
|
||
|
||
shapes = [(sz, sz, sz) for sz in [1024, 2048, 4096]] | ||
|
||
# Llama-8B shapes | ||
shapes += [ | ||
# linear in attention | ||
(32_768, 4096, 4096), | ||
(4096, 4096, 32_768), | ||
# linear in feed-forward | ||
(32_768, 14_336, 4096), | ||
(32_768, 4096, 14_336), | ||
(14_336, 4096, 32_768), | ||
] | ||
|
||
data = [] | ||
for M, N, K in shapes: | ||
print(f"{M=}, {N=}, {K=}") | ||
|
||
A_bf16 = torch.randn(M, K).bfloat16().cuda() | ||
B_bf16 = torch.randn(N, K).bfloat16().cuda() | ||
A_i8 = torch.randint(-128, 127, size=(M, K), dtype=torch.int8).cuda() | ||
B_i8 = torch.randint(-128, 127, size=(N, K), dtype=torch.int8).cuda() | ||
A_scale = torch.randn(M).bfloat16().cuda() | ||
B_scale = torch.randn(N).bfloat16().cuda() | ||
|
||
# benchmark F.linear() i.e. A @ B.T | ||
bf16_time = bench_f(torch.mm, A_bf16, B_bf16.T) | ||
i8_time = bench_f(torch._int_mm, A_i8, B_i8.T) | ||
i8_dequant_time = bench_f(int8_mm_dequant, A_i8, B_i8.T, A_scale, B_scale) | ||
|
||
sample = [M, N, K, bf16_time / i8_time, bf16_time / i8_dequant_time] | ||
data.append(sample) | ||
|
||
df = pd.DataFrame(data, columns=["M", "N", "K", "CuBLAS INT8 speedup", "Triton INT8 dequant speedup"]) | ||
print(df.to_markdown()) |
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
Oops, something went wrong.