From 542134bf501f201f38f6ff1d3e4ea8385a1baf5e Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Tue, 9 Jul 2024 16:52:47 -0700 Subject: [PATCH] new --- llm/llm.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/llm/llm.go b/llm/llm.go index f964a6540..a8b78ad5a 100644 --- a/llm/llm.go +++ b/llm/llm.go @@ -49,17 +49,26 @@ func Quantize(infile, outfile string, ftype fileType, fn func(resp api.ProgressR params.quantize_callback_data = store params.quantize_callback = (C.llama_progress_callback)(C.update_quantize_progress) - go func () { + ticker := time.NewTicker(60 * time.Millisecond) + done := make(chan struct{}) + defer close(done) + + go func() { + defer ticker.Stop() for { - time.Sleep(60 * time.Millisecond) - if params.quantize_callback_data == nil { - return - } else { + select { + case <-ticker.C: progress := *((*C.float)(store)) fn(api.ProgressResponse{ Status: fmt.Sprintf("quantizing model %d%%", int(progress*100)), Quantize: "quant", + }) + case <-done: + fn(api.ProgressResponse{ + Status: "quantizing model", + Quantize: "quant", }) + return } } }()