mirror of https://github.com/google/gemma.cpp.git
parent
59a1f87d63
commit
c0643577c3
|
|
@ -527,14 +527,21 @@ class Compressor {
|
||||||
template <typename MatT, size_t kCapacity>
|
template <typename MatT, size_t kCapacity>
|
||||||
void operator()(const char* name, const float* weights,
|
void operator()(const char* name, const float* weights,
|
||||||
CompressedArray<MatT, kCapacity>& compressed) {
|
CompressedArray<MatT, kCapacity>& compressed) {
|
||||||
fprintf(stderr, "Regenerating %s (%zuM), please wait\n", name,
|
Insert(name, weights, kCapacity, work_, compressed.CompressedSize(),
|
||||||
kCapacity / (1000 * 1000));
|
compressed.data(), 0, pool_);
|
||||||
Compress(weights, kCapacity, work_, kCapacity, compressed.data(), 0, pool_);
|
|
||||||
writer_.Add(CacheKey<MatT>(name), compressed.data(),
|
|
||||||
compressed.CompressedSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddScales(float* scales, size_t len) {
|
template <typename MatT>
|
||||||
|
void Insert(const char* name, const float* weights, size_t weights_count,
|
||||||
|
CompressWorkingSet& work, size_t out_capacity, MatT* out,
|
||||||
|
size_t out_ofs, hwy::ThreadPool& pool) {
|
||||||
|
fprintf(stderr, "Regenerating %s (%zuM), please wait\n", name,
|
||||||
|
weights_count / (1000 * 1000));
|
||||||
|
Compress(weights, weights_count, work_, weights_count, out, 0, pool_);
|
||||||
|
writer_.Add(CacheKey<MatT>(name), out, out_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddScales(const float* scales, size_t len) {
|
||||||
if (len) {
|
if (len) {
|
||||||
writer_.Add(CacheKey<float>("scales"), scales, len * sizeof(scales[0]));
|
writer_.Add(CacheKey<float>("scales"), scales, len * sizeof(scales[0]));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,13 @@ constexpr size_t CompressedArrayLen<NuqStream>(size_t capacity) {
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
// Returns the number of bytes required to store a compressed array with the
|
||||||
|
// given type and capacity.
|
||||||
|
template <typename MatT>
|
||||||
|
constexpr size_t CompressedArraySize(size_t capacity) {
|
||||||
|
return detail::CompressedArrayLen<MatT>(capacity) * sizeof(MatT);
|
||||||
|
}
|
||||||
|
|
||||||
// Compressed representation of floating-point elements. The array length may
|
// Compressed representation of floating-point elements. The array length may
|
||||||
// differ from the number of elements. Associated operations such as Dot are
|
// differ from the number of elements. Associated operations such as Dot are
|
||||||
// implemented in SIMD code and are thus non-member functions.
|
// implemented in SIMD code and are thus non-member functions.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue