Skip to content

Commit

Permalink
readme中增加llama.c
Browse files Browse the repository at this point in the history
  • Loading branch information
shenshen.fu committed Feb 29, 2024
1 parent c3bcdf6 commit 4ec6ffb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

**视频课程链接:**[https://space.bilibili.com/1822828582](https://space.bilibili.com/1822828582)

## 对llama的支持
> 我们将[llama.c](https://github.com/karpathy/llama2.c )中的算子替换为了KuiperInfer中的实现
模型下载地址

链接:https://pan.baidu.com/s/1PF5KqvIvNFR8yDIY1HmTYA?pwd=ma8r

![a.gif](imgs/a.gif)

## 第二次课程大纲

第二次课程是第一次课程的重置版,内容更加充实和完善,第一次课程大纲见下方章节。
Expand Down
12 changes: 6 additions & 6 deletions demos/llama2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)

#if (MSVC)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
#else ()
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fopenmp -march=native")
#endif ()
#set(CMAKE_BUILD_TYPE Release)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fopenmp -march=native")
endif ()
set(CMAKE_BUILD_TYPE Release)
add_executable(llama_chat llama_chat.cpp main.cpp)
target_link_directories(llama_chat PUBLIC ${PROJECT_SOURCE_DIR}/lib)
target_link_libraries(llama_chat ${OpenCV_LIBS} kuiper)
Expand Down
Binary file added imgs/a.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions source/layer/details/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ StatusCode LLamaMatmulLayer::Forward(const std::vector<std::shared_ptr<Tensor<fl
#pragma omp parallel for
for (int j = 0; j < weight_dim0_; ++j) {
arma::fmat sub_weight(weight_ptr + j * weight_dim1_, weight_dim1_, 1, false, true);
arma::fmat output_mat(output_ptr + j, 1, 1, false, true);
output_mat = input_vec * sub_weight;
*(output_ptr + j) = as_scalar(input_vec * sub_weight);
}
} else if (weight_dim0_ == 1) {
arma::fmat output_mat(output->raw_ptr(), input_dim1, weight_dim0_, false, true);
Expand Down
26 changes: 26 additions & 0 deletions test/test_layer/test_softmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ TEST(test_layer, forward_softmax_dim01) {
}
}


TEST(test_layer, forward_softmax_dim011) {
using namespace kuiper_infer;
SoftmaxLayer softmax_layer(0);
uint32_t size = 97;
std::vector<float> values;
for (uint32_t i = 0; i < size; ++i) {
values.push_back(float(i));
}

const uint32_t batch_size = 1;
std::vector<sftensor> inputs;

sftensor input = std::make_shared<ftensor>(97);
input->Fill(values);

std::vector<sftensor> outputs(1);
inputs.push_back(input);
softmax_layer.Forward(inputs, outputs);
softmax1(values.data(), values.size());
for (int i = 0; i < size; ++i) {
ASSERT_EQ(input->index(i), float(i));
ASSERT_NEAR(values.at(i), outputs.front()->index(i), 1e-3f);
}
}

TEST(test_layer, forward_softmax_dim02) {
using namespace kuiper_infer;
SoftmaxLayer softmax_layer(0);
Expand Down

0 comments on commit 4ec6ffb

Please sign in to comment.