MCPcopy Create free account
hub / github.com/apple/coremltools / read_int4_data

Method read_int4_data

milstoragepython/MilStorage.cpp:156–162  ·  view source on GitHub ↗

These methods are needed in addition to the above template methods because pybind does not allow us to expose template methods to Python with gcc on Linux.

Source from the content-addressed store, hash-verified

154// because pybind does not allow us to expose template methods to
155// Python with gcc on Linux.
156py::array_t<int8_t> MilStoragePythonReader::read_int4_data(uint64_t offset) {
157 // First read packed data using MILBlob reader, and restore to int8 values which represents int4.
158 auto int4SpanData = m_reader->GetDataView<MILBlob::Int4>(offset);
159 MILBlob::Util::Span<const uint8_t> packedValuesSpan = MILBlob::Util::CastFromBitSpan<const MILBlob::Int4>(int4SpanData);
160 auto unpackedInt4Data = MILBlob::UnPackSubByteVec<MILBlob::Int4>({packedValuesSpan.begin(), packedValuesSpan.end()}, int4SpanData.Size());
161 return py::array_t<int8_t>(unpackedInt4Data.size(), reinterpret_cast<int8_t*>(unpackedInt4Data.data()));
162}
163
164py::array_t<uint8_t> MilStoragePythonReader::read_uint1_data(uint64_t offset) {
165 return readUnsignedSubByteData<MILBlob::UInt1>(*m_reader, offset);

Callers 2

test_weight_blob_int4Method · 0.80
_load_file_valueFunction · 0.80

Calls 5

sizeMethod · 0.65
beginMethod · 0.45
endMethod · 0.45
SizeMethod · 0.45
dataMethod · 0.45

Tested by 1

test_weight_blob_int4Method · 0.64