Repository navigation
Expand file tree
/
Copy pathgemma4_31b_worker.cpp
More file actions
63 lines (55 loc) · 2.05 KB
/
Copy pathgemma4_31b_worker.cpp
File metadata and controls
63 lines (55 loc) · 2.05 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
/*
* 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.
*/
#include <gflags/gflags.h>
#include <executorch/examples/llm_server/cpp/worker_loop.h>
#include <executorch/examples/models/gemma4_31b/gemma4_31b_engine.h>
#include <executorch/runtime/platform/log.h>
DEFINE_string(model_path, "", "Model .pte file path.");
DEFINE_string(tokenizer_path, "", "HuggingFace tokenizer.json path.");
DEFINE_string(data_path, "", "Data file (.ptd) for delegated weights.");
DEFINE_int32(
max_sessions,
1,
"Max physical sessions to host on one weight allocation. Clamped to 1 if "
"the backend cannot isolate per-session mutable state.");
DEFINE_bool(
warm_resume,
true,
"Warm append-only resume for named sessions when the engine supports them.");
DEFINE_int32(bos_id, 2, "BOS token id to prepend to server-rendered prompts.");
DEFINE_int32(eos_id, 1, "EOS token id (Gemma convention: 1).");
namespace {
namespace llm = ::executorch::extension::llm;
using ::executorch::runtime::Error;
} // namespace
int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_model_path.empty() || FLAGS_tokenizer_path.empty()) {
ET_LOG(
Error, "gemma4_31b_worker: --model_path and --tokenizer_path required");
return 1;
}
llm::Gemma4_31BConfig config;
config.model_path = FLAGS_model_path;
config.data_path = FLAGS_data_path;
config.tokenizer_path = FLAGS_tokenizer_path;
config.max_sessions = FLAGS_max_sessions;
config.eos_id = FLAGS_eos_id;
auto engine_result = llm::Gemma4_31BEngine::create(config);
if (engine_result.error() != Error::Ok) {
ET_LOG(Error, "gemma4_31b_worker: failed to create engine");
return 1;
}
auto engine = std::move(engine_result.get());
return llm::run_worker_stdio_loop(
*engine,
*engine->tokenizer(),
engine->metadata(),
FLAGS_warm_resume,
{static_cast<uint64_t>(FLAGS_bos_id)});
}