Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Optimize the operation process #69

Merged
merged 7 commits into from
Mar 19, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Makefile
models/*
/.devcontainer/
/.vscode/
models
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Building mllm requires following tools:

#### Run Fuyu-8B

Download the model from [here](https://huggingface.co/mllmTeam), or using the following instructions
Download the model from [here](https://huggingface.co/mllmTeam/fuyu-8b-mllm/tree/main/), or using the following instructions

```bash
mkdir ../models && cd ../models
Expand Down Expand Up @@ -125,7 +125,7 @@ Result are as followed:

#### Run LLaMA-2-7B

Download model
Download model from [here](https://huggingface.co/mllmTeam/llama-2-7b-mllm/tree/main/), or using the following instructions

```bash
mkdir ../models && cd ../models
Expand Down Expand Up @@ -165,7 +165,7 @@ BUPT offers a wide range of undergraduate and graduate programs in fields such a

#### Run ImageBind

Download model
Download model from [here](https://huggingface.co/mllmTeam/imagebind_huge-mllm/tree/main), or using the following instructions

```bash
mkdir ../models && cd ../models
Expand Down
1 change: 0 additions & 1 deletion examples/demo_vit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <iostream>
#include <utility>
#include "cmdline.h"
#include "models/vit/modeling_vit.hpp"
#include "models/vit/labels_vit.hpp"
Expand Down
3 changes: 1 addition & 2 deletions include/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ typedef enum {
enum TensorStatus {
TENSOR_DYNAMIC,
TENSOR_STATIC_INIT ,
TENSOR_STATIC_SHAPED ,
TENSOR_STATIC_ALLOCED ,
TENSOR_STATIC_READY ,
};

enum ErrorCode {
Expand Down
689 changes: 325 additions & 364 deletions src/Layer.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ ParamLoader *Module::loader;
int Module::listIdx;
int Module::runlistIdx;
TensorStatus Module::tensor_status;

bool Module::doLoad = false;
} // namespace mllm
39 changes: 17 additions & 22 deletions src/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Module {
static map<BackendType, Backend *> backends;
static ParamLoader *loader;
static TensorStatus tensor_status;
static bool doLoad;

Module() = default;
virtual ~Module() = default;
Expand Down Expand Up @@ -48,6 +49,17 @@ class Module {

void load(string path) {
initLoader(path);
Module::doLoad = true;
vector<Tensor> tmps;
int max_in_size = 5;
for (int i = 0; i < max_in_size; ++i) {
Tensor::gph_[std::to_string(i)] = Tensor();
tmps.push_back(Tensor::gph_[std::to_string(i)]);
}
vector<int> tmpt = {0, 0};
operator()(tmps, tmpt);
Module::doLoad = false;
Tensor::gph_.clear();
}

virtual vector<Tensor> Forward(vector<Tensor> inputs, vector<std::any> args) = 0;
Expand All @@ -59,6 +71,9 @@ class Module {
template <typename... Args>
vector<Tensor> operator()(vector<Tensor> inputs, Args... args) {
vector<std::any> anyArgs = convertArgsToAnyVector(args...);
if(doLoad) {
return Forward(inputs, anyArgs);
}
if (inputs[0].ttype() == TensorType::INPUT_TENSOR) {
for (auto &input : inputs) {
input.setTtype(TensorType::NORMAL_TENSOR);
Expand All @@ -68,36 +83,16 @@ class Module {

Forward(inputs, anyArgs);
for (auto &input : inputs) {
input.status() = TENSOR_STATIC_SHAPED;
}
tensor_status = TENSOR_STATIC_SHAPED;

Forward(inputs, anyArgs);
for (auto &input : inputs) {
input.status() = TENSOR_STATIC_ALLOCED;
input.status() = TENSOR_STATIC_READY;
}
tensor_status = TENSOR_STATIC_ALLOCED;
tensor_status = TENSOR_STATIC_READY;

return Forward(inputs, anyArgs);
} else {
return Forward(inputs, anyArgs);
}
}

// vector<Tensor> call(vector<Tensor> inputs, vector<std::any> args) {
// return operator()(inputs, args);
// }

// template <typename T>
// static vector<T *> List(int n) {
// static_assert(std::is_base_of<Module, T>::value, "T must be a subclass of Module");
//
// vector<T *> modules;
// for (int i = 0; i < n; i++) {
// modules.push_back(new T());
// }
// return modules;
// }
static int listIdx;
static int runlistIdx;

Expand Down
Loading
Loading