Skip to main content

High-performance hyperbolic neural networks library powered by Rust

Project description

Reality Stone: 완전한 AGI 아키텍처

Reality Stone은 벨만-리만 통합 이론, 하이퍼볼릭 기하학, 계층적 LLM을 결합한 차세대 AGI 아키텍처입니다.

핵심 철학

단일 원리: 최소 작용의 원리 (Principle of Least Action)

모든 사고와 학습 과정을 하나의 물리 법칙으로 통합:

δ∫L dt = 0

여기서 라그랑지안 L은:

L = (운동 에너지) - (잠재 에너지)
  = (1/2) g_μν ẋ^μ ẋ^ν - (-Q*(x) + V_reg(x,g))

핵심 혁신

  1. 벨만 방정식을 좌표계로: 강화학습의 가치 함수를 신경망의 기본 좌표계로 사용
  2. 리만 메트릭을 공간 구조로: 학습 가능한 기하학적 구조로 계층 관계 자연스럽게 표현
  3. 라그랑지안을 최적화 원리로: 물리적 최소작용원리로 측지선 경로 탐색
  4. 3개 하이퍼볼릭 레이어 병렬: Poincaré, Lorentz, Klein 모델 동시 활용
  5. 시간축 창의성: 시간 미분으로 창의성 정량화
  6. 자연 그라디언트: Fisher 정보 행렬 기반 최적화

성능 목표

  • 압축률: 2-3배 (860억 → 340억 파라미터)
  • 학습 속도: 2-3배 빠른 수렴
  • 추론 능력: 1.2-1.5배 향상 (동일 데이터 조건)
  • 계층적 추론: 1.4-2.0배 향상

현재 릴리스: 0.2.0, 라이선스: MIT, Python 3.8–3.12, PyTorch 2.0+ 지원.

아키텍처 계층

Reality Stone AGI는 7개 계층으로 구성됩니다:

Level 0: 물리적 기반 (최소 작용의 원리)
    ↓
Level 1: 벨만 좌표계 (강화학습 통합)
    ↓
Level 2: 리만 메트릭 (학습 가능한 기하학)
    ↓
Level 3: 3개 하이퍼볼릭 레이어 (Poincaré, Lorentz, Klein)
    ↓
Level 4: 계층적 LLM (Sentence-Topic 구조)
    ↓
Level 5: 라그랑지안 최적화 (에너지 최소화)
    ↓
Level 6: 시간축 창의성 (시간 미분)
    ↓
Level 7: 자연 그라디언트 (Fisher 정보)

주요 기능

1. 벨만-리만 통합

  • BellmanCoordinateSystem: 가치 함수 기반 좌표계
  • RiemannianMetricTensor: 상태 의존적 메트릭 학습
  • LagrangianEnergySystem: 물리적 에너지 최소화
  • TemporalCreativityModule: 시간 미분 창의성 측정

2. 하이퍼볼릭 기하학 (Rust + CUDA)

  • 3개 모델 병렬: Poincaré, Lorentz, Klein
  • 고성능 커널: CUDA 최적화 (10-100배 가속)
  • 동적 곡률: 레이어별 학습 가능한 곡률
  • 모델 변환: 3개 기하학 간 seamless 변환

3. 계층적 LLM

  • Tree Processor: Bottom-up & Top-down 메시지 패싱
  • Sentence-Topic Head: 문장-주제 계층 구조
  • Metric Attention: SPD 메트릭 기반 어텐션
  • Structural Edit: 문장 구조 편집 (Replace/Insert/Delete/Reorder)
  • Top-Down Decoder: 계층적 생성

4. 최적화

  • Natural Gradient: Fisher 정보 행렬 기반
  • 배치 고유값 분해: 100배 속도 향상
  • Fast SPD Mixing: 10-100배 속도 향상
  • Mixed Precision: FP16 학습 지원

설치 및 빌드

사전 준비물

  • Python 3.8 이상, pip
  • Rust toolchain (stable), Cargo
  • PyTorch 2.0 이상
  • CUDA 사용 시: NVIDIA CUDA Toolkit 설치, 환경 변수 CUDA_HOME 또는 CUDA_PATH 설정

가상환경 생성 및 필수 패키지 설치

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt

CPU 전용 빌드

maturin develop
python -c "import reality_stone as rs; print(rs._has_rust_ext, rs._has_cuda)"

CUDA 빌드

export CUDA_HOME=/usr/local/cuda   # Windows: set CUDA_PATH=C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.x
maturin develop --features cuda --release
python -c "import reality_stone as rs; print(rs._has_rust_ext, rs._has_cuda)"

