Python bindings for ggml
ℹ️ Note this is a fork of the original project which hasn't been updated since July 2024. There have been a number of CVE security patches for
ggml / llama.cppsince that date. This fork updatesggmlto the latest. See the llama.cpp security page for more on this.
Python bindings for the ggml tensor library for machine learning.
Installation
Requirements
- Python 3.10+
- C compiler (gcc, clang, msvc, etc)
You can install ggml-py using pip:
pip install ggml-py
This will compile ggml using cmake which requires a c compiler installed on your system.
To build ggml with specific features (ie. OpenBLAS, GPU Support, etc) you can pass specific cmake options through the cmake.args pip install configuration setting. For example to install ggml-py with cuBLAS support you can run:
pip install --upgrade pip
pip install ggml-py --config-settings=cmake.args='-DGGML_CUDA=ON'
Options
| Option | Description | Default |
|---|---|---|
GGML_CUDA |
Enable cuBLAS support | OFF |
GGML_CLBLAST |
Enable CLBlast support | OFF |
GGML_OPENBLAS |
Enable OpenBLAS support | OFF |
GGML_METAL |
Enable Metal support | OFF |
GGML_RPC |
Enable RPC support | OFF |
Usage
import ggml
import ctypes
# Allocate a new context with 16 MB of memory
params = ggml.ggml_init_params(mem_size=16 * 1024 * 1024, mem_buffer=None)
ctx = ggml.ggml_init(params)
# Instantiate tensors
x = ggml.ggml_new_tensor_1d(ctx, ggml.GGML_TYPE_F32, 1)
a = ggml.ggml_new_tensor_1d(ctx, ggml.GGML_TYPE_F32, 1)
b = ggml.ggml_new_tensor_1d(ctx, ggml.GGML_TYPE_F32, 1)
# Use ggml operations to build a computational graph
x2 = ggml.ggml_mul(ctx, x, x)
f = ggml.ggml_add(ctx, ggml.ggml_mul(ctx, a, x2), b)
gf = ggml.ggml_new_graph(ctx)
ggml.ggml_build_forward_expand(gf, f)
# Set the input values
ggml.ggml_set_f32(x, 2.0)
ggml.ggml_set_f32(a, 3.0)
ggml.ggml_set_f32(b, 4.0)
# Compute the graph
ggml.ggml_graph_compute_with_ctx(ctx, gf, 1)
# Get the output value
output = ggml.ggml_get_f32_1d(f, 0)
assert output == 16.0
# Free the context
ggml.ggml_free(ctx)
Troubleshooting
If you are having trouble installing ggml-py or activating specific features please try to install it with the --verbose and --no-cache-dir flags to get more information about any issues:
pip install ggml-py --verbose --no-cache-dir --force-reinstall --upgrade
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for ggml-py 0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ggml_py-0.10.1.tar.gz | 2.9 MB | Without provenance | Details |
Release files / ggml_py-0.10.1.tar.gz
| Download URL | ggml_py-0.10.1.tar.gz |
|---|---|
| Size | 2.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77e840e8b87c319456331296333c641bc96232076dac00bb6b4563ab9422c71a
|
|
BLAKE2b-256 checksum How to use checksums |
8bc58bc941b59a8afc3be7c39f0b929970e902af8ceb86d8f10b84f64c1cde3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.20
|
Security for ggml-py 0.10.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.