-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (82 loc) · 3.27 KB
/
Copy pathmain.py
File metadata and controls
94 lines (82 loc) · 3.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import time
import math
TOTAL_MAX = 4500
ACCEPTABLE_MIN = 3000
def clearscreen():
os.system('cls' if os.name == 'nt' else 'clear')
# Simple input validation
def validate_user_input(prompt):
while True:
user_input = input(prompt)
try:
return int(user_input)
except ValueError:
print(f"Invalid input, please enter a valid value")
# Find the ideal epoch ranges
def calculator(size, repeats, batch, ga):
results = {
"min_estimated_steps": 0,
"max_estimated_steps": 0,
"min_effective_steps": 0,
"max_effective_steps": 0,
"min_recommended_epochs": 0,
"max_recommended_epochs": 0,
}
effective_multiplier = batch * ga
image_count_total = size * repeats
results["min_recommended_epochs"] = int(math.ceil(((ACCEPTABLE_MIN * batch * ga) / image_count_total) / effective_multiplier))
results["max_recommended_epochs"] = int(math.ceil(((TOTAL_MAX * batch * ga) / image_count_total) / effective_multiplier))
results["min_estimated_steps"] = int(image_count_total * results["min_recommended_epochs"])
results["max_estimated_steps"] = int(image_count_total * results["max_recommended_epochs"])
results["min_effective_steps"] = int((image_count_total * results["min_recommended_epochs"]) / effective_multiplier)
results["max_effective_steps"] = int((image_count_total * results["max_recommended_epochs"]) / effective_multiplier)
return results
# Simple TUI-like prompt
def tui():
clearscreen()
print(f"##########################")
print(f"# Kiba's Lora Calculator #")
print(f"##########################")
print(f"\n")
print(f"Free and open pupware(tm)")
print(f"Free to use and modify~!")
time.sleep(1)
# Dataset size
clearscreen()
print("What's the size of your dataset?")
print(f"\n")
setsize = validate_user_input("Dataset size: ")
# Repeat count
clearscreen()
print(f"How many repeats do you want to work with?")
print(f"\n")
imgrepeats = validate_user_input("Repeats: ")
# Batch size
clearscreen()
print(f"What batch size are you working with?")
print(f"\n")
batchsize = validate_user_input("Batch size: ")
# GA steps
clearscreen()
print(f"What GA (Gradient Accumulation) steps are you working with?")
print(f"\n")
gasteps = validate_user_input("GA Steps: ")
# Final result
clearscreen()
finalresults = calculator(setsize, imgrepeats, batchsize, gasteps)
print(f"###################################")
print(f"# Here's your recommended params: #")
print(f"###################################")
print(f"\n")
print(f"Given image set count", setsize)
print(f"Given image repeats:", imgrepeats)
print(f"Given batch size:", batchsize)
print(f"Given GA steps:", gasteps)
print(f"Recommended Max Epoch range:", finalresults["min_recommended_epochs"], "-", finalresults["max_recommended_epochs"])
print(f"Estimated steps range:", finalresults["min_estimated_steps"], "-", finalresults["max_estimated_steps"])
print(f"Effective steps range:", finalresults["min_effective_steps"], "-", finalresults["max_effective_steps"])
def main():
tui()
if __name__ == "__main__":
main()