🌐 AI搜索 & 代理 主页
Skip to content

Commit d7b5f0e

Browse files
committed
fix Fn/Bn handling
1 parent 77dd25a commit d7b5f0e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

cache_dit.hpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ struct CacheDitState {
527527
std::string get_summary() const {
528528
char buf[256];
529529
snprintf(buf, sizeof(buf),
530-
"CacheDIT[Fn=%d,Bn=%d,thresh=%.2f]: cached %zu/%d steps, %d/%d blocks",
531-
get_double_Fn_blocks(), get_double_Bn_blocks(),
530+
"CacheDIT[thresh=%.2f]: cached %zu/%d steps, %d/%d blocks",
532531
config.dbcache.residual_diff_threshold,
533532
cached_steps.size(), total_steps,
534533
total_blocks_cached, total_blocks_computed + total_blocks_cached);
@@ -636,6 +635,19 @@ inline int get_preset_warmup(const std::string& preset) {
636635
return 8;
637636
}
638637

638+
inline int get_preset_Fn(const std::string& preset) {
639+
if (preset == "slow" || preset == "s" || preset == "S") return 8;
640+
if (preset == "medium" || preset == "m" || preset == "M") return 8;
641+
if (preset == "fast" || preset == "f" || preset == "F") return 6;
642+
if (preset == "ultra" || preset == "u" || preset == "U") return 4;
643+
return 8;
644+
}
645+
646+
inline int get_preset_Bn(const std::string& preset) {
647+
(void)preset;
648+
return 0;
649+
}
650+
639651
inline void parse_dbcache_options(const std::string& opts, DBCacheConfig& cfg) {
640652
if (opts.empty()) return;
641653

@@ -858,7 +870,19 @@ struct CacheDitConditionState {
858870
float diff = CacheDitState::calculate_residual_diff(
859871
it->second.prev_input.data(), input_data, ne);
860872

861-
if (diff < config.residual_diff_threshold) {
873+
float effective_threshold = config.residual_diff_threshold;
874+
if (config.Fn_compute_blocks > 0) {
875+
float fn_confidence = 1.0f + 0.02f * (config.Fn_compute_blocks - 8);
876+
fn_confidence = std::max(0.5f, std::min(2.0f, fn_confidence));
877+
effective_threshold *= fn_confidence;
878+
}
879+
if (config.Bn_compute_blocks > 0) {
880+
float bn_quality = 1.0f - 0.03f * config.Bn_compute_blocks;
881+
bn_quality = std::max(0.5f, std::min(1.0f, bn_quality));
882+
effective_threshold *= bn_quality;
883+
}
884+
885+
if (diff < effective_threshold) {
862886
skip_current_step = true;
863887
total_steps_skipped++;
864888
cached_steps.push_back(current_step_index);

examples/cli/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,8 @@ struct SDGenerationParams {
17021702
cache_params.mode == SD_CACHE_CACHE_DIT) {
17031703

17041704
if (!cache_preset.empty()) {
1705+
cache_params.Fn_compute_blocks = get_preset_Fn(cache_preset);
1706+
cache_params.Bn_compute_blocks = get_preset_Bn(cache_preset);
17051707
cache_params.residual_diff_threshold = get_preset_threshold(cache_preset);
17061708
cache_params.max_warmup_steps = get_preset_warmup(cache_preset);
17071709

0 commit comments

Comments
 (0)