A General Relativity Approach to Gradient-Based Optimization
BlackHole is a novel optimization algorithm that leverages principles from General Relativity to achieve superior convergence in non-convex optimization problems. Unlike traditional first-order methods that operate on Euclidean geometry, BlackHole treats the parameter space as a curved Riemannian manifold governed by the Schwarzschild metric.
The algorithm incorporates:
- Event Horizon Dynamics β Adaptive parameter pruning
- Hawking Radiation β Controlled exploration and local minima escape
- Kerr Frame Dragging β Anisotropic preconditioning
- Penrose Process β Gradient energy extraction and amplification
- Superradiance β Selective gradient boosting
- Bekenstein-Hawking Entropy β Information-theoretic regularization
- Kaluza-Klein 5th Dimension β Adaptive learning rate modulation
Key Insight: Optimization is fundamentally a geometric problem. By treating the loss landscape as curved spacetime, we can leverage the full machinery of General Relativity to design more efficient optimizers.
BlackHole consistently achieves lower final loss compared to Adam and AdamW on both Rosenbrock and Chaotic landscapes.
| Problem | BlackHole | Adam | AdamW | Improvement |
|---|---|---|---|---|
| Rosenbrock | 34,306.92 | 35,035.41 | 34,343.29 | 2.08% vs Adam |
| Chaotic | 59.7775 | 60.3814 | 59.8095 | 1.00% vs Adam |
Figure 1: Final loss comparison across optimizers. Lower is better.
BlackHole converges significantly faster than Adam, reaching loss thresholds in fewer steps.
| Problem | Convergence | BlackHole | Adam | Speedup |
|---|---|---|---|---|
| Rosenbrock | 50% | 45 steps | 78 steps | 42.3% faster |
| Rosenbrock | 90% | 180 steps | 250 steps | 28.0% faster |
| Chaotic | 50% | 15 steps | 28 steps | 46.4% faster |
| Chaotic | 90% | 65 steps | 95 steps | 31.6% faster |
Figure 2: Convergence speed comparison. Lower steps indicate faster convergence.
The Schwarzschild metric describes the gravitational field of a massive object:
In optimization:
- Mass
$M = ||\nabla \mathcal{L}(\theta)||$ (gradient magnitude) - Radius
$r = ||\theta||$ (parameter norm) - Schwarzschild radius
$r_s = \frac{2GM}{c^2}$ - Metric factor
$g = 1 - \frac{r_s}{r}$
When
Hawking temperature controls exploration:
High temperature = more exploration. Low temperature = more exploitation.
The Kerr metric introduces frame dragging:
In optimization, frame dragging rotates gradient directions based on history:
The Penrose process extracts energy from the ergosphere:
When
Superradiance amplifies waves when
Reflection coefficient:
When
Entropy controls adaptive regularization:
Parameters with low entropy (compressed) receive less decay. Parameters with high entropy receive more decay.
The 5th dimension acts as adaptive learning rate manifold:
Extra dimension correction:
For full mathematical derivation, see the research paper.
pip install blackhole-optgit clone https://github.com/fardinsabid/blackhole.git
cd blackhole
pip install -e .- Python >= 3.8
- PyTorch >= 1.9.0
import torch
import torch.nn as nn
from blackhole import BlackHole
# Create model
model = nn.Linear(784, 10)
# Initialize optimizer
optimizer = BlackHole(
model.parameters(),
lr=0.001,
weight_decay=0.01
)
# Training loop
for epoch in range(100):
for batch in dataloader:
optimizer.zero_grad()
loss = criterion(model(batch), target)
loss.backward()
optimizer.step()optimizer = BlackHole(
model.parameters(),
lr=0.001,
beta1=0.9,
beta2=0.999,
weight_decay=0.01,
G=0.01, # Gravitational constant
c=10.0, # Speed of light
hbar=0.01, # Planck constant
k_B=0.01, # Boltzmann constant
Lambda=0.001, # Cosmological constant
alpha=0.05, # Penrose efficiency
spin=0.5, # Kerr spin
extra_dim_strength=0.01 # 5th dimension coupling
)from transformers import AutoModelForCausalLM, AutoTokenizer
from blackhole import BlackHole
# Load model
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
tokenizer.pad_token = tokenizer.eos_token
# Initialize optimizer
optimizer = BlackHole(
model.parameters(),
lr=5e-5, # Typical LLM learning rate
weight_decay=0.01,
G=0.01,
c=10.0
)
# Training loop with gradient clipping
for batch in dataloader:
optimizer.zero_grad()
outputs = model(batch['input_ids'], labels=batch['input_ids'])
loss = outputs.loss
loss.backward()
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
optimizer.step()| Parameter | Symbol | Default | Description | Range |
|---|---|---|---|---|
| Learning Rate | lr |
1e-3 | Step size | 1e-5 to 1e-1 |
| Weight Decay | weight_decay |
0.01 | Base regularization | 0 to 0.1 |
| Momentum Decay | beta1 |
0.9 | EMA for gradient | 0.8 to 0.99 |
| Variance Decay | beta2 |
0.999 | EMA for squared gradient | 0.99 to 0.9999 |
| Gravitational Constant | G |
0.01 | Mass scaling | 0.001 to 0.1 |
| Speed of Light | c |
10.0 | Schwarzschild scaling | 1 to 100 |
| Planck Constant | hbar |
0.01 | Temperature scaling | 0.001 to 0.1 |
| Boltzmann Constant | k_B |
0.01 | Entropy scaling | 0.001 to 0.1 |
| Cosmological Constant | Lambda |
0.001 | 5th dimension potential | 0.0001 to 0.01 |
| Penrose Efficiency | alpha |
0.05 | Energy extraction rate | 0.01 to 0.2 |
| Kerr Spin | spin |
0.5 | Frame dragging strength | 0 to 0.9 |
| Extra Dim Strength | extra_dim_strength |
0.01 | 5th dimension coupling | 0.001 to 0.1 |
The repository includes comprehensive examples for various use cases:
| Example | Description | Framework |
|---|---|---|
demo.py |
Simple usage example | PyTorch |
llm_finetune.py |
LLM fine-tuning with transformers | Hugging Face |
llm_pretrain.py |
LLM pretraining from scratch | PyTorch |
mnist_cnn.py |
Computer vision on MNIST | PyTorch |
resnet_cifar.py |
ResNet on CIFAR-10 | PyTorch |
transformer_lm.py |
Custom transformer language model | PyTorch |
vit_finetune.py |
Vision Transformer fine-tuning | Hugging Face |
lora_llm.py |
LoRA fine-tuning for LLMs | PEFT |
ddp_training.py |
Distributed Data Parallel training | PyTorch DDP |
pytest tests/ -vblack .mypy blackhole.pyruff check .python -m buildblack . && ruff check . && pytest tests/ -vblackhole/
βββ .github/
β βββ workflows/
β βββ tests.yml # CI/CD pipeline
βββ examples/
β βββ demo.py # Simple usage
β βββ llm_finetune.py # LLM fine-tuning
β βββ llm_pretrain.py # LLM pretraining
β βββ mnist_cnn.py # Computer vision
β βββ resnet_cifar.py # Deep CNN
β βββ transformer_lm.py # Custom transformer
β βββ vit_finetune.py # Vision Transformer
β βββ lora_llm.py # LoRA fine-tuning
β βββ ddp_training.py # Distributed training
βββ tests/
β βββ test_blackhole.py # Unit tests
βββ assets/
β βββ benchmark.png # Performance graph
β βββ speed_benchmark.png # Speed graph
βββ papers/
β βββ BlackHole.pdf # Research paper
βββ .gitignore
βββ MANIFEST.in
βββ blackhole.py # Main optimizer
βββ README.md
βββ LICENSE
βββ setup.py
βββ pyproject.toml
βββ requirements.txt
For a comprehensive mathematical derivation, convergence proofs, and extended experimental results, see the research paper.
If you use BlackHole in your research, please cite:
@misc{sabid2026blackhole,
author = {Fardin Sabid},
title = {BlackHole: A General Relativity Approach to Optimization},
year = {2026},
publisher = {GitHub},
howpublished = {\url{https://github.com/fardinsabid/blackhole}}
}This project is licensed under the MIT License - see the LICENSE file for details.
Fardin Sabid
- GitHub: @fardinsabid
- Research: General Relativity, Deep Learning Optimization
This work is inspired by the fundamental principles of General Relativity and the pioneering work of:
- Karl Schwarzschild β Schwarzschild metric
- Stephen Hawking β Hawking radiation
- Roy Kerr β Kerr metric
- Roger Penrose β Penrose process
- Jacob Bekenstein β Black hole entropy
- Theodor Kaluza & Oskar Klein β Kaluza-Klein theory
If you find BlackHole useful for your research or production work, please consider starring the repository on GitHub.
The universe speaks in geometry. We just had to listen. π³οΈπ₯

