@@ -98,6 +98,9 @@ struct SDParams {
9898 std::vector<int > high_noise_skip_layers = {7 , 8 , 9 };
9999 sd_sample_params_t high_noise_sample_params;
100100
101+ std::string easycache_option;
102+ sd_easycache_params_t easycache_params;
103+
101104 float moe_boundary = 0 .875f ;
102105 int video_frames = 1 ;
103106 int fps = 16 ;
@@ -139,6 +142,7 @@ struct SDParams {
139142 sd_sample_params_init (&sample_params);
140143 sd_sample_params_init (&high_noise_sample_params);
141144 high_noise_sample_params.sample_steps = -1 ;
145+ sd_easycache_params_init (&easycache_params);
142146 }
143147};
144148
@@ -208,6 +212,11 @@ void print_params(SDParams params) {
208212 printf (" chroma_use_t5_mask: %s\n " , params.chroma_use_t5_mask ? " true" : " false" );
209213 printf (" chroma_t5_mask_pad: %d\n " , params.chroma_t5_mask_pad );
210214 printf (" video_frames: %d\n " , params.video_frames );
215+ printf (" easycache: %s (threshold=%.3f, start=%.2f, end=%.2f)\n " ,
216+ params.easycache_params .enabled ? " enabled" : " disabled" ,
217+ params.easycache_params .reuse_threshold ,
218+ params.easycache_params .start_percent ,
219+ params.easycache_params .end_percent );
211220 printf (" vace_strength: %.2f\n " , params.vace_strength );
212221 printf (" fps: %d\n " , params.fps );
213222 free (sample_params_str);
@@ -593,6 +602,10 @@ void parse_args(int argc, const char** argv, SDParams& params) {
593602 " --upscale-model" ,
594603 " path to esrgan model." ,
595604 ¶ms.esrgan_path },
605+ {" " ,
606+ " --easycache" ,
607+ " enable EasyCache for DiT models with \" threshold,start_percent,end_percent\" (example: 0.2,0.15,0.95)" ,
608+ ¶ms.easycache_option },
596609 };
597610
598611 options.int_options = {
@@ -1118,6 +1131,59 @@ void parse_args(int argc, const char** argv, SDParams& params) {
11181131 exit (1 );
11191132 }
11201133
1134+ if (!params.easycache_option .empty ()) {
1135+ float values[3 ] = {0 .0f , 0 .0f , 0 .0f };
1136+ std::stringstream ss (params.easycache_option );
1137+ std::string token;
1138+ int idx = 0 ;
1139+ while (std::getline (ss, token, ' ,' )) {
1140+ auto trim = [](std::string& s) {
1141+ const char * whitespace = " \t\r\n " ;
1142+ auto start = s.find_first_not_of (whitespace);
1143+ if (start == std::string::npos) {
1144+ s.clear ();
1145+ return ;
1146+ }
1147+ auto end = s.find_last_not_of (whitespace);
1148+ s = s.substr (start, end - start + 1 );
1149+ };
1150+ trim (token);
1151+ if (token.empty ()) {
1152+ fprintf (stderr, " error: invalid easycache option '%s'\n " , params.easycache_option .c_str ());
1153+ exit (1 );
1154+ }
1155+ if (idx >= 3 ) {
1156+ fprintf (stderr, " error: easycache expects exactly 3 comma-separated values (threshold,start,end)\n " );
1157+ exit (1 );
1158+ }
1159+ try {
1160+ values[idx] = std::stof (token);
1161+ } catch (const std::exception&) {
1162+ fprintf (stderr, " error: invalid easycache value '%s'\n " , token.c_str ());
1163+ exit (1 );
1164+ }
1165+ idx++;
1166+ }
1167+ if (idx != 3 ) {
1168+ fprintf (stderr, " error: easycache expects exactly 3 comma-separated values (threshold,start,end)\n " );
1169+ exit (1 );
1170+ }
1171+ if (values[0 ] < 0 .0f ) {
1172+ fprintf (stderr, " error: easycache threshold must be non-negative\n " );
1173+ exit (1 );
1174+ }
1175+ if (values[1 ] < 0 .0f || values[1 ] >= 1 .0f || values[2 ] <= 0 .0f || values[2 ] > 1 .0f || values[1 ] >= values[2 ]) {
1176+ fprintf (stderr, " error: easycache start/end percents must satisfy 0.0 <= start < end <= 1.0\n " );
1177+ exit (1 );
1178+ }
1179+ params.easycache_params .enabled = true ;
1180+ params.easycache_params .reuse_threshold = values[0 ];
1181+ params.easycache_params .start_percent = values[1 ];
1182+ params.easycache_params .end_percent = values[2 ];
1183+ } else {
1184+ params.easycache_params .enabled = false ;
1185+ }
1186+
11211187 if (params.n_threads <= 0 ) {
11221188 params.n_threads = get_num_physical_cores ();
11231189 }
@@ -1717,6 +1783,7 @@ int main(int argc, const char* argv[]) {
17171783 params.pm_style_strength ,
17181784 }, // pm_params
17191785 params.vae_tiling_params ,
1786+ params.easycache_params ,
17201787 };
17211788
17221789 results = generate_image (sd_ctx, &img_gen_params);
@@ -1739,6 +1806,7 @@ int main(int argc, const char* argv[]) {
17391806 params.seed ,
17401807 params.video_frames ,
17411808 params.vace_strength ,
1809+ params.easycache_params ,
17421810 };
17431811
17441812 results = generate_video (sd_ctx, &vid_gen_params, &num_results);
0 commit comments