From a7fc352669cfca14365b698b5d25e4b6f54dc7a8 Mon Sep 17 00:00:00 2001 From: ZaneNi Date: Tue, 17 Feb 2026 13:56:08 -0500 Subject: [PATCH 1/4] feat: image resize for qwen2/3 vl --- src/common/AutoModel/modeling_qwen3vl.cpp | 6 ++- .../AutoModel/modeling_qwen3vl_image.cpp | 37 +++++++++++++++++-- src/include/AutoModel/automodel.hpp | 3 +- src/include/AutoModel/modeling_qwen3vl.hpp | 5 ++- src/include/utils/vm_args.hpp | 5 +++ src/server/rest_handler.cpp | 5 ++- src/server/rest_handler.hpp | 3 +- src/server/server.cpp | 4 +- src/src/main.cpp | 5 ++- 9 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/common/AutoModel/modeling_qwen3vl.cpp b/src/common/AutoModel/modeling_qwen3vl.cpp index e098d36f..57d2c554 100644 --- a/src/common/AutoModel/modeling_qwen3vl.cpp +++ b/src/common/AutoModel/modeling_qwen3vl.cpp @@ -13,6 +13,10 @@ /************ Qwen3VL family **************/ Qwen3VL::Qwen3VL(xrt::device* npu_device_inst) : AutoModel(npu_device_inst, "Qwen3VL") {} +void Qwen3VL::set_special_flags(int resize) { + this->resize = resize; +} + void Qwen3VL::load_model(std::string model_path, json model_info, int default_context_length, bool enable_preemption) { this->_shared_load_model(model_path, model_info, default_context_length, enable_preemption); @@ -122,7 +126,7 @@ bool Qwen3VL::insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input) { total_images++; } qwen3vl_image_t image = this->load_image_base64(img_str); - preprocess_image(image, image_payload._data__processed); + preprocess_image(image, image_payload._data__processed, resize); image_payload.images.push_back(image); image_payload.num_images++; } diff --git a/src/common/AutoModel/modeling_qwen3vl_image.cpp b/src/common/AutoModel/modeling_qwen3vl_image.cpp index c7cdf86f..d3b4590a 100644 --- a/src/common/AutoModel/modeling_qwen3vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen3vl_image.cpp @@ -508,21 +508,50 @@ void Qwen3VL::smart_resize( ///@note: Converts uint8 image to BF16 format, data is already in (3, H, W) CHW layout ///@param: image: the image to preprocess (already in CHW format) ///@return: the preprocessed image in BF16 format -void Qwen3VL::preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values) { +void Qwen3VL::preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values, int resize) { const int width = image.width; const int height = image.height; const int channels = 3; // RGB int resized_height; - int resized_width; + int resized_width; + int aresized_height; + int aresized_width; + + std::cout << "height "<< height << " width " << width <(height * scale); + int raw_new_w = static_cast(width * scale); + + // CRITICAL: Align to QWEN3_PATCH_SIZE. + // If we don't align, (resized_h / patch_size) will truncate, losing data. + // We round to the nearest multiple of the patch size. + aresized_height = ((raw_new_h + QWEN3_PATCH_SIZE / 2) / QWEN3_PATCH_SIZE) * QWEN3_PATCH_SIZE; + aresized_width = ((raw_new_w + QWEN3_PATCH_SIZE / 2) / QWEN3_PATCH_SIZE) * QWEN3_PATCH_SIZE; + + // Ensure we explicitly enforce the minimum size (1 patch) to avoid 0 dimension + aresized_height = std::max(resized_height, (int)QWEN3_PATCH_SIZE); + aresized_width = std::max(resized_width, (int)QWEN3_PATCH_SIZE); + + } + // do the automatically resizing in here smart_resize( - height, width, + aresized_height, aresized_width, resized_height, resized_width, QWEN3_PATCH_SIZE * QWEN3_IMAGE_MERGE_SIZE, QWEN3_SHORTEST_EDGE, QWEN3_LONGEST_EDGE ); - // std::cout << "resized_height "<< resized_height << " resized_width " << resized_width < is_cancelled = [] { return false; }) = 0; virtual chat_template_type_t get_chat_template_type() { diff --git a/src/include/AutoModel/modeling_qwen3vl.hpp b/src/include/AutoModel/modeling_qwen3vl.hpp index 22fc5049..4f0f33c8 100644 --- a/src/include/AutoModel/modeling_qwen3vl.hpp +++ b/src/include/AutoModel/modeling_qwen3vl.hpp @@ -48,6 +48,8 @@ class Qwen3VL : public AutoModel { int debug_count= 0; + int resize = -1; + void smart_resize( int height, int width, int& h_bar,int& w_bar, @@ -55,11 +57,12 @@ class Qwen3VL : public AutoModel { int min_pixels, int max_pixels); - void preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values); + void preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values, int resize = -1); public: Qwen3VL(xrt::device* npu_device_inst); + void set_special_flags(int resize) override; void load_model(std::string model_path, json model_inf, int default_context_length = -1, bool enable_preemption = false) override; //void toggle_enable_think() override; bool insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input) override; diff --git a/src/include/utils/vm_args.hpp b/src/include/utils/vm_args.hpp index 22ff4e78..05ba20f9 100644 --- a/src/include/utils/vm_args.hpp +++ b/src/include/utils/vm_args.hpp @@ -28,6 +28,7 @@ struct ParsedArgs { bool quiet_list; bool preemption; int ctx_length; + int resize; size_t max_socket_connections; size_t max_npu_queue; int port; @@ -70,6 +71,8 @@ bool parse_options(int argc, char *argv[], ParsedArgs& parsed_args) { ("quiet", "Hide emojis in the model list (can be used with --filter)") ("ctx-len,c", po::value(&parsed_args.ctx_length)->default_value(-1), "Set context length") + ("resize,r", po::value(&parsed_args.resize)->default_value(-1), + "Pre-resize the image") ("socket,s", po::value(&parsed_args.max_socket_connections)->default_value(10), "Set the maximum number of socket connections allowed (for serve command)") ("q-len,q", po::value(&parsed_args.max_npu_queue)->default_value(10), @@ -132,6 +135,7 @@ bool parse_options(int argc, char *argv[], ParsedArgs& parsed_args) { std::cout << " " << argv[0] << " serve llama3.2:1b --cors 0" << std::endl; std::cout << " " << argv[0] << " serve llama3.2:1b --asr 1" << std::endl; std::cout << " " << argv[0] << " serve llama3.2:1b --embed 1" << std::endl; + std::cout << " " << argv[0] << " serve qwen3vl-it:4b --resize 0" << std::endl; std::cout << " " << argv[0] << " list" << std::endl; std::cout << " " << argv[0] << " list --quiet" << std::endl; std::cout << " " << argv[0] << " list --filter installed" << std::endl; @@ -176,6 +180,7 @@ bool parse_options(int argc, char *argv[], ParsedArgs& parsed_args) { std::cout << " " << argv[0] << " serve llama3.2:1b --cors 0" << std::endl; std::cout << " " << argv[0] << " serve llama3.2:1b --asr 1" << std::endl; std::cout << " " << argv[0] << " serve llama3.2:1b --embed 1" << std::endl; + std::cout << " " << argv[0] << " serve qwen3vl-it:4b --resize 0" << std::endl; std::cout << " " << argv[0] << " list" << std::endl; std::cout << " " << argv[0] << " list --quiet" << std::endl; std::cout << " " << argv[0] << " list --filter installed" << std::endl; diff --git a/src/server/rest_handler.cpp b/src/server/rest_handler.cpp index adc37ea5..49d63b7c 100644 --- a/src/server/rest_handler.cpp +++ b/src/server/rest_handler.cpp @@ -146,8 +146,8 @@ static json normalize_template(json messages) { ///@param downloader the downloader ///@param default_tag the default tag ///@return the rest handler -RestHandler::RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length, bool preemption) - : supported_models(models), downloader(downloader), default_model_tag(default_tag), current_model_tag(""), asr(asr), embed(embed), preemption(preemption){ +RestHandler::RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length, int resize, bool preemption) + : supported_models(models), downloader(downloader), default_model_tag(default_tag), current_model_tag(""), asr(asr), embed(embed), resize(resize), preemption(preemption){ this->npu_device_inst = xrt::device(0); if (ctx_length != -1) { @@ -207,6 +207,7 @@ void RestHandler::ensure_model_loaded(const std::string& model_tag) { downloader.pull_model(ensure_tag); } auto [new_ensure_tag, model_info] = supported_models.get_model_info(ensure_tag); + auto_chat_engine->set_special_flags(resize); auto_chat_engine->load_model(supported_models.get_model_path(new_ensure_tag), model_info, ctx_length, preemption); current_model_tag = ensure_tag; } diff --git a/src/server/rest_handler.hpp b/src/server/rest_handler.hpp index 0b212d5a..3fffdef6 100644 --- a/src/server/rest_handler.hpp +++ b/src/server/rest_handler.hpp @@ -31,7 +31,7 @@ using StreamResponseCallback = std::function; // data, class RestHandler { public: - RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length = -1, bool preemption = false); + RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length = -1, int resize = -1, bool preemption = false); ~RestHandler(); void handle_show(const json& request, @@ -127,6 +127,7 @@ class RestHandler { int generate_context_id; int chat_context_id; int ctx_length; + int resize; std::string last_question; bool preemption; PromptCache prompt_cache; diff --git a/src/server/server.cpp b/src/server/server.cpp index 8b3f5e07..6cda9601 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -741,9 +741,9 @@ bool WebServer::handle_request(http::request& req, ///@param default_tag the default tag ///@param port the port ///@return the server -std::unique_ptr create_lm_server(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, std::string host, int port, int ctx_length, bool cors, bool preemption) { +std::unique_ptr create_lm_server(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, std::string host, int port, int ctx_length, int resize, bool cors, bool preemption) { auto server = std::make_unique(host, port, cors); - auto rest_handler = std::make_shared(models, downloader, default_tag, asr, embed, ctx_length); + auto rest_handler = std::make_shared(models, downloader, default_tag, asr, embed, ctx_length, resize); // Register Ollama-compatible routes server->register_handler("POST", "/api/show", diff --git a/src/src/main.cpp b/src/src/main.cpp index f061a5a5..91e7f949 100644 --- a/src/src/main.cpp +++ b/src/src/main.cpp @@ -146,7 +146,7 @@ void handle_user_input() { ///@param default_tag the default tag ///@param port the port to listen on, default is 52625, same with the ollama server ///@return the server -std::unique_ptr create_lm_server(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, std::string host, int port, int ctx_length, bool cors, bool preemption); +std::unique_ptr create_lm_server(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, std::string host, int port, int ctx_length, int resize, bool cors, bool preemption); ///@brief get_server_port gets the server port from environment variable FLM_SERVE_PORT @@ -264,6 +264,7 @@ int main(int argc, char* argv[]) { std::string power_mode = parsed_args.power_mode; bool got_power_mode = (power_mode != "performance"); // Check if user explicitly set power mode int ctx_length = parsed_args.ctx_length; + int resize = parsed_args.resize; bool preemption = parsed_args.preemption; size_t max_socket_connections = parsed_args.max_socket_connections; size_t max_npu_queue = parsed_args.max_npu_queue; @@ -339,7 +340,7 @@ int main(int argc, char* argv[]) { check_and_notify_new_version(); // Create the server int port = utils::get_server_port(user_port); - auto server = create_lm_server(availble_models, downloader, tag, asr, embed, user_host, port, ctx_length, cors, preemption); + auto server = create_lm_server(availble_models, downloader, tag, asr, embed, user_host, port, ctx_length, resize, cors, preemption); server->set_max_connections(max_socket_connections); // Allow up to 10 concurrent connections server->set_io_threads(10); // Allow up to 5 io threads server->set_npu_queue_length(max_npu_queue); // Allow up to 10 concurrent queue From 687758741dcb5253415918449c262b8a9037129a Mon Sep 17 00:00:00 2001 From: ZaneNi Date: Tue, 17 Feb 2026 15:44:41 -0500 Subject: [PATCH 2/4] feat: image resize for qwen2/3 vl --- src/common/AutoModel/modeling_qwen2vl.cpp | 4 ++ .../AutoModel/modeling_qwen2vl_image.cpp | 23 ++++++++++- src/common/AutoModel/modeling_qwen3vl.cpp | 2 +- .../AutoModel/modeling_qwen3vl_image.cpp | 38 +++++++------------ src/include/AutoModel/modeling_qwen2vl.hpp | 2 + src/include/AutoModel/modeling_qwen3vl.hpp | 2 +- src/include/utils/vm_args.hpp | 2 +- src/server/rest_handler.hpp | 2 +- 8 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/common/AutoModel/modeling_qwen2vl.cpp b/src/common/AutoModel/modeling_qwen2vl.cpp index 13181608..c4ae9c84 100644 --- a/src/common/AutoModel/modeling_qwen2vl.cpp +++ b/src/common/AutoModel/modeling_qwen2vl.cpp @@ -13,6 +13,10 @@ /************ Qwen2VL family **************/ Qwen2VL::Qwen2VL(xrt::device* npu_device_inst) : AutoModel(npu_device_inst, "Qwen2VL") {} +void Qwen2VL::set_special_flags(int resize) { + this->resize = resize; +} + void Qwen2VL::load_model(std::string model_path, json model_info, int default_context_length, bool enable_preemption) { this->_shared_load_model(model_path, model_info, default_context_length, enable_preemption); diff --git a/src/common/AutoModel/modeling_qwen2vl_image.cpp b/src/common/AutoModel/modeling_qwen2vl_image.cpp index 1beb88c2..8470cece 100644 --- a/src/common/AutoModel/modeling_qwen2vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen2vl_image.cpp @@ -512,17 +512,36 @@ void Qwen2VL::preprocess_image(qwen2vl_image_t& image, std::vector &pixel_ const int width = image.width; const int height = image.height; const int channels = 3; // RGB + int downscaled_height; + int downscaled_width; int resized_height; int resized_width; + + std::cout << "height " << height << " width " << width << std::endl; + + + int target_longest_edge = (resize == 1) ? 1080 : (resize == 2) ? 2560 : 0; + + if (target_longest_edge > 0) { + float scale = target_longest_edge / static_cast(std::max(height, width)); + scale = std::min(scale, 1.0f); + downscaled_height = static_cast(height * scale); + downscaled_width = static_cast(width * scale); + } + else { + downscaled_height = height; + downscaled_width = width; + } + // do the automatically resizing in here smart_resize( - height, width, + downscaled_height, downscaled_width, resized_height, resized_width, QWEN2_PATCH_SIZE * QWEN2_IMAGE_MERGE_SIZE, QWEN2_SHORTEST_EDGE, QWEN2_LONGEST_EDGE ); - // std::cout << "resized_height "<< resized_height << " resized_width " << resized_width <load_image_base64(img_str); - preprocess_image(image, image_payload._data__processed, resize); + preprocess_image(image, image_payload._data__processed); image_payload.images.push_back(image); image_payload.num_images++; } diff --git a/src/common/AutoModel/modeling_qwen3vl_image.cpp b/src/common/AutoModel/modeling_qwen3vl_image.cpp index d3b4590a..5adc28bf 100644 --- a/src/common/AutoModel/modeling_qwen3vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen3vl_image.cpp @@ -508,43 +508,33 @@ void Qwen3VL::smart_resize( ///@note: Converts uint8 image to BF16 format, data is already in (3, H, W) CHW layout ///@param: image: the image to preprocess (already in CHW format) ///@return: the preprocessed image in BF16 format -void Qwen3VL::preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values, int resize) { +void Qwen3VL::preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values) { const int width = image.width; const int height = image.height; const int channels = 3; // RGB + int downscaled_height; + int downscaled_width; int resized_height; int resized_width; - int aresized_height; - int aresized_width; std::cout << "height "<< height << " width " << width <(height * scale); - int raw_new_w = static_cast(width * scale); - - // CRITICAL: Align to QWEN3_PATCH_SIZE. - // If we don't align, (resized_h / patch_size) will truncate, losing data. - // We round to the nearest multiple of the patch size. - aresized_height = ((raw_new_h + QWEN3_PATCH_SIZE / 2) / QWEN3_PATCH_SIZE) * QWEN3_PATCH_SIZE; - aresized_width = ((raw_new_w + QWEN3_PATCH_SIZE / 2) / QWEN3_PATCH_SIZE) * QWEN3_PATCH_SIZE; - - // Ensure we explicitly enforce the minimum size (1 patch) to avoid 0 dimension - aresized_height = std::max(resized_height, (int)QWEN3_PATCH_SIZE); - aresized_width = std::max(resized_width, (int)QWEN3_PATCH_SIZE); + int target_longest_edge = (resize == 1) ? 1080 : (resize == 2) ? 2560 : 0; + if (target_longest_edge > 0) { + float scale = target_longest_edge / static_cast(std::max(height, width)); + scale = std::min(scale, 1.0f); + downscaled_height = static_cast(height * scale); + downscaled_width = static_cast(width * scale); + } + else { + downscaled_height = height; + downscaled_width = width; } // do the automatically resizing in here smart_resize( - aresized_height, aresized_width, + downscaled_height, downscaled_width, resized_height, resized_width, QWEN3_PATCH_SIZE * QWEN3_IMAGE_MERGE_SIZE, QWEN3_SHORTEST_EDGE, diff --git a/src/include/AutoModel/modeling_qwen2vl.hpp b/src/include/AutoModel/modeling_qwen2vl.hpp index d567e4ba..d4589fa6 100644 --- a/src/include/AutoModel/modeling_qwen2vl.hpp +++ b/src/include/AutoModel/modeling_qwen2vl.hpp @@ -47,6 +47,7 @@ class Qwen2VL : public AutoModel { int debug_count= 0; + int resize; void smart_resize( int height, int width, int& h_bar,int& w_bar, @@ -59,6 +60,7 @@ class Qwen2VL : public AutoModel { public: Qwen2VL(xrt::device* npu_device_inst); + void set_special_flags(int resize) override; void load_model(std::string model_path, json model_inf, int default_context_length = -1, bool enable_preemption = false) override; //void toggle_enable_think() override; bool insert(chat_meta_info_t& meta_info, lm_uniform_input_t& input) override; diff --git a/src/include/AutoModel/modeling_qwen3vl.hpp b/src/include/AutoModel/modeling_qwen3vl.hpp index 4f0f33c8..9f6e7ade 100644 --- a/src/include/AutoModel/modeling_qwen3vl.hpp +++ b/src/include/AutoModel/modeling_qwen3vl.hpp @@ -57,7 +57,7 @@ class Qwen3VL : public AutoModel { int min_pixels, int max_pixels); - void preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values, int resize = -1); + void preprocess_image(qwen3vl_image_t& image, std::vector &pixel_values); public: Qwen3VL(xrt::device* npu_device_inst); diff --git a/src/include/utils/vm_args.hpp b/src/include/utils/vm_args.hpp index 05ba20f9..4c2a71a3 100644 --- a/src/include/utils/vm_args.hpp +++ b/src/include/utils/vm_args.hpp @@ -71,7 +71,7 @@ bool parse_options(int argc, char *argv[], ParsedArgs& parsed_args) { ("quiet", "Hide emojis in the model list (can be used with --filter)") ("ctx-len,c", po::value(&parsed_args.ctx_length)->default_value(-1), "Set context length") - ("resize,r", po::value(&parsed_args.resize)->default_value(-1), + ("resize,r", po::value(&parsed_args.resize)->default_value(0), "Pre-resize the image") ("socket,s", po::value(&parsed_args.max_socket_connections)->default_value(10), "Set the maximum number of socket connections allowed (for serve command)") diff --git a/src/server/rest_handler.hpp b/src/server/rest_handler.hpp index 3fffdef6..47c16b9e 100644 --- a/src/server/rest_handler.hpp +++ b/src/server/rest_handler.hpp @@ -31,7 +31,7 @@ using StreamResponseCallback = std::function; // data, class RestHandler { public: - RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length = -1, int resize = -1, bool preemption = false); + RestHandler(model_list& models, ModelDownloader& downloader, const std::string& default_tag, bool asr, bool embed, int ctx_length = -1, int resize = 0, bool preemption = false); ~RestHandler(); void handle_show(const json& request, From 748b0a963636762d9721a25e51dfe64ed6faaac3 Mon Sep 17 00:00:00 2001 From: ZaneNi Date: Tue, 17 Feb 2026 15:46:48 -0500 Subject: [PATCH 3/4] hide debug info --- src/common/AutoModel/modeling_qwen2vl_image.cpp | 5 ++--- src/common/AutoModel/modeling_qwen3vl_image.cpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/AutoModel/modeling_qwen2vl_image.cpp b/src/common/AutoModel/modeling_qwen2vl_image.cpp index 8470cece..5f1b0844 100644 --- a/src/common/AutoModel/modeling_qwen2vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen2vl_image.cpp @@ -517,8 +517,7 @@ void Qwen2VL::preprocess_image(qwen2vl_image_t& image, std::vector &pixel_ int resized_height; int resized_width; - std::cout << "height " << height << " width " << width << std::endl; - + //std::cout << "height " << height << " width " << width << std::endl; int target_longest_edge = (resize == 1) ? 1080 : (resize == 2) ? 2560 : 0; @@ -541,7 +540,7 @@ void Qwen2VL::preprocess_image(qwen2vl_image_t& image, std::vector &pixel_ QWEN2_SHORTEST_EDGE, QWEN2_LONGEST_EDGE ); - std::cout << "resized_height "<< resized_height << " resized_width " << resized_width < &pixel_ int resized_height; int resized_width; - std::cout << "height "<< height << " width " << width < &pixel_ QWEN3_LONGEST_EDGE ); - std::cout << "resized_height " << resized_height << " resized_width " << resized_width << std::endl; + //std::cout << "resized_height " << resized_height << " resized_width " << resized_width << std::endl; // Cache size calculations for efficiency const uint32_t single_frame_size = resized_height * resized_width * channels; From fbee4d70bd60ee0fac06bf86f97d6d20d2527ea5 Mon Sep 17 00:00:00 2001 From: ZaneNi Date: Wed, 18 Feb 2026 10:48:52 -0500 Subject: [PATCH 4/4] feat: improve resize --- src/common/AutoModel/modeling_qwen2vl_image.cpp | 2 +- src/common/AutoModel/modeling_qwen3vl_image.cpp | 2 +- src/include/AutoModel/modeling_qwen2vl.hpp | 4 ++-- src/include/AutoModel/modeling_qwen3vl.hpp | 4 ++-- src/runner/runner.cpp | 3 ++- src/runner/runner.hpp | 2 +- src/src/main.cpp | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/common/AutoModel/modeling_qwen2vl_image.cpp b/src/common/AutoModel/modeling_qwen2vl_image.cpp index 5f1b0844..bd34eb84 100644 --- a/src/common/AutoModel/modeling_qwen2vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen2vl_image.cpp @@ -519,7 +519,7 @@ void Qwen2VL::preprocess_image(qwen2vl_image_t& image, std::vector &pixel_ //std::cout << "height " << height << " width " << width << std::endl; - int target_longest_edge = (resize == 1) ? 1080 : (resize == 2) ? 2560 : 0; + int target_longest_edge = (resize == 0) ? 1080 : (resize == 1) ? 1920 : (resize == 2) ? 2560 : 0; if (target_longest_edge > 0) { float scale = target_longest_edge / static_cast(std::max(height, width)); diff --git a/src/common/AutoModel/modeling_qwen3vl_image.cpp b/src/common/AutoModel/modeling_qwen3vl_image.cpp index 1e7980e5..5e0943e0 100644 --- a/src/common/AutoModel/modeling_qwen3vl_image.cpp +++ b/src/common/AutoModel/modeling_qwen3vl_image.cpp @@ -519,7 +519,7 @@ void Qwen3VL::preprocess_image(qwen3vl_image_t& image, std::vector &pixel_ //std::cout << "height "<< height << " width " << width < 0) { float scale = target_longest_edge / static_cast(std::max(height, width)); diff --git a/src/include/AutoModel/modeling_qwen2vl.hpp b/src/include/AutoModel/modeling_qwen2vl.hpp index d4589fa6..5e0bc649 100644 --- a/src/include/AutoModel/modeling_qwen2vl.hpp +++ b/src/include/AutoModel/modeling_qwen2vl.hpp @@ -46,8 +46,8 @@ class Qwen2VL : public AutoModel { qwen2vl_image_t load_image_base64(const std::string& base64_string); - int debug_count= 0; - int resize; + int debug_count = 0; + int resize = 0; void smart_resize( int height, int width, int& h_bar,int& w_bar, diff --git a/src/include/AutoModel/modeling_qwen3vl.hpp b/src/include/AutoModel/modeling_qwen3vl.hpp index 9f6e7ade..ab88caca 100644 --- a/src/include/AutoModel/modeling_qwen3vl.hpp +++ b/src/include/AutoModel/modeling_qwen3vl.hpp @@ -47,8 +47,8 @@ class Qwen3VL : public AutoModel { qwen3vl_image_t load_image_base64(const std::string& base64_string); - int debug_count= 0; - int resize = -1; + int debug_count = 0; + int resize = 0; void smart_resize( int height, int width, diff --git a/src/runner/runner.cpp b/src/runner/runner.cpp index 4532de1c..4e6cc9ef 100644 --- a/src/runner/runner.cpp +++ b/src/runner/runner.cpp @@ -36,7 +36,7 @@ std::map cmd_map = { /// \param supported_models - the list of supported models /// \param downloader - the downloader for the models /// \param tag - the tag of the model to load -Runner::Runner(model_list& supported_models, ModelDownloader& downloader, std::string& tag, bool asr, bool embed, int ctx_length, bool preemption) +Runner::Runner(model_list& supported_models, ModelDownloader& downloader, std::string& tag, bool asr, bool embed, int ctx_length, int resize, bool preemption) : supported_models(supported_models), downloader(downloader), tag(tag), asr(asr), embed(embed) { this->npu_device_inst = xrt::device(0); @@ -83,6 +83,7 @@ Runner::Runner(model_list& supported_models, ModelDownloader& downloader, std::s this->downloader.pull_model(this->tag); } auto [new_tag, model_info] = this->supported_models.get_model_info(this->tag); + this->auto_chat_engine->set_special_flags(resize); this->auto_chat_engine->load_model(this->supported_models.get_model_path(new_tag), model_info, this->ctx_length, this->preemption); this->generate_limit = -1; diff --git a/src/runner/runner.hpp b/src/runner/runner.hpp index 93813166..b61b6199 100644 --- a/src/runner/runner.hpp +++ b/src/runner/runner.hpp @@ -43,7 +43,7 @@ typedef enum { /// \brief Runner class class Runner { public: - Runner(model_list& supported_models, ModelDownloader& downloader, std::string& tag, bool asr, bool embed, int ctx_length, bool preemption); + Runner(model_list& supported_models, ModelDownloader& downloader, std::string& tag, bool asr, bool embed, int ctx_length, int resize, bool preemption); void run(); private: std::string tag; diff --git a/src/src/main.cpp b/src/src/main.cpp index 91e7f949..e658699a 100644 --- a/src/src/main.cpp +++ b/src/src/main.cpp @@ -333,7 +333,7 @@ int main(int argc, char* argv[]) { } else if (command == "run") { check_and_notify_new_version(); - Runner runner(availble_models, downloader, tag, asr, embed, ctx_length, preemption); + Runner runner(availble_models, downloader, tag, asr, embed, ctx_length, resize, preemption); runner.run(); } else if (command == "serve") {