diff --git a/src/Tensor.hpp b/src/Tensor.hpp index e5ab4a3b..e2124426 100644 --- a/src/Tensor.hpp +++ b/src/Tensor.hpp @@ -495,9 +495,48 @@ class Tensor { } } std::cout << name() << " " << sum / count() << std::endl; -// std::cout << name() << ": shape:[" << batch() << " " << head() << " " << sequence() << " " << dimension() << "] AVG:" << sum / count() << std::endl; +// std::cout << name() << ": shape:[" << num() << " " << channels() << " " << height() << " " << width() << "] AVG:" << sum / count() << std::endl; } + + + + shared_ptr view(int batch, int head, int sequence, int dimension) { + auto t = std::make_shared(); + t->setBackend(backend_); + t->setDtype(dtype_); + t->reshape(batch, head, sequence, dimension); + t->host_ptr_ = host_ptr_; + return t; + } + shared_ptr unfold(int axis, int size, int step) { + CHECK_GE(axis, 0); + CHECK_LT(axis, numAxes()); + CHECK_GE(size, 0); + CHECK_GE(step, 0); + CHECK_LE(size, shape(axis)); + CHECK_LE(step, shape(axis)); + CHECK_EQ(shape(axis) % step, 0); + auto t = std::make_shared(); + t->setBackend(backend_); + t->setDtype(dtype_); + vector shape = shape_; + shape[axis] = size; + shape.insert(shape.begin() + axis + 1, shape[axis] / step); + shape[axis + 1] = step; + t->reshape(shape); + t->host_ptr_ = host_ptr_; + return t; + } + +// +// void setByteWidth(int bw) { +// byte_width_ = bw; +// } + // TODO:Name? + + + template void fullData(Dtype value) { for (int n = 0; n < batch(); ++n) { diff --git a/src/backends/cpu/CPUKVCache.hpp b/src/backends/cpu/CPUKVCache.hpp index 4b8c1866..380acc4b 100644 --- a/src/backends/cpu/CPUKVCache.hpp +++ b/src/backends/cpu/CPUKVCache.hpp @@ -22,6 +22,7 @@ class CPUKVCache final : public Op { private: bool support_multi_thread_ = false; + int cache_seq_len_= -999; bool isK_;