Spaces:
Sleeping
Sleeping
joshua400 commited on
Commit ยท
2521148
1
Parent(s): 74e0a5e
๐ OPTIMIZE: Model loading hardware-aware logic and eval mode
Browse files- inference.py +3 -1
inference.py
CHANGED
|
@@ -101,7 +101,9 @@ class TrainedInferencePolicy:
|
|
| 101 |
import torch
|
| 102 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 103 |
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
|
| 106 |
def __call__(self, obs: FairRecoveryObservation) -> FairRecoveryAction:
|
| 107 |
if obs.day > 10: return FairRecoveryAction(action_type=ActionType.SUBMIT)
|
|
|
|
| 101 |
import torch
|
| 102 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 103 |
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 104 |
+
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 105 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=dtype, device_map="auto")
|
| 106 |
+
self.model.eval()
|
| 107 |
|
| 108 |
def __call__(self, obs: FairRecoveryObservation) -> FairRecoveryAction:
|
| 109 |
if obs.day > 10: return FairRecoveryAction(action_type=ActionType.SUBMIT)
|