Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid double precision operations #83

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tm_layers.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ tm_err_t TM_WEAK tml_softmax(tm_mat_t* in, tm_mat_t* out, sctype_t in_s, zptype_
dout[c] -= dmax;
dout[c] = (float)tm_exp(dout[c]);
sum += dout[c];
dout[c] -= 0.000001; //prevent 1.0 value (cause 256 overflow)
dout[c] -= 0.000001f; //prevent 1.0 value (cause 256 overflow)
}
for(int c=0; c <in->c; c++){ //int8/int16 <= fp32, so it is ok
#if TM_MDL_TYPE == TM_MDL_INT8 || TM_MDL_TYPE == TM_MDL_INT16
Expand Down
4 changes: 2 additions & 2 deletions src/tm_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ tm_err_t TM_WEAK tm_preprocess(tm_mdl_t* mdl, tm_pp_t pp_type, tm_mat_t* in, tm_
#else
case TMPP_UINT2FP01:
for(int i=0; i<in_size; i++)
out->data[i] = (((uint8_t*)(in->data))[i])/255.0;
out->data[i] = (((uint8_t*)(in->data))[i])/255.0f;
break;
case TMPP_UINT2FPN11:
for(int i=0; i<in_size; i++)
out->data[i] = ((((uint8_t*)(in->data))[i])-128)/128.0;
out->data[i] = ((((uint8_t*)(in->data))[i])-128)/128.0f;
break;
#endif
default: //don't do anything
Expand Down