-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#include "template.h" | ||
|
||
#include <string.h> | ||
|
||
int main(void) | ||
|
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,34 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/numpy.h> | ||
#include "template.h" // Include your header file | ||
|
||
namespace py = pybind11; | ||
|
||
PYBIND11_MODULE(bindings, m) { | ||
m.doc() = "Your module documentation string"; | ||
|
||
py::class_<module>(m, "Module") | ||
.def(py::init<>()) | ||
.def_readwrite("hparams", &module::hparams) | ||
// .def_readwrite("backend", &module::backend) | ||
// .def_readwrite("buffer_w", &module::buffer_w) | ||
.def_readwrite("fc_w", &module::fc_w) | ||
.def_readwrite("bias", &module::bias) | ||
// .def_readwrite("ctx", &module::ctx) | ||
.def_readwrite("tensors", &module::tensors); | ||
|
||
m.def("load_model", [](const std::string& fname) -> std::tuple<bool, py::object> { | ||
module model; | ||
bool success = load_model(fname, model); | ||
return std::make_tuple(success, success ? py::cast(model) : py::cast(nullptr)); | ||
}, "A function to load the model"); | ||
|
||
m.def("compute", [](const module& model, const std::vector<float>& input) { | ||
struct ggml_tensor* result = compute(model, input); | ||
std::vector<float> out_data(ggml_nelements(result)); | ||
memcpy(out_data.data(), result->data, ggml_nbytes(result)); | ||
// ggml_free(result); | ||
return out_data; | ||
}, "A function to compute using the loaded model"); | ||
} |
This file was deleted.
Oops, something went wrong.
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