주의: 기본 CUDA 아키텍처 플래그는 sm_70입니다. 다른 GPU를 사용한다면 build.rs-arch=sm_70을 환경에 맞게 수정하세요.

빠른 시작

1. 설치

git clone https://github.com/jigglypop/reality_stone.git
cd reality_stone
python -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt

maturin develop --release

maturin develop --features cuda --release

2. 완전한 AGI 모델

from reality_stone.models.agi import RealityStoneAGI, AGIConfig

config = AGIConfig(
    state_dim=128,
    action_dim=10,
    hidden_dim=256,
    num_layers=4,
    num_topics=8,
    use_encryption=True,
    enable_top_down=True,
    enable_structural_edit=True
)

model = RealityStoneAGI(config)

state = torch.randn(16, 128)
action = torch.randn(16, 10)
key = torch.randn(16, 32)

outputs = model(state, action, key, return_all=True)

print(f"Value: {outputs['value']}")
print(f"Policy: {outputs['policy']}")
print(f"Creativity: {outputs['creativity']}")
print(f"Lagrangian Loss: {outputs['lagrangian_loss']}")

3. 계층적 LLM

from reality_stone.models.hierarchical_sentence_topic_llm import (
    HierarchicalLLMConfig,
    train_hierarchical_llm_from_text
)

config = HierarchicalLLMConfig(
    d_model=128,
    num_topics=8,
    use_fast_spd_mixing=True,
    enable_top_down=True,
    enable_structural_edit=True
)

model, info = train_hierarchical_llm_from_text(
    data_path="data/text.txt",
    config=config,
    epochs=10,
    batch_size=4
)

4. 하이퍼볼릭 레이어

import torch
import reality_stone as rs

u = torch.randn(4, 8)
v = torch.randn(4, 8)
y = rs.poincare_ball_layer(u, v, c=1e-3, t=0.7)

x = torch.randn(2, 4)
y = torch.randn(2, 4)
d = rs.poincare_distance(x, y, c=1e-3)
xL = rs.poincare_to_lorentz(x, c=1e-3)

5. 데모 실행

python examples/bellman_riemannian_demo.py

python examples/train_on_real_data.py

python -m tests.poincare --quick
python -m tests.lorentz --quick
python -m tests.klein --quick

프로젝트 구조

reality_stone/
├── docs/                               # 문서
│   ├── COMPLETE_AGI_ARCHITECTURE.md   # ⭐ 완전한 AGI 아키텍처
│   ├── AGI_IMPLEMENTATION_ROADMAP.md  # ⭐ 구현 로드맵
│   ├── CORE_EQUATIONS.md              # 핵심 수식
│   ├── IMPLEMENTATION_GUIDE.md        # 구현 가이드
│   ├── BELLMAN_RIEMANNIAN_SUMMARY.md  # 요약
│   ├── unified_geometric_agi_architecture.md  # 통합 조감도
│   └── ...
├── src/                                # Rust 코어
│   ├── layers/                         # 하이퍼볼릭 레이어
│   │   ├── poincare.rs
│   │   ├── lorentz.rs
│   │   ├── klein.rs
│   │   └── cuda/                       # CUDA 커널
│   ├── ops/                            # 연산자
│   └── bindings/                       # PyO3 바인딩
├── python/reality_stone/               # Python API
│   ├── models/                         # 모델
│   │   ├── agi.py                      # ⭐ 통합 AGI 모델
│   │   ├── hierarchical_sentence_topic_llm.py  # 계층적 LLM
│   │   ├── bellman.py                  # 벨만 좌표계
│   │   └── ...
│   ├── layers/                         # Autograd 레이어
│   └── optimizers/                     # 최적화기
├── examples/                           # 예제
│   ├── bellman_riemannian_demo.py
│   ├── train_on_real_data.py
│   └── ...
└── tests/                              # 테스트

데이터 플로우

Python Input
    ↓
벨만 좌표 인코딩
    ↓
리만 메트릭 계산
    ↓
[Poincaré] ← PyO3 → Rust/CUDA
[Lorentz]  ← PyO3 → Rust/CUDA  (병렬)
[Klein]    ← PyO3 → Rust/CUDA
    ↓
메트릭 가중 결합
    ↓
계층적 LLM 처리
    ↓
라그랑지안 최적화
    ↓
시간 미분 (창의성)
    ↓
자연 그라디언트 업데이트
    ↓
Output (Value + Policy + Generated Text)

API 개요 (Python)

