unity_model_loader.cpp 949 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. #include "ggml/ggml.h"
  7. #include "ggml/ggml-alloc.h"
  8. #include "common.h"
  9. #include "common-ggml.h"
  10. #include "unity_model_loader.h"
  11. void unity_model_loader::load_hparams(fairseq2_model& model, std::ifstream &fin)
  12. {
  13. unity_hparams* hparams = (unity_hparams*)model.hparams;
  14. read_unity_hparams(*hparams, fin);
  15. if (hparams->__end_of_hparams__ != 6877961321223123048) {
  16. throw std::invalid_argument("");
  17. }
  18. }
  19. std::size_t
  20. unity_model_loader::compute_context_size(void* raw_hparams)
  21. {
  22. auto* hparams = (unity_hparams*)raw_hparams;
  23. return hparams->model_byte_size;
  24. };
  25. extern "C" int load_unity_ggml_file(fairseq2_model& model, const char* fname) {
  26. return load_fairseq2_ggml_file<unity_model_loader>(model, fname);
  27. }