Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/models/llama/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,25 @@ static constexpr auto kUseSDPAWithKVCache = "use_sdpa_with_kv_cache";
Runner::Runner(
const std::string& model_path,
const std::string& tokenizer_path,
const float temperature)
const float temperature,
std::optional<const std::string> data_path)
// NOTE: we observed ~2x loading performance increase on iPhone 15
// and a ~5% improvement on Galaxy S22 by switching to
// FileDataLoader instead of MmapDataLoader + UseMlockIgnoreErrors.
: temperature_(temperature),
module_(std::make_unique<Module>(model_path, Module::LoadMode::File)),
tokenizer_path_(tokenizer_path),
metadata_({
{kEnableDynamicShape, false},
{kMaxSeqLen, 128},
{kUseKVCache, true},
{kUseSDPAWithKVCache, false},
}) {
if (data_path.has_value()) {
module_ = std::make_unique<Module>(
model_path, data_path.value(), Module::LoadMode::File);
} else {
module_ = std::make_unique<Module>(model_path, Module::LoadMode::File);
}
ET_LOG(
Info,
"Creating LLaMa runner: model_path=%s, tokenizer_path=%s",
Expand Down
4 changes: 3 additions & 1 deletion examples/models/llama/runner/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>

Expand All @@ -32,7 +33,8 @@ class ET_EXPERIMENTAL Runner : public executorch::extension::llm::IRunner {
explicit Runner(
const std::string& model_path,
const std::string& tokenizer_path,
const float temperature = 0.8f);
const float temperature = 0.8f,
std::optional<const std::string> data_path = std::nullopt);

bool is_loaded() const;
::executorch::runtime::Error load();
Expand Down
Loading