Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f8fb22f
Add Cargo.toml files for workspace and plonky3 library; update .gitig…
mdvillagra Sep 9, 2025
8d78de2
Fix path to plonky3 library in Cargo.toml
mdvillagra Sep 9, 2025
2accb76
Update .gitignore to include additional Cargo.lock and coverage files
mdvillagra Sep 9, 2025
d39571a
Refactor imports and improve code readability in plonky3 library. Adj…
mdvillagra Sep 9, 2025
2d979be
Update comments in MatrixMultiplicationAIR to clarify column indexing…
mdvillagra Sep 9, 2025
57e1a0f
Refactor matrix multiplication logic in plonky3 library to differenti…
mdvillagra Sep 9, 2025
295fecd
Correct typo in comment regarding column indexing in matrix multiplic…
mdvillagra Sep 9, 2025
899be3f
Add new fields to MatrixMultiplicationAIR struct for compression and …
mdvillagra Sep 10, 2025
711c478
Refactor dependencies in Cargo.toml to use Git sources for plonky3 li…
mdvillagra Sep 10, 2025
af374d8
Enhance matrix multiplication logic in MatrixMultiplicationAIR by add…
mdvillagra Sep 10, 2025
37f06ba
Refactor matrix multiplication assertions in plonky3 library to impro…
mdvillagra Sep 11, 2025
5badb34
Add vector-matrix multiplication function and corresponding test in p…
mdvillagra Sep 11, 2025
9bd9f36
Add vector-matrix multiplication function with detailed documentation…
mdvillagra Sep 11, 2025
bc08c4b
Refactor MatrixMultiplicationAIR to VectorMatrixMultiplicationAIR, up…
mdvillagra Sep 11, 2025
ee55de0
Implement eval method in VectorMatrixMultiplicationAIR for enforcing …
mdvillagra Sep 11, 2025
1ccb422
Enhance starting state assertions in VectorMatrixMultiplicationAIR by…
mdvillagra Sep 11, 2025
dc8f570
Enhance trace generation in VectorMatrixMultiplicationAIR by adding a…
mdvillagra Sep 12, 2025
204f0f1
Refine starting state assertions in VectorMatrixMultiplicationAIR by …
mdvillagra Sep 12, 2025
af2b0ac
Enhance final state assertions in VectorMatrixMultiplicationAIR by en…
mdvillagra Sep 12, 2025
75478c3
Enforce booleanity conditions in VectorMatrixMultiplicationAIR by add…
mdvillagra Sep 12, 2025
4d6d1af
Enhance VectorMatrixMultiplicationAIR by adding assertions to enforce…
mdvillagra Sep 14, 2025
3a8eeb2
Refine VectorMatrixMultiplicationAIR logic by adjusting the running s…
mdvillagra Sep 14, 2025
f9ac318
Update Cargo.toml to include bincode dependency and modify lib.rs to …
mdvillagra Sep 15, 2025
2cf7f34
Fix typo in comment and reorder imports in lib.rs for clarity and con…
mdvillagra Sep 15, 2025
2e8aeb2
Refactor matrix multiplication logic by removing the matrix_multiply …
mdvillagra Sep 15, 2025
f41268a
Add vector-matrix multiplication proof functionality with transformat…
mdvillagra Sep 15, 2025
978997a
Add vector-matrix multiplication proof verification functionality and…
mdvillagra Sep 15, 2025
bb46f11
Add zero-knowledge proof generation for vector-matrix multiplication …
mdvillagra Sep 15, 2025
c2ea414
Add Python bindings for vector-matrix multiplication proof functions …
mdvillagra Sep 15, 2025
abbce9a
Enhance proof generation by introducing a `zk_backend` parameter to s…
mdvillagra Sep 15, 2025
74c567e
Add ONNX export functionality for LoRA submodules and implement activ…
mdvillagra Sep 15, 2025
ece7fc3
Add asynchronous support for proof generation in Plonky3. Introduce `…
mdvillagra Sep 15, 2025
e75deca
Add README documentation for ZKLoRA project, including usage instruct…
mdvillagra Sep 16, 2025
51a3136
Add fixed point encoding and decoding functions for 16-bit floats in …
mdvillagra Sep 16, 2025
c29d12c
Fix variable name in vector-matrix multiplication assertion for clarity
mdvillagra Sep 16, 2025
4f2df36
Remove unused variables and print statements related to fixed point e…
mdvillagra Sep 16, 2025
5405bb1
Add fixed point encoding and decoding functions to `fp_coding.py` and…
mdvillagra Sep 16, 2025
9a2a59e
Refactor fixed point encoding and decoding functions in `fp_coding.py…
mdvillagra Sep 16, 2025
962b680
Refactor fixed point encoding usage in proof generation for Plonky3. …
mdvillagra Sep 16, 2025
3b8dc9a
Enhance proof generation by integrating fixed point encoding in vecto…
mdvillagra Sep 16, 2025
90ad85c
Fix matrix element ordering in trace data push for vector-matrix mult…
mdvillagra Sep 17, 2025
a6a7216
Fix matrix dimensions in vector-matrix multiplication tests and imple…
mdvillagra Sep 17, 2025
dbc136c
Add debug print statements to `generate_proofs` for matrix dimensions…
mdvillagra Sep 17, 2025
a7f4818
Update requirements: consolidate dependencies into `requirements.txt`…
mdvillagra Sep 17, 2025
3cbcbf4
Add detailed documentation for vector-matrix multiplication proof str…
mdvillagra Sep 18, 2025
511ac23
Refactor vector-matrix multiplication implementation by extracting th…
mdvillagra Oct 2, 2025
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ build/
*.whl
.pypirc
.coverage

