MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / fold_weight_norm_dim0

Function fold_weight_norm_dim0

src/models/stable_audio/same_autoencoder.cpp:88–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86std::vector<float> squeeze_weight_g(std::vector<float> values, int64_t out_channels, const std::string & prefix) {
87 if (static_cast<int64_t>(values.size()) != out_channels) {
88 throw std::runtime_error("Stable Audio SAME weight_g shape mismatch: " + prefix);
89 }
90 return values;
91}
92
93std::vector<float> fold_weight_norm_dim0(
94 const std::vector<float> & weight_v,
95 const std::vector<float> & weight_g,
96 int64_t out_channels,
97 int64_t in_channels,
98 int64_t kernel,
99 const std::string & prefix) {
100 const int64_t inner = in_channels * kernel;
101 if (static_cast<int64_t>(weight_v.size()) != out_channels * inner ||
102 static_cast<int64_t>(weight_g.size()) != out_channels) {
103 throw std::runtime_error("Stable Audio SAME weight_norm tensor shape mismatch: " + prefix);
104 }
105 std::vector<float> out(weight_v.size(), 0.0F);
106 for (int64_t row = 0; row < out_channels; ++row) {
107 const size_t base = static_cast<size_t>(row * inner);
108 double sum = 0.0;
109 for (int64_t i = 0; i < inner; ++i) {
110 const float value = weight_v[base + static_cast<size_t>(i)];
111 sum += static_cast<double>(value) * static_cast<double>(value);
112 }
113 const float scale = static_cast<float>(static_cast<double>(weight_g[static_cast<size_t>(row)]) / std::sqrt(sum));
114 for (int64_t i = 0; i < inner; ++i) {
115 out[base + static_cast<size_t>(i)] = weight_v[base + static_cast<size_t>(i)] * scale;
116 }
117 }

Callers 1

load_weight_norm_conv1dFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected