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

Method write_int4_data

milstoragepython/MilStorage.cpp:56–64  ·  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

54// because pybind does not allow us to expose template methods to
55// Python with gcc on Linux.
56u_int64_t MilStoragePythonWriter::write_int4_data(const py::array_t<int8_t>& data) {
57 // The `data` is stored in int8 because numpy doesn't support int4.
58 // First pack those int4 data into uint8 Span, and then cast to int4 Span and write it.
59 auto int8SpanData = MILBlob::Util::Span<const int8_t>(data.data(), data.size());
60 std::vector<uint8_t> packedValues = MILBlob::PackInt8Span<MILBlob::Int4>(int8SpanData);
61 auto packedValuesSpan = MILBlob::Util::Span<const uint8_t>(packedValues.data(), packedValues.size());
62 auto int4Span = MILBlob::Util::CastToBitSpan<const MILBlob::Int4>(packedValuesSpan, data.size());
63 return m_writer->WriteData<MILBlob::Int4>(int4Span);
64}
65
66u_int64_t MilStoragePythonWriter::write_uint1_data(const py::array_t<uint8_t>& data) {
67 return writeUnsignedSubByteData<MILBlob::UInt1>(*m_writer, data);

Callers 3

test_weight_blob_int4Method · 0.80

Calls 2

sizeMethod · 0.65
dataMethod · 0.45

Tested by 2

test_weight_blob_int4Method · 0.64