-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodel_equation_aio_regression.py
105 lines (91 loc) · 1.24 KB
/
model_equation_aio_regression.py
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
from sklearn.linear_model import LinearRegression
import numpy as np
print('-'*50 + "Fitting extend" + '-'*50)
# Fit a linear regression model to attention part of prompt calculation
# Example dataset
query_tokens = [
1,
16,
64,
128,
256,
512,
1024,
2048,
4096,
8192,
14166,
28232,
256,
256,
512,
1024,
1024,
512,
512,
512,
4096,
]
ctx_lens = [
8192,
8192,
8192,
8192,
8192,
8192,
8192,
8192,
8192,
8192,
14166,
28232,
4096,
8192,
4096,
4096,
8192,
8192,
16384,
32768,
4096,
]
ops = [q * c for q, c in zip(query_tokens, ctx_lens)]
X = [[q, c, o] for q, c, o in zip(query_tokens, ctx_lens, ops)]
y = [
56.57,
56.6,
66.4,
63.72,
67.42,
80.15,
122.98,
191.95,
357.6,
771.88,
1338.21,
2942.76,
52.29,
65.74,
66.37,
106.91,
121.27,
81.9,
106.89,
158.81,
368.25,
]
# Create a linear regression model
model = LinearRegression()
# Fit the model
model.fit(X, y)
# Print the coefficients and intercept
print("multi query attention Coefficients:", model.coef_)
print("multi query attention Intercept:", model.intercept_)
# Calculate and print the R2 value
r2_score = model.score(X, y)
print("multi query attention R2 value:", r2_score)
new_query = 8192
new_ctx = 8192
p = model.predict([[new_query, new_ctx, new_query * new_ctx]])
# p = model.predict(X)
print(p)