상위 함수

  • poincare_ball_layer(u, v, c, t)
  • lorentz_layer(u, v, c, t)
  • klein_layer(u, v, c, t)

거리/변환

  • poincare_distance(x, y, c)
  • poincare_to_lorentz(x, c), poincare_to_klein(x, c)
  • lorentz_to_poincare(x, c), lorentz_to_klein(x, c)
  • klein_to_poincare(x, c), klein_to_lorentz(x, c)

레이어

  • PoincareBallLayer, LorentzLayer, KleinLayer
  • 하이퍼볼릭 선형 변형: HyperbolicLinear, GeodesicLinear, EquivalentHyperbolicLinear
  • 압축: SplineLinear

기타

  • 투영: project_to_ball(x, epsilon)
  • 메트릭 합성: from reality_stone import metrikey (SPD 메트릭/합성/암시적 변환 함수 제공)

테스트 실행

벨만-리만 데모

python examples/bellman_riemannian_demo.py

하이퍼볼릭 레이어 테스트

python -m tests.poincare --mode both --quick --epochs 2 --batch-size 256
python -m tests.lorentz  --quick --epochs 2 --batch-size 256
python -m tests.klein    --quick --epochs 2 --batch-size 256

공통 옵션: --device {auto,cpu,cuda}, --data-dir tests/data, --epochs, --batch-size, --lr, --t, --c, --quick, --seed

문제 해결

  • Rust 확장 모듈을 찾지 못함: maturin develop로 빌드 후 다시 시도하세요.
  • CUDA가 비활성으로 표시됨: CUDA_HOME/CUDA_PATH 확인, GPU 드라이버/Toolkit 설치 상태 점검, CUDA 피처로 빌드했는지 확인.
  • Windows 빌드: Visual C++ Build Tools 설치 필요. PowerShell 대신 CMD/Developer Prompt 또는 Git Bash 사용 가능.
  • CUDA 아키텍처 오류: build.rs-arch=sm_70을 환경에 맞게 수정.
  • NumPy 2.x와의 호환성: 현재 numpy>=1.21,<2.0을 사용합니다.

변경 사항 요약 (v0.2.0)

새로운 기능 (벨만-리만 통합)

  • 벨만-리만 통합 아키텍처: 벨만 방정식, 리만 기하학, 라그랑지안 역학 통합
  • 핵심 수식 문서화: docs/CORE_EQUATIONS.md - 모든 핵심 수식과 이론적 근거
  • 구현 가이드: docs/IMPLEMENTATION_GUIDE.md - 모듈별 상세 구현 방법
  • 데모 예제: examples/bellman_riemannian_demo.py - 실행 가능한 완전한 데모
  • BellmanCoordinateSystem: 벨만 방정식을 좌표계로 사용
  • RiemannianMetricTensor: 상태 의존적 메트릭 학습 + 암호화
  • LagrangianEnergySystem: 라그랑지안 기반 최적화
  • TemporalCreativityModule: 시간 미분으로 창의성 측정
  • NaturalGradientOptimizer: Fisher 정보 행렬 기반 최적화

기존 기능 개선

  • Poincaré/Lorentz/Klein 레이어 및 연산의 Python Autograd 경로 정비
  • 동적/레이어별 곡률 API 추가: poincare_ball_layer_layerwise_cpu 및 정확한 backward
  • 스플라인 압축 레이어 SplineLinear 추가 및 from_linear 최적화 파이프라인 도입
  • 하이퍼볼릭 선형 변형 레이어군 추가: HyperbolicLinear, GeodesicLinear, EquivalentHyperbolicLinear
  • metrikey 서브모듈 공개: SPD 메트릭 합성/적용, 암시적 변환 체인

성능 예측

  • 압축률: 2-3배 (860억 → 340억 파라미터)
  • 학습 속도: 2-3배 (Natural Gradient + 라그랑지안)
  • 추론 능력: 1.2-1.5배 (동일 데이터 조건)

