Skip to content

Commit e085cb4

Browse files
committed
Small changes
1 parent 83cb20a commit e085cb4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

modules/models.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import numpy as np
88
import torch
99
import transformers
10-
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, AutoConfig
11-
from accelerate import infer_auto_device_map, init_empty_weights, load_checkpoint_and_dispatch
10+
from accelerate import infer_auto_device_map, init_empty_weights
11+
from transformers import (AutoConfig, AutoModelForCausalLM, AutoTokenizer,
12+
BitsAndBytesConfig)
1213

1314
import modules.shared as shared
1415

@@ -113,23 +114,20 @@ def load_model(model_name):
113114

114115
if shared.args.gpu_memory:
115116
memory_map = shared.args.gpu_memory
116-
max_memory = { 0: f'{memory_map[0]}GiB' }
117-
for i in range(1, len(memory_map)):
117+
max_memory = {}
118+
for i in range(len(memory_map)):
118119
max_memory[i] = f'{memory_map[i]}GiB'
119120
max_memory['cpu'] = f'{shared.args.cpu_memory or 99}GiB'
120121
params['max_memory'] = max_memory
121122
else:
122-
total_mem = (torch.cuda.get_device_properties(0).total_memory / (1024 * 1024))
123-
suggestion = round((total_mem - 1000) / 1000) * 1000
123+
total_mem = (torch.cuda.get_device_properties(0).total_memory / (1024*1024))
124+
suggestion = round((total_mem-1000) / 1000) * 1000
124125
if total_mem - suggestion < 800:
125126
suggestion -= 1000
126127
suggestion = int(round(suggestion/1000))
127128
print(f"\033[1;32;1mAuto-assiging --gpu-memory {suggestion} for your GPU to try to prevent out-of-memory errors.\nYou can manually set other values.\033[0;37;0m")
128129

129-
max_memory = {
130-
0: f'{suggestion}GiB',
131-
'cpu': f'{shared.args.cpu_memory or 99}GiB'
132-
}
130+
max_memory = {0: f'{suggestion}GiB', 'cpu': f'{shared.args.cpu_memory or 99}GiB'}
133131
params['max_memory'] = max_memory
134132

135133
if shared.args.disk:

0 commit comments

Comments
 (0)