Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Wrong implementation of c++ function roundByFactor (https://github.com/NVIDIA/TensorRT-Edge-LLM/blob/release/0.7.0/cpp/multimodal/qwenViTRunner.cpp#L373-L375), which refer round_by_factor in https://github.com/QwenLM/Qwen3-VL/blob/main/qwen-vl-utils/src/qwen_vl_utils/vision_process.py#L41-L43
GT
def round_by_factor(number: int, factor: int) -> int:
"""Returns the closest integer to 'number' that is divisible by 'factor'."""
return round(number / factor) * factor
factor=32
h_bar = max(factor, round_by_factor(720, factor))
print(h_bar)
Impl of v0.7.0
Modified impl
auto my_round_by_factor = [](int64_t value, int64_t factor) -> int64_t {
if (factor == 0) return int64_t(0);
double div = static_cast<double>(value) / factor;
double rounded = std::nearbyint(div);
return static_cast<int64_t>(rounded) * factor;
};Test
#include <stdio.h>
#include <cmath>
int64_t factor = 32;
int main(){
auto roundByFactor = [](int64_t value, int64_t factor) -> int64_t {
return std::round(static_cast<double>(value) / factor) * factor;
};
auto a = roundByFactor(720, factor);
printf("%d\n", a);
//////////////////////////////////////////////////////////////////////
auto my_round_by_factor = [](int64_t value, int64_t factor) -> int64_t {
if (factor == 0) return int64_t(0);
double div = static_cast<double>(value) / factor;
double rounded = std::nearbyint(div);
return static_cast<int64_t>(rounded) * factor;
};
auto b = my_round_by_factor(720, factor);
printf("%d\n", b);
return 0;
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
nvamberl commentedon May 13, 2026
Thanks @lix19937 for the detailed report and reproducer — confirmed.
std::roundrounds half-away-from-zero while Python 3'srounduses banker's rounding (round-half-to-even), so the C++ and HF outputs diverge on any.5boundary (e.g. 720 / 32 → 736 in C++ vs 704 in Python).A fix has been merged internally and will ship in the next release. We're using an integer banker's-round implementation instead of
std::nearbyintto avoid any dependency on the global FP rounding mode, but the end behavior matches Pythonround(v/f)*fexactly.