-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an interface for LLM runner (#6356)
Summary: In case we have custom LLM runners other than llama runner, we want to have a uniform interface Pull Request resolved: #6356 Reviewed By: cccclai Differential Revision: D64629696 Pulled By: kirklandsign fbshipit-source-id: b9a670e47c4a73ae1180c85e9f11f0b23e3e4ed6
- Loading branch information
1 parent
8209bc1
commit 4d7b294
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// An interface for LLM runners. Developers can create their own runner that | ||
// implements their own load and generation logic to run the model. | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#include <executorch/extension/llm/runner/stats.h> | ||
#include <executorch/extension/module/module.h> | ||
|
||
namespace executorch { | ||
namespace extension { | ||
namespace llm { | ||
|
||
class ET_EXPERIMENTAL IRunner { | ||
public: | ||
virtual ~IRunner() = default; | ||
|
||
// Checks if the model is loaded. | ||
virtual bool is_loaded() const = 0; | ||
|
||
// Load the model and tokenizer. | ||
virtual ::executorch::runtime::Error load() = 0; | ||
|
||
// Generate the output tokens. | ||
virtual ::executorch::runtime::Error generate( | ||
const std::string& prompt, | ||
int32_t seq_len, | ||
std::function<void(const std::string&)> token_callback = {}, | ||
std::function<void(const ::executorch::extension::llm::Stats&)> | ||
stats_callback = {}, | ||
bool echo = true, | ||
bool warming = false) = 0; | ||
|
||
// Stop the generation. | ||
virtual void stop() = 0; | ||
}; | ||
|
||
} // namespace llm | ||
} // namespace extension | ||
} // namespace executorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters