TorchAO Testing commited on
Commit
8dba8c9
·
verified ·
1 Parent(s): 8c29207

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```
2
+ import torch
3
+ import io
4
+
5
+ model = torch.nn.Sequential(torch.nn.Linear(32, 256, dtype=torch.bfloat16, device="cuda"))
6
+
7
+ from torchao.quantization import quantize_, Float8DynamicActivationFloat8WeightConfig, PerRow
8
+ quant_config = Float8DynamicActivationFloat8WeightConfig(granularity=PerRow(), version=1)
9
+ quantize_(model, quant_config)
10
+ example_inputs = (torch.randn(2, 32, dtype=torch.bfloat16, device="cuda"),)
11
+ output = model(*example_inputs)
12
+
13
+ # Push to hub
14
+ USER_ID = "torchao-testing"
15
+ MODEL_NAME = "single-linear"
16
+ save_to = f"{USER_ID}/{MODEL_NAME}-Float8DynamicActivationFloat8WeightConfig-v1-0.13-dev"
17
+
18
+ from huggingface_hub import HfApi
19
+ api = HfApi()
20
+
21
+ buf = io.BytesIO()
22
+ torch.save(model.state_dict(), buf)
23
+ api.create_repo(save_to, repo_type="model", exist_ok=True)
24
+ api.upload_file(
25
+ path_or_fileobj=buf,
26
+ path_in_repo="model.bin",
27
+ repo_id=save_to,
28
+ )
29
+
30
+ buf = io.BytesIO()
31
+ torch.save(example_inputs, buf)
32
+ api.upload_file(
33
+ path_or_fileobj=buf,
34
+ path_in_repo="model_inputs.pt",
35
+ repo_id=save_to,
36
+ )
37
+
38
+ buf = io.BytesIO()
39
+ torch.save(output, buf)
40
+ api.upload_file(
41
+ path_or_fileobj=buf,
42
+ path_in_repo="model_output.pt",
43
+ repo_id=save_to,
44
+ )
45
+ ```