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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sys/stat.h>
#include <unistd.h>

namespace torch::executor {
namespace example {

class FileMemMapper { // Read-only mmap
public:
Expand Down Expand Up @@ -97,4 +97,4 @@ class FileMemMapper { // Read-only mmap
size_t mSize = 0;
};

} // namespace torch::executor
} // namespace example
4 changes: 2 additions & 2 deletions examples/mediatek/executor_runner/llama_runner/LlamaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "llm_helper/include/llm_types.h"

namespace torch::executor {
namespace example {

using llm_helper::LLMType;

Expand Down Expand Up @@ -42,4 +42,4 @@ struct LlamaModelPaths {
std::vector<std::string> gen_model_paths;
};

} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "llm_helper/include/mask_builder.h"
#include "llm_helper/include/rotary_embedding.h"

namespace torch::executor {
namespace example {

inline std::vector<size_t> getIndexRange(
const size_t startIndex,
Expand Down Expand Up @@ -343,4 +343,4 @@ void LlamaModelChunk::InitCache() {
}
}

} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include "llm_helper/include/mask_builder.h"
#include "llm_helper/include/rotary_embedding.h"

namespace torch::executor {
namespace example {

using llm_helper::MaskBuilder;
using llm_helper::RotaryEmbeddingMasterLut;

using TensorShape = Span<const int32_t>;
using TensorShape = executorch::runtime::Span<const int32_t>;
using ModelIndexMap = std::unordered_map<size_t, size_t>;

// Llama decoder chunk
Expand Down Expand Up @@ -135,4 +135,4 @@ class LlamaModelChunk : public ModelChunk {
size_t mCurrentTokenIndex = 0;
};

} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "llm_helper/include/rotary_embedding.h"
#include "llm_helper/include/token_embedding.h"

namespace torch::executor {
namespace example {

void LlamaRuntime::Initialize(
const LlamaModelOptions& modelOptions,
Expand Down Expand Up @@ -201,4 +201,4 @@ const LlamaModelOptions& LlamaRuntime::GetModelOptions() const {
return mModelOptions;
}

} // namespace torch::executor
} // namespace example
4 changes: 2 additions & 2 deletions examples/mediatek/executor_runner/llama_runner/LlamaRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "llm_helper/include/rotary_embedding.h"
#include "llm_helper/include/token_embedding.h"

namespace torch::executor {
namespace example {

class LlamaRuntime {
public:
Expand Down Expand Up @@ -56,4 +56,4 @@ class LlamaRuntime {
size_t mTokenIndex = 0;
};

} // namespace torch::executor
} // namespace example
20 changes: 16 additions & 4 deletions examples/mediatek/executor_runner/llama_runner/ModelChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@
#define ENSURE_INIT \
ET_CHECK_MSG(Initialized(), "Error: Model chunk not initialized.");

namespace torch::executor {

using util::FileDataLoader;
namespace example {

using executorch::aten::Tensor;
using executorch::aten::TensorImpl;
using executorch::extension::FileDataLoader;
using executorch::runtime::Error;
using executorch::runtime::HierarchicalAllocator;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::MemoryManager;
using executorch::runtime::Method;
using executorch::runtime::MethodMeta;
using executorch::runtime::Program;
using executorch::runtime::Result;
using executorch::runtime::Span;
using executorch::runtime::Tag;

static constexpr size_t kMethodAllocatorPoolSize = 4 * 1024U * 1024U; // 4MB

Expand Down Expand Up @@ -572,4 +584,4 @@ void ModelChunk::ReleaseModelInstance(void* modelInstance) {
}
}

} // namespace torch::executor
} // namespace example
6 changes: 3 additions & 3 deletions examples/mediatek/executor_runner/llama_runner/ModelChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "MultiModelLoader.h"

namespace torch::executor {
namespace example {

struct BufferInfo {
void* data = nullptr;
Expand Down Expand Up @@ -91,7 +91,7 @@ class ModelChunk : protected MultiTokenSizeModelLoader {
// Release allocated buffers for model IOs
void ReleaseIoBuffers();

Method& GetModelMethod();
executorch::runtime::Method& GetModelMethod();

private:
// Override the virtual functions
Expand Down Expand Up @@ -119,4 +119,4 @@ class ModelChunk : protected MultiTokenSizeModelLoader {
std::unordered_map<size_t, size_t> mModelOutToInIndexLinks;
};

} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <unordered_map>
#include <vector>

namespace torch::executor {
namespace example {

template <typename IdType>
void MultiModelLoader<IdType>::LoadModels() {
Expand Down Expand Up @@ -174,4 +174,4 @@ std::string MultiModelLoader<IdType>::GetIdString(const IdType& id) {
template class MultiModelLoader<int>;
template class MultiModelLoader<size_t>;

} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <unordered_map>
#include <vector>

namespace torch::executor {
namespace example {

template <typename IdType = size_t>
class MultiModelLoader {
Expand Down Expand Up @@ -92,4 +92,4 @@ class MultiModelLoader {
IdType mCurrentModelId = 0;
};

} // namespace torch::executor
} // namespace example
4 changes: 2 additions & 2 deletions examples/mediatek/executor_runner/llama_runner/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string_view>
#include <vector>

namespace torch::executor {
namespace example {
namespace utils {

class Timer {
Expand Down Expand Up @@ -113,4 +113,4 @@ static std::string to_string(const std::vector<T> vec) {
}

} // namespace utils
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <stddef.h>
#include <strings.h>

namespace torch::executor {
namespace example {
namespace llm_helper {

typedef enum { INT4, INT8, INT16, FP16, INT32, FP32, INVALID } LLMType;
Expand Down Expand Up @@ -72,4 +72,4 @@ inline const char* getLLMTypeName(const LLMType llm_type) {
}

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <string>

namespace torch::executor {
namespace example {
namespace llm_helper {

class MaskBuilder {
Expand Down Expand Up @@ -76,4 +76,4 @@ class MaskBuilder {
};

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string>
#include <vector>

namespace torch::executor {
namespace example {
namespace llm_helper {

class RotaryEmbeddingMasterLut {
Expand Down Expand Up @@ -77,4 +77,4 @@ class RotaryEmbeddingMasterLut {
};

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string>
#include <vector>

namespace torch::executor {
namespace example {

class FileMemMapper;

Expand Down Expand Up @@ -49,4 +49,4 @@ class TokenEmbeddingLut {
};

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <executorch/runtime/platform/assert.h>
#include <executorch/runtime/platform/log.h>

namespace torch::executor {
namespace example {
namespace llm_helper {

// Define mask values for different types
Expand Down Expand Up @@ -260,4 +260,4 @@ bool MaskBuilder::adjustMaskForPadding(const size_t tokenBatchSize) {
}

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <fstream>
#include <type_traits>

namespace torch::executor {
namespace example {
namespace llm_helper {

RotaryEmbeddingMasterLut::RotaryEmbeddingMasterLut(
Expand Down Expand Up @@ -394,4 +394,4 @@ size_t RotaryEmbeddingMasterLut::getRotEmbedLength() const {
}

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace fs = std::filesystem;

namespace torch::executor {
namespace example {
namespace llm_helper {

TokenEmbeddingLut::TokenEmbeddingLut(
Expand Down Expand Up @@ -90,4 +90,4 @@ void TokenEmbeddingLut::lookupEmbedding(const std::vector<uint64_t>& tokens) {
}

} // namespace llm_helper
} // namespace torch::executor
} // namespace example
20 changes: 15 additions & 5 deletions examples/mediatek/executor_runner/mtk_executor_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ DEFINE_string(
"Model serialized in flatbuffer format.");
DEFINE_int32(iteration, 1, "Iterations of inference.");

using namespace torch::executor;
using torch::executor::util::FileDataLoader;
using executorch::extension::FileDataLoader;
using executorch::extension::prepare_input_tensors;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::HierarchicalAllocator;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::MemoryManager;
using executorch::runtime::Method;
using executorch::runtime::MethodMeta;
using executorch::runtime::Program;
using executorch::runtime::Result;
using executorch::runtime::Span;

int main(int argc, char** argv) {
runtime_init();
executorch::runtime::runtime_init();

gflags::ParseCommandLineFlags(&argc, &argv, true);
if (argc != 1) {
Expand Down Expand Up @@ -158,7 +168,7 @@ int main(int argc, char** argv) {
// Allocate input tensors and set all of their elements to 1. The `inputs`
// variable owns the allocated memory and must live past the last call to
// `execute()`.
auto inputs = util::prepare_input_tensors(*method);
auto inputs = prepare_input_tensors(*method);
ET_CHECK_MSG(
inputs.ok(),
"Could not prepare inputs: 0x%" PRIx32,
Expand Down Expand Up @@ -196,7 +206,7 @@ int main(int argc, char** argv) {
status = method->get_outputs(outputs.data(), outputs.size());
ET_CHECK(status == Error::Ok);
// Print the first and last 100 elements of long lists of scalars.
std::cout << torch::executor::util::evalue_edge_items(100);
std::cout << executorch::extension::evalue_edge_items(100);
for (int i = 0; i < outputs.size(); ++i) {
std::cout << "Output " << i << ": " << outputs[i] << std::endl;
}
Expand Down
Loading
Loading