From 955d86d9212dc53bc21059055abeaa21fb28a2a9 Mon Sep 17 00:00:00 2001 From: Daniel Keysers Date: Tue, 28 Jan 2025 04:03:48 -0800 Subject: [PATCH] Assorted small cleanups. PiperOrigin-RevId: 720517452 --- compression/compress.h | 2 +- compression/python/compression_clif_aux.cc | 6 +++--- gemma/gemma-inl.h | 2 -- gemma/weights.cc | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compression/compress.h b/compression/compress.h index 233f8d7..468c0d1 100644 --- a/compression/compress.h +++ b/compression/compress.h @@ -629,7 +629,7 @@ class ReadFromBlobStore { // reader_ invalid or any Enqueue failed if (err_ != 0) return err_; // Setup the model_memory. - for (int b = 0; b < model_toc_.size(); ++b) { + for (size_t b = 0; b < model_toc_.size(); ++b) { const std::string& file_key = file_keys_[b]; MatPtr* blob = model_toc_[b]; if (!file_toc_.Empty()) { diff --git a/compression/python/compression_clif_aux.cc b/compression/python/compression_clif_aux.cc index 05a5110..cad0d14 100644 --- a/compression/python/compression_clif_aux.cc +++ b/compression/python/compression_clif_aux.cc @@ -139,8 +139,9 @@ class SbsWriterImpl : public WriterInterface { void AddTokenizer(const std::string& tokenizer_path) override { Path path(tokenizer_path); GemmaTokenizer tokenizer(path); - tokenizer_proto_ = tokenizer.Serialize(); - compressor_.AddTokenizer(tokenizer_proto_); + std::string tokenizer_proto = tokenizer.Serialize(); + HWY_ASSERT(!tokenizer_proto.empty()); + compressor_.AddTokenizer(tokenizer_proto); } // Returns the number of blobs added. @@ -159,7 +160,6 @@ class SbsWriterImpl : public WriterInterface { std::vector model_memory_; std::vector scales_; CompressorMode mode_; - std::string tokenizer_proto_; }; WriterInterface* NewSbsWriter(CompressorMode mode) { diff --git a/gemma/gemma-inl.h b/gemma/gemma-inl.h index 1cfe7a5..666e9d5 100644 --- a/gemma/gemma-inl.h +++ b/gemma/gemma-inl.h @@ -690,7 +690,6 @@ HWY_NOINLINE void FFWNoVit(Activations& activations, size_t num_interleaved, PROFILER_ZONE("Gen.FFW"); const size_t model_dim = layer_weights->layer_config.model_dim; const size_t ffh_hidden_dim = layer_weights->layer_config.ff_hidden_dim; - using WeightType = T; HWY_DASSERT(num_interleaved <= activations.bf_pre_ffw_rms_out.BatchSize()); const bool add_bias = layer_weights->layer_config.ff_biases; @@ -746,7 +745,6 @@ HWY_NOINLINE void FFWVit(Activations& activations, size_t num_interleaved, const LayerWeightsPtrs* layer_weights) { PROFILER_ZONE("Gen.FFW"); const size_t ff_hidden_dim = layer_weights->layer_config.ff_hidden_dim; - using WeightType = typename LayerWeightsPtrs::WeightF32OrBF16; HWY_DASSERT(num_interleaved <= activations.bf_pre_ffw_rms_out.BatchSize()); const bool add_bias = layer_weights->layer_config.ff_biases; diff --git a/gemma/weights.cc b/gemma/weights.cc index 426de6d..213bb7e 100644 --- a/gemma/weights.cc +++ b/gemma/weights.cc @@ -130,7 +130,7 @@ BlobError ModelWeightsStorage::Save(const std::string& tokenizer, writer.AddTokenizer(tokenizer); int err = writer.WriteAll(weights, &config_); if (err != 0) { - fprintf(stderr, "Failed to load model weights: %d\n", err); + fprintf(stderr, "Failed to write model weights: %d\n", err); return err; } return 0;