# Specific Cargo.lock files to ignore
zklora/libs/Cargo.lock
Cargo.lock

.coverage
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"src/zklora/libs/plonky3"
]
resolver = "2"
File renamed without changes.
12 changes: 8 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
numpy
pytest
torch
transformers
torch>=2.0.0
transformers>=4.30.0
peft>=0.4.0
onnx>=1.14.0
onnxruntime>=1.15.0
numpy>=1.24.0
ezkl>=5.0.0
maturin>=1.9.4
7 changes: 0 additions & 7 deletions src/requirements.txt

This file was deleted.

24 changes: 16 additions & 8 deletions src/zklora/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
__version__ = "0.1.2"

from .zk_proof_generator import batch_verify_proofs
from .zk_proof_generator import generate_proofs
from .mpi_lora_onnx_exporter import export_lora_onnx_json_mpi
from .lora_contributor_mpi import LoRAServer, LoRAServerSocket
from .base_model_user_mpi import BaseModelClient
from .polynomial_commit import commit_activations, verify_commitment

from .lora_onnx_exporter import export_lora_submodules
from .fp_coding import fixed_point_encode, fixed_point_decode

__all__ = [
"batch_verify_proofs",
"LoRAServer",
"LoRAServerSocket",
"BaseModelClient",
"commit_activations",
"verify_commitment",
"__version__",
'batch_verify_proofs',
'generate_proofs',
'export_lora_onnx_json_mpi',
'export_lora_submodules',
'fixed_point_encode',
'fixed_point_decode',
'LoRAServer',
'LoRAServerSocket',
'BaseModelClient',
'commit_activations',
'verify_commitment',
'__version__',
]
88 changes: 88 additions & 0 deletions src/zklora/fp_coding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import numpy as np

def fixed_point_encode(x, fractional_bits: int = 10, total_bits: int = 32):
"""Encode floating-point values to *signed* fixed-point two's complement integers.

Parameters
----------
x : array-like or scalar
Values convertible to ``np.float16``.
fractional_bits : int, default ``10``
Number of bits reserved for the fractional part of the fixed-point number.
total_bits : int, default ``32``
Total bit-width of the resulting fixed-point integer. ``total_bits`` must be
large enough to accommodate the integer, fractional **and** sign bit. 32 is
a sensible default because we return ``np.uint32`` values.

Returns
-------
list[int]
Two's-complement encoded unsigned integers (``np.uint32``) representing the
input values at the requested precision.
"""

# Convert to higher precision float before scaling to avoid precision loss.
arr = np.asarray(x, dtype=np.float32)
multiplier = 2 ** fractional_bits

# Scale and round towards nearest integer.
fixed = np.round(arr * multiplier).astype(np.int64) # temporary wider type

# Check that the value fits in the desired bit-width (including sign bit).
max_val = (1 << (total_bits - 1)) - 1
min_val = -1 << (total_bits - 1)
if np.any(fixed > max_val) or np.any(fixed < min_val):
raise OverflowError(
f"Value out of range for {total_bits}-bit fixed-point representation"
)

# Convert to two's complement by masking – this yields an *unsigned* view of
# exactly the same bits.
fixed_twos = (fixed & ((1 << total_bits) - 1)).astype(np.uint32)

return fixed_twos.tolist()

# Fixed point decoding function for 16-bit floating point numbers from u32 fixed-point representation
def fixed_point_decode(y, fractional_bits: int = 10, total_bits: int = 32):
"""Decode signed fixed-point two's complement integers back to floats.

Parameters
----------
y : array-like or scalar
Unsigned integers (``np.uint32`` or compatible) storing two's-complement
fixed-point values produced by :func:`fixed_point_encode`.
fractional_bits : int, default ``10``
Number of fractional bits that were used during encoding.
total_bits : int, default ``32``
Total width of the stored integers. Must match the value passed to
:func:`fixed_point_encode`.

Returns
-------
list[np.float16]
The decoded floating-point values.
"""

arr_unsigned = np.asarray(y, dtype=np.uint32)

# Re-interpret the unsigned integers as signed two's complement.
signed = arr_unsigned.view(np.int32) if total_bits == 32 else arr_unsigned.astype(np.int64)

multiplier = 2 ** fractional_bits
decoded = signed.astype(np.float32) / multiplier
return decoded.astype(np.float16).tolist()

if __name__ == "__main__":
# Basic sanity check for the fixed-point codec.
test_values = np.array([-3.25, -1.5, -0.125, 0.0, 0.125, 1.5, 3.25], dtype=np.float32)

encoded = fixed_point_encode(test_values, fractional_bits=10)
decoded = np.array(fixed_point_decode(encoded, fractional_bits=10), dtype=np.float32)

# Expect equality within one LSB of the fractional part.
assert np.allclose(test_values, decoded, atol=1 / (2 ** 10)), (
f"Round-trip mismatch:\noriginal: {test_values}\ndecoded : {decoded}"
)

print("[fp_coding] Self-test passed for signed two's-complement encoding/decoding.")

5 changes: 5 additions & 0 deletions src/zklora/libs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"plonky3"
]
resolver = "2"
35 changes: 35 additions & 0 deletions src/zklora/libs/plonky3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "plonky3"
version = "0.1.0"
edition = "2021"

[lib]
name = "plonky3_py"
crate-type = ["cdylib"]

[dependencies]
rand = "0.8.5"
pyo3 = { version = "0.24.1", features = ["extension-module"] }

# plonky3 dependencies
p3-air = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-mersenne-31 = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-util = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-circle = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-dft = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-fri = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-blake3 = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-keccak = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-mds = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-poseidon = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git" }
p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3.git" }
bincode = { version = "2.0.1", features = ["serde"] }
Loading
Loading