Skip to content

Commit

Permalink
Add support for autodetecting tensor_storage.type from the size of th…
Browse files Browse the repository at this point in the history
…e stream when it's not specified
  • Loading branch information
lmagder committed Aug 17, 2024
1 parent 697d000 commit f974370
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ struct PickleTensorReader {
ReadPhase phase = READ_NAME;
size_t entry_size = 0;
int32_t nelements = 0;
bool read_explict_type = false;

TensorStorage tensor_storage;

Expand All @@ -1049,6 +1050,11 @@ struct PickleTensorReader {
nelements = value;
phase = READ_DIMENS;
return true;
} else if (!read_explict_type && entry_size == value * ggml_type_size(GGML_TYPE_F16)) {
nelements = value;
tensor_storage.type = GGML_TYPE_F16;
phase = READ_DIMENS;
return true;
} else {
phase = READ_NAME;
}
Expand All @@ -1072,12 +1078,14 @@ struct PickleTensorReader {
read_global_type = false;
}
tensor_storage.type = GGML_TYPE_F32;
read_explict_type = true;
} else if (str == "HalfStorage") {
if (read_global_type) {
global_type = GGML_TYPE_F16;
read_global_type = false;
}
tensor_storage.type = GGML_TYPE_F16;
read_explict_type = true;
}
}

Expand Down

0 comments on commit f974370

Please sign in to comment.