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

remove ggml_cpy_inplace and ggml_cont_inplace, close ggerganov#622 #693

Merged
merged 1 commit into from
Jan 11, 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
23 changes: 2 additions & 21 deletions examples/python/ggml/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,6 @@ class lib:
struct ggml_tensor * a);
"""
...
def ggml_cont_inplace(ctx: ffi.CData, a: ffi.CData) -> ffi.CData:
"""
make contiguous, in-place

GGML_API struct ggml_tensor * ggml_cont_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a);
"""
...
def ggml_conv_1d(ctx: ffi.CData, a: ffi.CData, b: ffi.CData, s0: int, p0: int, d0: int) -> ffi.CData:
"""
GGML_API struct ggml_tensor * ggml_conv_1d(
Expand Down Expand Up @@ -614,16 +605,6 @@ class lib:
struct ggml_tensor * b);
"""
...
def ggml_cpy_inplace(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
"""
a -> b, in-place, return view(b)

GGML_API struct ggml_tensor * ggml_cpy_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b);
"""
...
def ggml_cross_entropy_loss(ctx: ffi.CData, a: ffi.CData, b: ffi.CData) -> ffi.CData:
"""
GGML_API struct ggml_tensor * ggml_cross_entropy_loss(
Expand Down Expand Up @@ -1202,7 +1183,7 @@ class lib:
- you don't need to keep the host memory buffer allocated as it is never accessed by Metal
- max_size specifies the maximum size of a tensor and is used to create shared views such
that it is guaranteed that the tensor will fit in at least one of the views


bool ggml_metal_add_buffer(
struct ggml_metal_context * ctx,
Expand Down Expand Up @@ -2428,4 +2409,4 @@ class lib:
...
def quantize_row_q8_K_reference(x: ffi.CData, y: ffi.CData, k: int) -> None:
"""void quantize_row_q8_K_reference(const float * restrict x, block_q8_K * restrict y, int k);"""
...
...
2 changes: 1 addition & 1 deletion examples/python/ggml/cffi.py

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions include/ggml/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -1163,22 +1163,11 @@ extern "C" {
struct ggml_tensor * a,
struct ggml_tensor * b);

// a -> b, in-place, return view(b)
GGML_API struct ggml_tensor * ggml_cpy_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b);

// make contiguous
GGML_API struct ggml_tensor * ggml_cont(
struct ggml_context * ctx,
struct ggml_tensor * a);

// make contiguous, in-place
GGML_API struct ggml_tensor * ggml_cont_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a);

// make contiguous, with new shape
GGML_API struct ggml_tensor * ggml_cont_1d(
struct ggml_context * ctx,
Expand Down
30 changes: 8 additions & 22 deletions src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -4311,13 +4311,13 @@ struct ggml_tensor * ggml_set_2d_inplace(
static struct ggml_tensor * ggml_cpy_impl(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b,
bool inplace) {
struct ggml_tensor * b) {
GGML_ASSERT(ggml_nelements(a) == ggml_nelements(b));

bool is_node = false;

if (!inplace && (a->grad || b->grad)) {
if (a->grad || b->grad) {
// inplace is false and either one have a grad
is_node = true;
}

Expand All @@ -4341,29 +4341,21 @@ struct ggml_tensor * ggml_cpy(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b) {
return ggml_cpy_impl(ctx, a, b, false);
}

struct ggml_tensor * ggml_cpy_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a,
struct ggml_tensor * b) {
return ggml_cpy_impl(ctx, a, b, true);
return ggml_cpy_impl(ctx, a, b);
}

// ggml_cont

static struct ggml_tensor * ggml_cont_impl(
struct ggml_context * ctx,
struct ggml_tensor * a,
bool inplace) {
struct ggml_tensor * a) {
bool is_node = false;

if (!inplace && a->grad) {
if (a->grad) {
is_node = true;
}

struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
struct ggml_tensor * result = ggml_dup_tensor(ctx, a);
ggml_format_name(result, "%s (cont)", a->name);

result->op = GGML_OP_CONT;
Expand All @@ -4376,13 +4368,7 @@ static struct ggml_tensor * ggml_cont_impl(
struct ggml_tensor * ggml_cont(
struct ggml_context * ctx,
struct ggml_tensor * a) {
return ggml_cont_impl(ctx, a, false);
}

struct ggml_tensor * ggml_cont_inplace(
struct ggml_context * ctx,
struct ggml_tensor * a) {
return ggml_cont_impl(ctx, a, true);
return ggml_cont_impl(ctx, a);
}

// make contiguous, with new shape
Expand Down