model_loader.h 930 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // All rights reserved.
  3. //
  4. // This source code is licensed under the license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. #pragma once
  7. #include "ggml/ggml.h"
  8. #include "ggml/ggml-alloc.h"
  9. #include "common.h"
  10. #include "common-ggml.h"
  11. #include "fairseq2.h"
  12. #include <iostream>
  13. #include <stdexcept>
  14. class model_loader {
  15. public:
  16. std::int64_t load_model_weights(fairseq2_model &model, std::ifstream &fin);
  17. void load_hparams(std::unordered_map<std::string, std::int64_t>& hparams, std::ifstream &fin);
  18. private:
  19. ggml_tensor * next_tensor(std::ifstream &fin, fairseq2_model &model);
  20. std::string get_name(std::ifstream &fin);
  21. };
  22. ggml_tensor* load_tensor_value(std::ifstream &fin, ggml_context* ctx);
  23. std::ifstream open_ggml_file(const char* fname);
  24. extern "C" int load_fairseq2_ggml_file(fairseq2_model& model, const char* fname);