Skip to content

Bug in buffer protocol implementation #405

Open

Description

@mariosasko

While inspecting the code, I noticed a small bug in the buffer protocol implementation - the buffer's .shape is equal to num_tokens * buffer.itemsize, but instead it should be num_tokens to ensure math.prod(buffer.shape) * buffer.itemsize == len(buffer) afterward, as per the official spec. This then leads to memoryview(buffer).tolist() returning an incorrect result. Luckily, NumPy ignores the .shape (unlike CPython) and builds the result using len(buffer) // buffer.itemsize.

Even though the encode_to_tiktoken_buffer API is somewhat private, this bug is probably still worth fixing to follow the spec 😃.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions