forked from SALT-NLP/chain-of-thought-bias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_flan_handler.py
40 lines (30 loc) · 884 Bytes
/
00_flan_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import atexit
from multiprocessing import Lock
from multiprocessing.managers import BaseManager
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
import argparse
print("LOADING FLAN")
parser = argparse.ArgumentParser()
parser.add_argument('--model', default="flan-t5-xxl")
args = parser.parse_args()
model = args.model
flan_model = T5ForConditionalGeneration.from_pretrained(
f"google/{model}",
device_map="auto",
cache_dir="/nlp/scr/oshaikh/flan-cache",
torch_dtype=torch.bfloat16
)
print("FLAN LOADED")
def get_connection():
return flan_model
def get_name():
return model
@atexit.register
def close_connections():
return
manager = BaseManager(('', 37844), b'flanserver')
manager.register('get_connection', get_connection)
manager.register('get_name', get_name)
server = manager.get_server()
server.serve_forever()