Skip to content

Commit 950190a

Browse files
committed
Replace mutable references with pointers for vlm util functions
1 parent 868092b commit 950190a

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

cpp/serve/model.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ class ModelImpl : public ModelObj {
116116
CHECK(ft_.image_embed_func_.defined()) << "`image_embed` function is not found in the model. ";
117117

118118
int tmp_h = 0, tmp_w = 0;
119-
CalculateResizeShape(image, this->model_type_, tmp_h, tmp_w);
119+
CalculateResizeShape(image, this->model_type_, &tmp_h, &tmp_w);
120120
ShapeTuple resize_h = {tmp_h};
121121
ShapeTuple resize_w = {tmp_w};
122122

123-
CalculateCropShape(image, this->model_type_, tmp_h, tmp_w);
123+
CalculateCropShape(image, this->model_type_, &tmp_h, &tmp_w);
124124
ShapeTuple crop_h = {tmp_h};
125125
ShapeTuple crop_w = {tmp_w};
126126

cpp/support/vlm_utils.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace mlc {
1010
namespace llm {
1111

1212
void CalculateResizeShape(tvm::runtime::NDArray image_data, std::string model_type,
13-
int& target_height, int& target_width) {
13+
int* p_target_height, int* p_target_width) {
1414
ICHECK_EQ(image_data->shape[3], 3) << "Image format must be NHWC";
1515
int height = image_data->shape[1];
1616
int width = image_data->shape[2];
@@ -23,34 +23,34 @@ void CalculateResizeShape(tvm::runtime::NDArray image_data, std::string model_ty
2323
scale += 1;
2424
}
2525
scale -= 1;
26-
target_width = static_cast<int>(scale * 336);
27-
target_height = static_cast<int>(target_width / ratio);
26+
*p_target_width = static_cast<int>(scale * 336);
27+
*p_target_height = static_cast<int>(*p_target_width / ratio);
2828
}
2929
}
3030

31-
void CalculatePadShape(tvm::runtime::NDArray image_data, std::string model_type, int& pad_height,
32-
int& pad_width) {
31+
void CalculatePadShape(tvm::runtime::NDArray image_data, std::string model_type, int* p_pad_height,
32+
int* p_pad_width) {
3333
ICHECK_EQ(image_data->shape[3], 3) << "Image format must be NHWC";
3434
if ("phi3_v" == model_type) {
3535
int resized_height = 0, resized_width = 0;
36-
CalculateResizeShape(image_data, model_type, resized_height, resized_width);
36+
CalculateResizeShape(image_data, model_type, &resized_height, &resized_width);
3737
int tar = (int)(ceil(resized_height / 336.0) * 336);
3838
int top_padding = (int)((tar - resized_height) / 2);
3939
int bottom_padding = tar - resized_height - top_padding;
4040
ICHECK_EQ(tar, resized_height + top_padding + bottom_padding) << "Padding size not equal!";
41-
pad_height = tar;
42-
pad_width = resized_width;
41+
*p_pad_height = tar;
42+
*p_pad_width = resized_width;
4343
}
4444
}
4545

46-
void CalculateCropShape(tvm::runtime::NDArray image_data, std::string model_type, int& crop_height,
47-
int& crop_width) {
46+
void CalculateCropShape(tvm::runtime::NDArray image_data, std::string model_type,
47+
int* p_crop_height, int* p_crop_width) {
4848
ICHECK_EQ(image_data->shape[3], 3) << "Image format must be NHWC";
4949
if ("phi3_v" == model_type) {
5050
int pad_h = 0, pad_w = 0;
51-
CalculatePadShape(image_data, model_type, pad_h, pad_w);
52-
crop_height = pad_h / 336;
53-
crop_width = pad_w / 336;
51+
CalculatePadShape(image_data, model_type, &pad_h, &pad_w);
52+
*p_crop_height = pad_h / 336;
53+
*p_crop_width = pad_w / 336;
5454
}
5555
}
5656

cpp/support/vlm_utils.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ namespace llm {
2121
* the variable where the calculated target width will be stored.
2222
*/
2323
void CalculateResizeShape(tvm::runtime::NDArray image_data, std::string model_type,
24-
int& target_height, int& target_width);
24+
int* p_target_height, int* p_target_width);
2525
/*!
2626
* \brief Calculate the padding height and width for an image based on the input data and model
2727
* type. \param image_data The input image data as a TVM NDArray. \param model_type The type of the
2828
* model influencing the padding parameters (e.g., phi3v). \param pad_height Reference to the
2929
* variable where the calculated padding height will be stored. \param pad_width Reference to the
3030
* variable where the calculated padding width will be stored.
3131
*/
32-
void CalculatePadShape(tvm::runtime::NDArray image_data, std::string model_type, int& pad_height,
33-
int& pad_width);
32+
void CalculatePadShape(tvm::runtime::NDArray image_data, std::string model_type, int* p_pad_height,
33+
int* p_pad_width);
3434

3535
/*!
3636
* \brief Calculate the cropping height and width for an image based on the input data and model
@@ -39,8 +39,8 @@ void CalculatePadShape(tvm::runtime::NDArray image_data, std::string model_type,
3939
* variable where the calculated cropping height will be stored. \param crop_width Reference to the
4040
* variable where the calculated cropping width will be stored.
4141
*/
42-
void CalculateCropShape(tvm::runtime::NDArray image_data, std::string model_type, int& crop_height,
43-
int& crop_width);
42+
void CalculateCropShape(tvm::runtime::NDArray image_data, std::string model_type,
43+
int* p_crop_height, int* p_crop_width);
4444

4545
} // namespace llm
4646
} // namespace mlc

0 commit comments

Comments
 (0)