라이선스

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reality_stone-0.2.5.tar.gz (767.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

reality_stone-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

reality_stone-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

reality_stone-0.2.5-cp312-cp312-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

reality_stone-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

reality_stone-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

reality_stone-0.2.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

reality_stone-0.2.5-cp311-cp311-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

reality_stone-0.2.5-cp311-cp311-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

reality_stone-0.2.5-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

reality_stone-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

reality_stone-0.2.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

reality_stone-0.2.5-cp310-cp310-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

reality_stone-0.2.5-cp310-cp310-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file reality_stone-0.2.5.tar.gz.

File metadata

  • Download URL: reality_stone-0.2.5.tar.gz
  • Upload date:
  • Size: 767.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for reality_stone-0.2.5.tar.gz
Algorithm Hash digest
SHA256 8d21a06c3869638cb51d4249f9e82fe835f9a1a3863b5e2ae202c7b1c0caa0fe
MD5 5c430d4e16e94fda31f090450d58a5fc
BLAKE2b-256 07c0b3a09f90853aeeb4cdc0faaebdcfb02badfecc5c511aa4321e1401305748

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dac65dee3bc9b594255e520f887ef1048a40de46df50eb6c22f456df6a4bfbf3
MD5 53545639347c232dbd00ca775c0debf4
BLAKE2b-256 60f49749eab86176e41aa4a657b6ec498972dae41a73f7ab01cfeb1eb264d001

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cca7afb9fb971be411e620f53310e84beb8711c8c1e93a037c5a21e8dd8f4fd0
MD5 951a9414d3e58da622c346bf60d8a667
BLAKE2b-256 c81750dce7cb51a39c25d1b8c6a8be5b4defdcadb5aeba881fe850d92824bc73

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccb0ef34780f8779d0d1131de303b7684644fc11068cf88d5f0ba95d6145b29b
MD5 e88546b7c5fd0ac6b95b9c9444cfc1e8
BLAKE2b-256 a35425797ee6a5da5e37b23368bb3ca63d02df45bbe4ca2a36f4bd066058921d

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 31e0d9dcf7169bac92adbf446300551b30427500fe089b812088cc5456765b1e
MD5 1d2189c2a254018e386d8ec9a334c02e
BLAKE2b-256 503eef84a61bb6abe23bc9fdff04f08d7b2336ec327f0aad672b4822db15f2cb

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d0b0260fce5bcd3c0ee02f5092735646d6ea4c85ad8d356a9815493bc9d36b5a
MD5 a74dbd6ef87f8cd32e4a72b5afae0ba7
BLAKE2b-256 fa503a77595859b5f443729062933dcaa10228e4ce7ce81eba247e06e7bf9a7c

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8888f604670e5e985731c67ce61d5a2a7cf0433f836e58f915f07a24c8b36fff
MD5 417631d583ce82186102b75fd2816b65
BLAKE2b-256 a78bd9494bf0740be5e12f770ff2756017797d1a217d42695022c148627828b0

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 987f20e4f0a55323769672f57b3dc05334698821cafdce0fe2b377961735f9c2
MD5 3bf9217cc5bcad3fd0128191cf2e1488
BLAKE2b-256 88c932c15fa57d5e6dab8d645517a0922c3b5e5443428de6ed9ee66d6988e402

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 15f9d34f39d4843685f668aac61635caf56c00c25ace16eba6a5d26971d5e53e
MD5 652c0a47cd0fa2738d88af877c107d81
BLAKE2b-256 63d43e59130c9c6dc6c2a0d432c5298c3671f91364549124b8d0cfc0daeefbc1

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1e22ae3e9ce05906bc37c53dc1ad09403584accea2f1479e2a4864533201349f
MD5 233c1e3ceae18325e913458c6742386a
BLAKE2b-256 59cf56ecab71cfe6381f00047a3787d8d4a4b9c249504b2f6ea81b728a77c543

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e15ccb9582da4f71d98e20d428216832aeaa9716904ed8c1d02f9acbccf1d046
MD5 2a2a6f8aab797152e0a03ab581a28494
BLAKE2b-256 7de213663b5414da1e80bc879633932925bf3bdecc299729b0d37d15a016d56e

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52d1e5ca3cd105994827f2cdd8e9a14a68caf568cb8aae2ff0b3deedeef23102
MD5 e72b39450723dcf9b01a38e27b019b2f
BLAKE2b-256 7d9688b938e6cbfea1b6701700ec0bcda3b66f588a6a2c1f1bb1ba4adddebcdc

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2ca828c6e2230cd00d50f8a6e25645be15670f87c399d87eeb0f4f135083db1
MD5 51e6e5dd1fa1a371356c60e1e94c687d
BLAKE2b-256 623cc3195f555a1bc9d10313735f47fa439161e88022e869098d21375ba1a517

See more details on using hashes here.

File details

Details for the file reality_stone-0.2.5-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for reality_stone-0.2.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e953131005567c6e9c365c96ff7d20d0cfee62164bccc364293812a6b23d458f
MD5 baa8f57c3cd7e6a6aa3de35601fb13d1
BLAKE2b-256 3c1d304d67fb8222cdbc1c5e7c2f256df7580a834e8ebb5c3b04532716aca820

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page