-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathfree_vram_hack.py
More file actions
76 lines (65 loc) · 2.32 KB
/
free_vram_hack.py
File metadata and controls
76 lines (65 loc) · 2.32 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import torch
import gc
import requests
import json
class Everything(str):
def __ne__(self, __value: object) -> bool:
return False
class FreeVRAM:
@classmethod
def INPUT_TYPES(s):
return {"required": {"anything": (Everything("*"),)}}
RETURN_TYPES = (Everything("*"),)
RETURN_NAME = ("anything",)
FUNCTION = "free_vram"
CATEGORY = "Bjornulf"
def free_vram(self, anything):
print("Attempting to free VRAM...")
# Clear CUDA cache
if torch.cuda.is_available():
torch.cuda.empty_cache()
print("CUDA cache cleared.")
# Run garbage collection
collected = gc.collect()
print(f"Garbage collector: collected {collected} objects.")
# Trigger the HTTP request
self.trigger_http_request()
# Return the input image unchanged
return (anything,)
def trigger_http_request(self):
url = "http://localhost:8188/prompt"
headers = {"Content-Type": "application/json"}
payload = {
"prompt": {
"3": {
"inputs": {"text": "free VRAM hack"},
"class_type": "Bjornulf_WriteText",
"_meta": {"title": "✒ Write Text"}
},
"4": {
"inputs": {"text_value": ["3", 0], "text": "free VRAM hack"},
"class_type": "Bjornulf_ShowText",
"_meta": {"title": "👁 Show (Text)"}
}
}
}
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
response.raise_for_status()
print("HTTP request triggered successfully")
except requests.exceptions.RequestException as e:
print(f"Failed to trigger HTTP request: {e}")
class PurgeCLIPNode:
@classmethod
def INPUT_TYPES(cls):
return {"required": {}}
RETURN_TYPES = ()
FUNCTION = "purge_clip"
CATEGORY = "utils"
def purge_clip(self):
# Check if the CLIP model is accessible in the global scope
global clip_model
if 'clip_model' in globals():
del clip_model # Delete the CLIP model reference
torch.cuda.empty_cache() # Clear VRAM cache
return ()