Skip to content

Commit c78f576

Browse files
committed
Fix memory management and offload dirs
1 parent f006d5f commit c78f576

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

ModelForge/utilities/chat_playground.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, model_path: str):
3939
self.device = "cuda" if torch.cuda.is_available() else "cpu"
4040
if self.device == "cpu":
4141
print("CUDA is not available. Exiting...")
42+
input("\nPress Enter to exit...")
4243
exit(1)
4344

4445
print("Loading model...")
@@ -52,7 +53,15 @@ def __init__(self, model_path: str):
5253
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
5354
tokenizer.pad_token = tokenizer.eos_token
5455
module = getattr(peft, self.modelforge_config["model_class"])
55-
peft_model = module.from_pretrained(model_path, config=config, is_trainable=False)
56+
peft_model = module.from_pretrained(
57+
model_path,
58+
config=config,
59+
is_trainable=False,
60+
low_cpu_mem_usage=True,
61+
device_map="auto",
62+
torch_dtype="auto",
63+
offload_folder=os.path.join(model_path, "offload")
64+
)
5665
self.generator = pipeline(
5766
self.modelforge_config["pipeline_task"],
5867
streamer=streamer,
@@ -61,12 +70,15 @@ def __init__(self, model_path: str):
6170
)
6271
except AttributeError:
6372
print(f"Model class {self.modelforge_config['model_class']} not found in peft module.")
73+
input("\nPress Enter to exit...")
6474
exit(1)
6575
except KeyError:
6676
print(f"Pipeline task {self.modelforge_config['pipeline_task']} not found in definitions for the pipeline object of transformers.")
77+
input("\nPress Enter to exit...")
6778
exit(1)
6879
except Exception as e:
6980
print(traceback.format_exc())
81+
input("\nPress Enter to exit...")
7082
exit(1)
7183

7284
def generate_response(self, prompt: str, context=None, temperature=0.2, top_p=0.92, top_k=50,

0 commit comments

Comments
 (0)