-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
137 lines (113 loc) · 3.85 KB
/
calculator.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class TransformerFLOPs {
constructor(throughput=null, parameters=null, tokens=null, time=null, num_chips=null, utilization=null, cost_per_flop=null) {
if(parameters){
this.parameters = parseFloat(parameters);
}
if(tokens){
this.tokens = parseFloat(tokens);
}
if(!utilization){
this.utilization = 0.3;
}
else{
this.utilization = utilization;
}
if (throughput) {
this.throughput = throughput * this.utilization;
}
// if statement to check if cost_per_flop is null
if(cost_per_flop === null){
this.cost_per_flop = 1;
}
else{
this.cost_per_flop = cost_per_flop;
}
this.num_chips = num_chips;
this.time = time;
}
//need to add solutions to eq thaat are not reliant on compute var
compute() {
return 6 * this.parameters * this.tokens;
}
computeTime() {
return this.compute() / (this.num_chips * this.throughput);
}
computeParameters() {
return this.compute() / 6 / this.tokens;
}
computeTokens() {
return this.compute() / 6 / this.parameters;
}
computeChips() {
return this.compute() / (this.time * this.throughput);
}
///"User inputs the cost per flop, defaults to $1?"
cost() {
return this.gpu_cost * this.compute();
}
//calculates as many variables as it can
calculateMissingVariable() {
if (!this.time) {
this.time = this.computeTime();
}
if (!this.num_chips) {
this.num_chips = this.computeChips();
}
if (!this.parameters) {
this.parameters = this.computeParameters();
}
if (!this.tokens) {
this.tokens = this.computeTokens();
}
// Need to check this math..
if(!this.throughput){
this.throughput = this.throughput;
}
if(!this.utilization){
this.utilization = this.throughput / this.compute();
}
if (!this.cost) {
this.cost = this.cost();
}
}
prettyTime(seconds) {
let result = '';
const year = 31536000;
const month = 2628000;
const day = 86400;
const hour = 3600;
const minute = 60;
if (seconds >= year) {
const numberOfYears = Math.floor(seconds / year);
result += `${numberOfYears} year${numberOfYears !== 1 ? 's' : ''} `;
seconds = seconds % year;
}
if (seconds >= month) {
const numberOfMonths = Math.floor(seconds / month);
result += `${numberOfMonths} month${numberOfMonths !== 1 ? 's' : ''} `;
seconds = seconds % month;
}
if (seconds >= day) {
const numberOfDays = Math.floor(seconds / day);
result += `${numberOfDays} day${numberOfDays !== 1 ? 's' : ''} `;
seconds = seconds % day;
}
if (seconds >= hour) {
const numberOfHours = Math.floor(seconds / hour);
result += `${numberOfHours} hour${numberOfHours !== 1 ? 's' : ''} `;
seconds = seconds % hour;
}
if (seconds >= minute) {
const numberOfMinutes = Math.floor(seconds / minute);
result += `${numberOfMinutes} minute${numberOfMinutes !== 1 ? 's' : ''} `;
seconds = seconds % minute;
}
if (seconds > 0) {
// add seconds with at most 1 decimal place
seconds = Math.round(seconds * 10) / 10;
result += `${seconds} second${seconds !== 1 ? 's' : ''} `;
}
this.pretty_time = result.trim();
return result.trim();
}
}