| 1178 | assets::TensorStorageType weight_storage_type) { |
| 1179 | if (!weights) { |
| 1180 | weights = std::make_unique<StableAudioSameWeights>(load_stable_audio_same_weights( |
| 1181 | *assets, |
| 1182 | execution.backend(), |
| 1183 | execution.backend_type(), |
| 1184 | 0, |
| 1185 | weight_storage_type)); |
| 1186 | } |
| 1187 | return *weights; |
| 1188 | } |
| 1189 | |
| 1190 | void StableAudioSameRuntime::prepare_decode(int64_t batch, int64_t latent_tokens, bool chunked) const { |
| 1191 | const auto & weights = require_same_weights(weights_, *execution_, assets_, weight_storage_type_); |
| 1192 | const int64_t graph_latents = decoder_graph_latents(assets_->config, latent_tokens, chunked); |
| 1193 | if (!graph_ || !graph_->matches(batch, graph_latents)) { |
| 1194 | graph_ = std::make_unique<Graph>(*execution_, assets_, weights, batch, graph_latents, weight_storage_type_); |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | std::vector<runtime::AudioBuffer> StableAudioSameRuntime::decode( |
| 1199 | const std::vector<float> & latents, |
| 1200 | int64_t batch, |
| 1201 | int64_t latent_tokens, |
| 1202 | uint64_t seed, |
| 1203 | uint64_t & rng_offset_blocks, |
| 1204 | bool chunked) const { |
| 1205 | const auto & config = assets_->config; |
| 1206 | if (static_cast<int64_t>(latents.size()) != batch * config.latent_dim * latent_tokens) { |
| 1207 | throw std::runtime_error("Stable Audio SAME decode latent shape mismatch"); |
| 1208 | } |
| 1209 | const int64_t graph_latents = decoder_graph_latents(config, latent_tokens, chunked); |
| 1210 | prepare_decode(batch, latent_tokens, chunked); |
| 1211 | std::vector<int64_t> starts; |
| 1212 | if (!chunked || latent_tokens <= kSameChunkLatents) { |
| 1213 | starts.push_back(0); |
| 1214 | } else { |
| 1215 | const int64_t hop = kSameChunkLatents - kSameChunkOverlap; |
| 1216 | for (int64_t start = 0; start <= latent_tokens - kSameChunkLatents; start += hop) { |
| 1217 | starts.push_back(start); |
| 1218 | } |
| 1219 | const int64_t final_start = latent_tokens - kSameChunkLatents; |
| 1220 | if (starts.empty() || starts.back() != final_start) { |
| 1221 | starts.push_back(final_start); |
| 1222 | } |
| 1223 | } |
| 1224 | const int64_t frames_per_chunk = graph_latents * config.downsampling_ratio; |
| 1225 | const int64_t total_frames = latent_tokens * config.downsampling_ratio; |
| 1226 | std::vector<float> channel_major(static_cast<size_t>(batch * config.audio_channels * total_frames), 0.0F); |
| 1227 | std::vector<float> chunk_latent(static_cast<size_t>(batch * config.latent_dim * graph_latents), 0.0F); |
| 1228 | std::vector<float> bottleneck_noise(static_cast<size_t>(batch * config.latent_dim * graph_latents), 0.0F); |
| 1229 | std::vector<float> bottleneck_noise_source; |
| 1230 | std::vector<float> token_noise; |
| 1231 | double chunk_latent_ms = 0.0; |
| 1232 | double bottleneck_noise_ms = 0.0; |
| 1233 | double token_noise_ms = 0.0; |
| 1234 | double input_upload_ms = 0.0; |
| 1235 | double graph_compute_ms = 0.0; |
| 1236 | double output_read_ms = 0.0; |
| 1237 | double output_pack_ms = 0.0; |
no test coverage detected