| 245 | } |
| 246 | |
| 247 | int64_t cache_graph_capacity(int64_t required_capacity, int64_t model_capacity) { |
| 248 | if (required_capacity <= 0) { |
| 249 | throw std::runtime_error("VibeVoice decoder cache capacity must be positive"); |
| 250 | } |
| 251 | if (model_capacity > 0 && required_capacity > model_capacity) { |
| 252 | throw std::runtime_error("VibeVoice decoder cache requirement exceeds model position capacity"); |
| 253 | } |
| 254 | int64_t capacity = required_capacity; |
| 255 | if (required_capacity < kScratchTailCachedAttentionMinSteps) { |
| 256 | capacity = 1; |
| 257 | while (capacity < required_capacity) { |
| 258 | if (capacity > std::numeric_limits<int64_t>::max() / 2) { |
| 259 | throw std::runtime_error("VibeVoice decoder cache capacity overflow"); |
| 260 | } |
| 261 | capacity *= 2; |
| 262 | } |
| 263 | } else { |
| 264 | capacity = ((required_capacity + kLargeCacheGrowthStep - 1) / kLargeCacheGrowthStep) * |
| 265 | kLargeCacheGrowthStep; |
| 266 | } |
| 267 | return model_capacity > 0 ? std::min(capacity, model_capacity) : capacity; |
| 268 | } |
| 269 | |
| 270 | runtime::TransformerKVState empty_decoder_state(size_t layers) { |
| 271 | runtime::TransformerKVState state; |
no test coverage detected