@@ -4,7 +4,6 @@ package txt2img
4
4
5
5
import (
6
6
"math"
7
- "time"
8
7
"unsafe"
9
8
)
10
9
@@ -14,82 +13,19 @@ type ggmlTensor struct {
14
13
}
15
14
16
15
var (
17
- n_threads = 4
18
- diffusion_model = & DiffusionModel {}
16
+ nThreads = 4
19
17
)
20
18
21
- func ggmlTimeMs () int64 {
22
- return time .Now ().UnixNano () / int64 (time .Millisecond )
23
- }
24
-
25
- func vectorToGgmlTensorI32 (workCtx unsafe.Pointer , vec []int ) * ggmlTensor {
26
- panic ("fix me" )
27
- return & ggmlTensor {}
28
- }
29
-
30
- func ggmlDupTensor (workCtx unsafe.Pointer , tensor * ggmlTensor ) * ggmlTensor {
31
- panic ("fix me" )
32
- return & ggmlTensor {}
33
- }
34
-
35
- func ggmlTensorMean (tensor * ggmlTensor ) float32 {
36
- panic ("fix me" )
37
- return 0.0
38
- }
39
-
40
- func ggmlTensorGetF32 (tensor * ggmlTensor , i0 , i1 , i2 int ) float32 {
41
- panic ("fix me" )
42
- return 0.0
43
- }
44
-
45
- func ggmlTensorSetF32 (tensor * ggmlTensor , value float32 , i0 , i1 , i2 int ) {
46
- panic ("fix me" )
47
- }
48
-
49
- func ggmlTensorScale (tensor * ggmlTensor , scale float32 ) {
50
- panic ("fix me" )
51
- }
52
-
53
- func ggmlNelements (tensor * ggmlTensor ) int {
54
- panic ("fix me" )
55
- return 0
56
- }
57
-
58
- func vectorToGgmlTensor (workCtx unsafe.Pointer , vec []float32 ) * ggmlTensor {
59
- panic ("fix me" )
60
- return & ggmlTensor {}
61
- }
62
-
63
- func ggmlReshape2D (workCtx unsafe.Pointer , tensor * ggmlTensor , dim0 , dim1 int ) * ggmlTensor {
64
- panic ("fix me" )
65
- return & ggmlTensor {}
66
- }
67
-
68
- func ggmlNewTensor1D (workCtx unsafe.Pointer , tensorType int , size int ) * ggmlTensor {
69
- panic ("fix me" )
70
- return & ggmlTensor {}
71
- }
72
-
73
- func ggmlView2D (workCtx unsafe.Pointer , tensor * ggmlTensor , dim0 , dim1 , stride , offset int ) * ggmlTensor {
74
- panic ("fix me" )
75
- return & ggmlTensor {}
76
- }
77
-
78
- func ggmlNbytes (tensor * ggmlTensor ) int {
79
- panic ("fix me" )
80
- return 0
81
- }
82
-
83
19
func setTimestepEmbedding (timesteps []float32 , embedView * ggmlTensor , outDim int ) {
84
20
panic ("fix me" )
85
21
}
86
22
87
- func getLearnedCondition ( workCtx unsafe.Pointer , text string , clipSkip , width , height int , forceZeroEmbeddings bool ) (* ggmlTensor , * ggmlTensor ) {
88
- tokens , weights := tokenize ( text , true )
89
- return getLearnedConditionCommon (workCtx , tokens , weights , clipSkip , width , height , forceZeroEmbeddings )
23
+ func ( gen * Generator ) GetLearnedCondition ( workCtx unsafe.Pointer , prompt string , clipSkip , width , height int , forceZeroEmbeddings bool ) (unsafe. Pointer , unsafe. Pointer ) {
24
+ tokens , weights := gen . Tokenize ( prompt , true )
25
+ return gen . getLearnedConditionCommon (workCtx , tokens , weights , clipSkip , width , height , forceZeroEmbeddings )
90
26
}
91
27
92
- func getLearnedConditionCommon (workCtx unsafe.Pointer , tokens []int , weights []float32 , clipSkip , width , height int , forceZeroEmbeddings bool ) (* ggmlTensor , * ggmlTensor ) {
28
+ func ( gen * Generator ) getLearnedConditionCommon (workCtx unsafe.Pointer , tokens []int , weights []float32 , clipSkip , width , height int , forceZeroEmbeddings bool ) (unsafe. Pointer , unsafe. Pointer ) {
93
29
cond_stage_model .setClipSkip (clipSkip )
94
30
var hiddenStates , chunkHiddenStates , pooled * ggmlTensor
95
31
var hiddenStatesVec []float32
@@ -100,7 +36,7 @@ func getLearnedConditionCommon(workCtx unsafe.Pointer, tokens []int, weights []f
100
36
chunkTokens := tokens [chunkIdx * chunkLen : (chunkIdx + 1 )* chunkLen ]
101
37
chunkWeights := weights [chunkIdx * chunkLen : (chunkIdx + 1 )* chunkLen ]
102
38
103
- inputIds := vectorToGgmlTensorI32 (workCtx , chunkTokens )
39
+ inputIds := gen . GGML . VectorToGgmlTensorI32 (workCtx , chunkTokens )
104
40
var inputIds2 * ggmlTensor
105
41
var maxTokenIdx int
106
42
// if version == VERSION_XL {
@@ -119,9 +55,9 @@ func getLearnedConditionCommon(workCtx unsafe.Pointer, tokens []int, weights []f
119
55
inputIds2 = vectorToGgmlTensorI32 (workCtx , chunkTokens )
120
56
// }
121
57
122
- cond_stage_model .compute (n_threads , inputIds , inputIds2 , maxTokenIdx , false , & chunkHiddenStates , workCtx )
58
+ cond_stage_model .compute (nThreads , inputIds , inputIds2 , maxTokenIdx , false , & chunkHiddenStates , workCtx )
123
59
if chunkIdx == 0 {
124
- cond_stage_model .compute (n_threads , inputIds , inputIds2 , maxTokenIdx , true , & pooled , workCtx )
60
+ cond_stage_model .compute (nThreads , inputIds , inputIds2 , maxTokenIdx , true , & pooled , workCtx )
125
61
}
126
62
127
63
result := ggmlDupTensor (workCtx , chunkHiddenStates )
0 commit comments