Update handler.py
Browse files- handler.py +7 -6
handler.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
-
from contextlib import nullcontext
|
| 2 |
import time
|
| 3 |
import torch
|
| 4 |
-
from apogee.tokenizer import Tokenizer
|
| 5 |
-
from apogee.model import GPT, ModelConfig
|
| 6 |
|
|
|
|
| 7 |
from typing import Any, Dict, Optional, Union
|
| 8 |
from pathlib import Path
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
torch.backends.cuda.matmul.allow_tf32 = True # allow tf32 on matmul
|
| 11 |
torch.backends.cudnn.allow_tf32 = True # allow tf32 on cudnn
|
| 12 |
|
| 13 |
-
class
|
| 14 |
"""
|
| 15 |
Handler class.
|
| 16 |
"""
|
|
@@ -39,7 +40,7 @@ class ApogeeHandler:
|
|
| 39 |
self.model.eval()
|
| 40 |
self.model.to(self.device)
|
| 41 |
self.model = torch.compile(self.model)
|
| 42 |
-
dtype = 'bfloat16' if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else 'float16' # 'float32' or 'bfloat16' or 'float16'
|
| 43 |
ptdtype = {'float32': torch.float32, 'bfloat16': torch.bfloat16, 'float16': torch.float16}[dtype]
|
| 44 |
self.ctx = nullcontext() if device == 'cpu' else torch.amp.autocast(device_type=device, dtype=ptdtype)
|
| 45 |
print("Warming up hardware 🔥")
|
|
@@ -124,7 +125,7 @@ class ApogeeHandler:
|
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
| 126 |
import pandas as pd
|
| 127 |
-
handler =
|
| 128 |
test_path = Path(__file__).parents[2] / "tests" / "assets" / "BTCUSDT-1m-2019-03.csv"
|
| 129 |
with open(test_path, "r") as f:
|
| 130 |
data = pd.read_csv(f)
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
import torch
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
from contextlib import nullcontext
|
| 5 |
from typing import Any, Dict, Optional, Union
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
+
from apogee.tokenizer import Tokenizer
|
| 9 |
+
from apogee.model import GPT, ModelConfig
|
| 10 |
+
|
| 11 |
torch.backends.cuda.matmul.allow_tf32 = True # allow tf32 on matmul
|
| 12 |
torch.backends.cudnn.allow_tf32 = True # allow tf32 on cudnn
|
| 13 |
|
| 14 |
+
class EndpointHandler:
|
| 15 |
"""
|
| 16 |
Handler class.
|
| 17 |
"""
|
|
|
|
| 40 |
self.model.eval()
|
| 41 |
self.model.to(self.device)
|
| 42 |
self.model = torch.compile(self.model)
|
| 43 |
+
dtype = 'bfloat16' if torch.cuda.is_available() and torch.cuda.is_bf16_supported() and torch.cuda.get_device_capability()[0] >= 8 else 'float16' # 'float32' or 'bfloat16' or 'float16'
|
| 44 |
ptdtype = {'float32': torch.float32, 'bfloat16': torch.bfloat16, 'float16': torch.float16}[dtype]
|
| 45 |
self.ctx = nullcontext() if device == 'cpu' else torch.amp.autocast(device_type=device, dtype=ptdtype)
|
| 46 |
print("Warming up hardware 🔥")
|
|
|
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|
| 127 |
import pandas as pd
|
| 128 |
+
handler = EndpointHandler()
|
| 129 |
test_path = Path(__file__).parents[2] / "tests" / "assets" / "BTCUSDT-1m-2019-03.csv"
|
| 130 |
with open(test_path, "r") as f:
|
| 131 |
data = pd.read_csv(f)
|