-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
184 lines (167 loc) · 4.86 KB
/
__init__.py
File metadata and controls
184 lines (167 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
Grilly - GPU-accelerated neural network operations using Vulkan.
PyTorch-like API for GPU-accelerated neural networks:
- nn: Neural network layers (Module, Linear, LayerNorm, Attention, etc.)
- functional: Functional API (activations, linear, attention, memory, etc.)
- optim: Optimizers (Adam, SGD, NLMS, NaturalGradient)
- utils: Utilities (data loading, checkpointing, device management)
This package provides GPU acceleration for:
- Spiking Neural Networks (SNN)
- Feedforward Neural Networks (FNN)
- Attention mechanisms
- Memory operations
- FAISS similarity search
- Place and time cells
- Learning operations (STDP, Hebbian, EWC, NLMS, Whitening)
- Bridge operations (continuous ↔ spike)
- Hippocampal transformer with capsule memory
"""
# grilly_core.<plat>.pyd lives in this directory as a sibling .pyd. Editable
# (PEP 660) installs route `import grilly` through a path hook that does NOT
# add this directory to sys.path, so `import grilly_core` would fail and the
# Vulkan probe in backend/base.py would silently report VULKAN_AVAILABLE=False
# even on machines with a perfectly working Vulkan device. Insert the package
# directory once, before any submodule import triggers the probe.
import os as _os
import sys as _sys
_pkg_dir = _os.path.dirname(_os.path.abspath(__file__))
if _pkg_dir not in _sys.path:
_sys.path.insert(0, _pkg_dir)
import grilly.functional as functional
import grilly.nn as nn
import grilly.optim as optim
import grilly.utils as utils
from grilly.backend.base import (
VULKAN_AVAILABLE,
VULKAN_PYTHON_BINDINGS_AVAILABLE,
VULKAN_PYTHON_LEGACY_BACKEND_AVAILABLE,
)
from grilly.backend.capsule_transformer import (
CapsuleMemory,
CapsuleTransformerConfig,
CognitiveFeatures,
MemoryType,
)
from grilly.backend.compute import VulkanCompute
from grilly.backend.learning import VulkanLearning
from grilly.backend.snn_compute import SNNCompute
from . import torch_api
# Main API exports
Compute = VulkanCompute
Learning = VulkanLearning
# Import utilities for HuggingFace and PyTorch compatibility
try:
from grilly.utils.device_manager import get_cuda_backend, get_device_manager, get_vulkan_backend
from grilly.utils.huggingface_bridge import HuggingFaceBridge, get_huggingface_bridge
from grilly.utils.pytorch_compat import Tensor, ones, randn, tensor, zeros
from grilly.utils.pytorch_ops import (
add,
avg_pool2d,
conv2d,
cross_entropy_loss,
dropout,
gelu,
layer_norm,
matmul,
max_pool2d,
mse_loss,
mul,
relu,
softmax,
)
COMPAT_AVAILABLE = True
except Exception:
COMPAT_AVAILABLE = False
__all__ = [
"VULKAN_AVAILABLE",
"VULKAN_PYTHON_BINDINGS_AVAILABLE",
"VULKAN_PYTHON_LEGACY_BACKEND_AVAILABLE",
"VulkanCompute",
"Compute",
"SNNCompute",
"VulkanLearning",
"Learning",
"CapsuleMemory",
"CapsuleTransformerConfig",
"CognitiveFeatures",
"MemoryType",
# Submodules
"nn",
"functional",
"optim",
"utils",
"torch_api",
]
# Conditionally add compatibility exports
if COMPAT_AVAILABLE:
__all__.extend(
[
"get_device_manager",
"get_vulkan_backend",
"get_cuda_backend",
"HuggingFaceBridge",
"get_huggingface_bridge",
"Tensor",
"tensor",
"zeros",
"ones",
"randn",
"add",
"mul",
"matmul",
"relu",
"gelu",
"softmax",
"layer_norm",
"dropout",
"conv2d",
"max_pool2d",
"avg_pool2d",
"mse_loss",
"cross_entropy_loss",
]
)
# Tensor conversion utilities
try:
from grilly.utils.tensor_conversion import (
VulkanTensor,
ensure_vulkan_compatible,
from_vulkan,
to_vulkan,
to_vulkan_batch,
to_vulkan_gpu,
)
if "to_vulkan" not in __all__:
__all__.extend(
[
"to_vulkan",
"to_vulkan_batch",
"to_vulkan_gpu",
"from_vulkan",
"ensure_vulkan_compatible",
"VulkanTensor",
]
)
except Exception:
pass
# ONNX utilities
try:
from grilly.utils.onnx_exporter import OnnxExporter
from grilly.utils.onnx_finetune import OnnxFineTuner
from grilly.utils.onnx_loader import GrillyOnnxModel, OnnxModelLoader
ONNX_AVAILABLE = True
except Exception:
ONNX_AVAILABLE = False
if ONNX_AVAILABLE:
__all__.extend(
[
"OnnxModelLoader",
"OnnxExporter",
"GrillyOnnxModel",
"OnnxFineTuner",
]
)
try:
from grilly._version import version as __version__
except ImportError:
__version__ = "0.0.0.dev0" # fallback when _version.py not yet generated