Spaces:
Runtime error
Runtime error
Alberto Carmona
commited on
Commit
·
5bf8ab4
1
Parent(s):
76427ba
Change the device of the tokenizer's output
Browse files- functions.py +5 -2
functions.py
CHANGED
@@ -29,6 +29,7 @@ def summarize_text(text: str):
|
|
29 |
print(['summarize_text', 'start'])
|
30 |
input_text = f'<s>Instruction: Elabora un resume del siguiente texto.\nInput: {text}\nOutput: '
|
31 |
batch = tokenizer(input_text, return_tensors='pt')
|
|
|
32 |
print(['summarize_text', 'generating'])
|
33 |
with torch.cuda.amp.autocast():
|
34 |
output_tokens = model.generate(**batch,
|
@@ -45,8 +46,10 @@ def load_model(peft_model_id):
|
|
45 |
print(['load_model', 'start'])
|
46 |
config = PeftConfig.from_pretrained(peft_model_id)
|
47 |
print(['load_model', 'loading model'])
|
48 |
-
model = AutoModelForCausalLM.from_pretrained(
|
49 |
-
|
|
|
|
|
50 |
print(['load_model', 'loading tokenizer'])
|
51 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
52 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
|
|
29 |
print(['summarize_text', 'start'])
|
30 |
input_text = f'<s>Instruction: Elabora un resume del siguiente texto.\nInput: {text}\nOutput: '
|
31 |
batch = tokenizer(input_text, return_tensors='pt')
|
32 |
+
batch = batch.to('cuda')
|
33 |
print(['summarize_text', 'generating'])
|
34 |
with torch.cuda.amp.autocast():
|
35 |
output_tokens = model.generate(**batch,
|
|
|
46 |
print(['load_model', 'start'])
|
47 |
config = PeftConfig.from_pretrained(peft_model_id)
|
48 |
print(['load_model', 'loading model'])
|
49 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path,
|
50 |
+
return_dict=True,
|
51 |
+
load_in_8bit=True,
|
52 |
+
device_map='auto')
|
53 |
print(['load_model', 'loading tokenizer'])
|
54 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
55 |
model = PeftModel.from_pretrained(model, peft_model_id)
|