Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ScaleAdd.py 759 B

You have to be logged in to leave a comment. Sign In
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
  1. from core.leras import nn
  2. tf = nn.tf
  3. class ScaleAdd(nn.LayerBase):
  4. def __init__(self, ch, dtype=None, **kwargs):
  5. if dtype is None:
  6. dtype = nn.floatx
  7. self.dtype = dtype
  8. self.ch = ch
  9. super().__init__(**kwargs)
  10. def build_weights(self):
  11. self.weight = tf.get_variable("weight",(self.ch,), dtype=self.dtype, initializer=tf.initializers.zeros() )
  12. def get_weights(self):
  13. return [self.weight]
  14. def forward(self, inputs):
  15. if nn.data_format == "NHWC":
  16. shape = (1,1,1,self.ch)
  17. else:
  18. shape = (1,self.ch,1,1)
  19. weight = tf.reshape ( self.weight, shape )
  20. x0, x1 = inputs
  21. x = x0 + x1*weight
  22. return x
  23. nn.ScaleAdd = ScaleAdd
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...