-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathrunner.h
More file actions
67 lines (57 loc) · 2.1 KB
/
runner.h
File metadata and controls
67 lines (57 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
// A simple llama2 runner that includes preprocessing and post processing logic.
// The module takes in a string as input and emits a string as output.
#pragma once
#include "irunner.h"
#include "stats.h"
#include "text_decoder_runner.h"
#include "text_prefiller.h"
#include "text_token_generator.h"
#include <cstdint>
#include <executorch/extension/module/module.h>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <tokenizers-cpp/tokenizers_cpp.h>
#include <unordered_map>
namespace example {
class ET_EXPERIMENTAL Runner : public executorch::extension::llm::IRunner {
public:
explicit Runner(const std::string &model_path,
const std::string &tokenizer_path,
const float temperature = 0.8f,
std::optional<const std::string> data_path = std::nullopt);
bool is_loaded() const;
::executorch::runtime::Error load();
::executorch::runtime::Error
generate(const std::string &prompt,
std::function<void(const std::string &)> token_callback = {},
std::function<void(const ::executorch::extension::llm::Stats &)>
stats_callback = {},
bool echo = true, bool warming = false);
::executorch::runtime::Error warmup(const std::string &prompt);
void stop();
private:
float temperature_;
bool shouldStop_{false};
// model
std::unique_ptr<::executorch::extension::Module> module_;
std::string tokenizer_path_;
std::unique_ptr<tokenizers::Tokenizer> tokenizer_;
std::unordered_map<std::string, int64_t> metadata_;
std::unique_ptr<::executorch::extension::llm::TextDecoderRunner>
text_decoder_runner_;
std::unique_ptr<::executorch::extension::llm::TextPrefiller> text_prefiller_;
std::unique_ptr<::executorch::extension::llm::TextTokenGenerator>
text_token_generator_;
// stats
::executorch::extension::llm::Stats stats_;
};
} // namespace example