| 906 | if (noise_file.empty()) { |
| 907 | return gaussian_noise(count, seed); |
| 908 | } |
| 909 | auto values = io::read_f32_file(noise_file); |
| 910 | if (values.size() != count) { |
| 911 | throw std::runtime_error( |
| 912 | "ACE-Step diffusion noise file size mismatch: expected " + |
| 913 | std::to_string(count) + " floats, got " + std::to_string(values.size())); |
| 914 | } |
| 915 | return values; |
| 916 | } |
| 917 | |
| 918 | struct NoiseSchedule { |
| 919 | std::vector<float> initial_noise; |
| 920 | std::vector<std::vector<float>> renoise_noises; |
| 921 | }; |
| 922 | |
| 923 | NoiseSchedule load_noise_schedule_or_sample(const std::string & noise_file, size_t count, uint32_t seed) { |
| 924 | NoiseSchedule schedule; |
| 925 | if (noise_file.empty()) { |
| 926 | schedule.initial_noise = gaussian_noise(count, seed); |
| 927 | return schedule; |
| 928 | } |
| 929 | auto values = io::read_f32_file(noise_file); |
| 930 | if (values.empty() || values.size() % count != 0) { |
| 931 | throw std::runtime_error( |
| 932 | "ACE-Step diffusion noise file size mismatch: expected a positive multiple of " + |
| 933 | std::to_string(count) + " floats, got " + std::to_string(values.size())); |
| 934 | } |
| 935 | const size_t chunks = values.size() / count; |
| 936 | schedule.initial_noise.assign(values.begin(), values.begin() + static_cast<std::ptrdiff_t>(count)); |
| 937 | schedule.renoise_noises.reserve(chunks > 0 ? chunks - 1 : 0); |
| 938 | for (size_t chunk = 1; chunk < chunks; ++chunk) { |
| 939 | const auto begin = values.begin() + static_cast<std::ptrdiff_t>(chunk * count); |
| 940 | schedule.renoise_noises.emplace_back(begin, begin + static_cast<std::ptrdiff_t>(count)); |
| 941 | } |
| 942 | return schedule; |
| 943 | } |
| 944 | |
| 945 | } // namespace |
| 946 | |
| 947 | class AceStepDiffusionRuntime::Impl { |
| 948 | public: |
| 949 | class CrossAttentionCacheGraph { |
| 950 | public: |
| 951 | CrossAttentionCacheGraph( |
| 952 | std::shared_ptr<const AceStepAssets> assets, |
no test coverage detected