PyTensorForge
PyTensorForge is a machine learning framework. It provides a modular core for tensor operations, neural network layers, activation functions, optimizers, loss metrics, and model definitions. It is designed to build and train enterprise-level models for computer vision, forecasting, LLM, NLP, etc.
PyTensorForge is also designed for learning, experimentation, and rapid prototyping
Key Features
- Core tensor and scalar abstractions for numerical computation
- Layer-based neural network support with dense and sequential model building
- Common activation functions such as ReLU, Sigmoid, Tanh, ELU, and SELU
- Standard optimization algorithms with SGD and batch optimization
- Loss functions including mean squared error, mean absolute error, and binary cross-entropy
- Weight initialization utilities with Glorot, He, LeCun, and zeros initializers
- Model implementations for regression and logistic classification
Project Structure
src/core/– Tensor, scalar, matrix, and vector primitivessrc/neural/– Neural layer abstractions, parameters, and dense layerssrc/activations/– Activation function implementationssrc/optimizer/– Optimizer base classes and SGD implementationsrc/loss/– Loss function abstractions and implementationssrc/initializers/– Weight initializer utilitiessrc/models/– High-level model APIs for regression, classification, and sequential modelssrc/scaling/– Data scaling utilitiessrc/models/gpt/– decoder-only GPT Transformer (seePHASE1_GPT_TRAINING.md)src/data/,src/training/– streaming corpora, token shards, resumable trainer (PHASE1_GPT_TRAINING.md,PHASE2_DATA_PIPELINE.md)src/tokenization/– tokenizer abstraction, word-level and byte-level BPE (TOKENIZER.md)src/inference/– KV-cache inference runtime, continuous batching, chat templates (PHASE3_INFERENCE.md)src/serving/– OpenAI-compatible HTTP/SSE model server (PHASE4_SERVING.md)- RoPE, activation checkpointing, bf16/fp16 numerics, parallel tokenization (
PHASE5_TRAINING_EFFICIENCY.md) - Context extension for RoPE models: extrapolate, linear, NTK (
PHASE6_CONTEXT_EXTENSION.md) - Fine-tuning (
init_from) and chat training with assistant-only loss masking (PHASE7_FINETUNING.md) web/– TypeScript chat web client (prebuilt inweb/dist)predict/– Prediction utilities and example datasetstest/– Unit tests and example usage scripts
Installation
-
Clone the repository:
git clone https://github.com/philipsz-davido/PyTensorForge.git cd PyTensorForge
-
Install dependencies:
pip install -e .
This installs the
pytensorforgecommand (train,resume,evaluate,inspect,tokenize,prepare-dataset,generate,export,serve). Runtime dependencies arenumpyandpyyamlonly.
Note: This repository is intended for educational use and may require additional dependencies depending on the development environment.
Usage
Import components from the package and build models using the provided modules. Example:
from src.neural.Dense import Dense
from src.neural.Layer import Layer
from src.optimizers.SGD import SGD
from src.loss.MSE import MSE
Refer to the test/ directory for example scripts and usage patterns.
Serving a trained model:
pytensorforge export checkpoints/latest --output exports/my-gpt --tokenizer tokenizer/ --chat-template ptf-chat
pytensorforge serve exports/my-gpt --name my-gpt --api-key-file api_keys.txt
Then open http://127.0.0.1:8000/ or point any OpenAI-compatible client at
http://127.0.0.1:8000/v1. See serve.example.yaml and PHASE4_SERVING.md.
Contribution
Contributions are welcome. Please open an issue or submit a pull request for feature requests, bug fixes, or documentation improvements.
License
This project is provided under the terms of the repository license. Check the project root for license details.
Metadata
Release files for pytensorforge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytensorforge-0.1.0.tar.gz | 96.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytensorforge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 225.8 kB
Release files / pytensorforge-0.1.0.tar.gz
| Download URL | pytensorforge-0.1.0.tar.gz |
|---|---|
| Size | 96.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8de678d9ffc7c43115efae16a1c451bad0a279f3897dd7dd17b76662b89b7d5e
|
|
BLAKE2b-256 checksum How to use checksums |
6c6a4a751d328837f2fffa6c1efc8032c3bc7f632e17270751de789ffa47728e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / pytensorforge-0.1.0-py3-none-any.whl
| Download URL | pytensorforge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 129.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
764b517a4160442d69e2ff04ca74e320d63ac13c485db2f644da18924b9035ae
|
|
BLAKE2b-256 checksum How to use checksums |
9ad936621b61c4abad3b0b55c26ef29e18073bb91f795372c9807566cc5418fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|