From 22d139bff78ec0bff465b5107569b753900a2f49 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 12 May 2025 01:30:37 +0200 Subject: [PATCH] Allow changing context size. --- profiler/src/profiler/TracyLlm.cpp | 17 +++++++++++++++-- profiler/src/profiler/TracyLlm.hpp | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index 1cbf7d25..1b43b1cc 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -122,7 +122,10 @@ void TracyLlm::Draw() m_cv.notify_all(); } - if( ImGui::BeginCombo( "Model##model", m_models[m_modelIdx].name.c_str() ) ) + ImGui::AlignTextToFramePadding(); + TextDisabledUnformatted( "Model:" ); + ImGui::SameLine(); + if( ImGui::BeginCombo( "##model", m_models[m_modelIdx].name.c_str() ) ) { for( size_t i = 0; i < m_models.size(); ++i ) { @@ -139,6 +142,16 @@ void TracyLlm::Draw() ImGui::EndCombo(); } + ImGui::AlignTextToFramePadding(); + TextDisabledUnformatted( "Context size:" ); + ImGui::SameLine(); + ImGui::SetNextItemWidth( 80 * scale ); + if( ImGui::InputInt( "##contextSize", &m_ctxPercent ) ) { m_ctxPercent = std::clamp( m_ctxPercent, 1, 100 ); } + ImGui::SameLine(); + ImGui::TextUnformatted( "%" ); + ImGui::SameLine(); + ImGui::TextDisabled( "(%s)", RealToString( m_models[m_modelIdx].ctxSize * m_ctxPercent / 100 ) ); + ImGui::Spacing(); ImGui::BeginChild( "##ollama", ImVec2( 0, -( ImGui::GetFrameHeight() + ImGui::GetStyle().ItemSpacing.y * 2 ) ), ImGuiChildFlags_Borders ); if( m_chat->empty() ) @@ -317,7 +330,7 @@ void TracyLlm::UpdateModels() void TracyLlm::SendMessage( ollama::messages&& messages ) { ollama::options options; - options["num_ctx"] = m_models[m_modelIdx].ctxSize; + options["num_ctx"] = m_models[m_modelIdx].ctxSize * m_ctxPercent / 100; // The chat() call will fire a callback right away, so the assistant message needs to be there already m_chat->emplace_back( ollama::message( "assistant", "" ) ); diff --git a/profiler/src/profiler/TracyLlm.hpp b/profiler/src/profiler/TracyLlm.hpp index e73e69ca..6ea12fe1 100644 --- a/profiler/src/profiler/TracyLlm.hpp +++ b/profiler/src/profiler/TracyLlm.hpp @@ -76,7 +76,7 @@ private: std::vector m_models; size_t m_modelIdx; - size_t m_ctxSize; + int m_ctxPercent = 100; std::atomic m_exit; std::condition_variable m_cv;