Lordoflingus commited on
Commit
e10e84c
·
verified ·
1 Parent(s): c889c8d

import mmap

Browse files

import torch
import json
import os
from huggingface_hub import hf_hub_download


def load_file(filename, device):
with open(filename, mode="r", encoding="utf8") as file_obj:
with mmap.mmap(file_obj.fileno(), length=0, access=mmap.ACCESS_READ) as m:
header = m.read(8)
n = int.from_bytes(header, "little")
metadata_bytes = m.read(n)
metadata = json.loads(metadata_bytes)

size = os.stat(filename).st_size
storage = torch.ByteStorage.from_file(filename, shared=False, size=size).untyped()
offset = n + 8
return {name: create_tensor(storage, info, offset) for name, info in metadata.items() if name != "__metadata__"}


DTYPES = {"F32": torch.float32}
device = "cpu"


def create_tensor(storage, info, offset):
dtype = DTYPES[info["dtype"]]
shape = info["shape"]
start, stop = info["data_offsets"]
return torch.asarray(storage[start + offset : stop + offset], dtype=torch.uint8).view(dtype=dtype).reshape(shape)


def main():
filename = hf_hub_download("gpt2", filename="model.safetensors")
weights = load_file(filename, device)
print(weights.keys())


if __name__ == "__main__":
main()

Files changed (2) hide show
  1. README.md +6 -3
  2. index.html +333 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Neuronnet Explorer
3
- emoji: 🔥
4
  colorFrom: gray
5
  colorTo: gray
 
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: NeuronNet Explorer 🌐
 
3
  colorFrom: gray
4
  colorTo: gray
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
index.html CHANGED
@@ -1,19 +1,334 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>NeuronNet Explorer - AI Model Analysis</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://unpkg.com/feather-icons"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script>
11
+ tailwind.config = {
12
+ darkMode: 'class',
13
+ theme: {
14
+ extend: {
15
+ colors: {
16
+ primary: {
17
+ 50: '#eef2ff',
18
+ 100: '#e0e7ff',
19
+ 200: '#c7d2fe',
20
+ 300: '#a5b4fc',
21
+ 400: '#818cf8',
22
+ 500: '#6366f1',
23
+ 600: '#4f46e5',
24
+ 700: '#4338ca',
25
+ 800: '#3730a3',
26
+ 900: '#312e81',
27
+ },
28
+ secondary: {
29
+ 50: '#ecfdf5',
30
+ 100: '#d1fae5',
31
+ 200: '#a7f3d0',
32
+ 300: '#6ee7b7',
33
+ 400: '#34d399',
34
+ 500: '#10b981',
35
+ 600: '#059669',
36
+ 700: '#047857',
37
+ 800: '#065f46',
38
+ 900: '#064e3b',
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ </script>
45
+ <style>
46
+ .gradient-bg {
47
+ background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #064e3b 100%);
48
+ }
49
+ .neuron-glow {
50
+ box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
51
+ }
52
+ .pulse-animation {
53
+ animation: pulse 2s infinite;
54
+ }
55
+ @keyframes pulse {
56
+ 0%, 100% { opacity: 1; }
57
+ 50% { opacity: 0.7; }
58
+ }
59
+ </style>
60
+ </head>
61
+ <body class="bg-gray-900 text-white font-sans">
62
+ <!-- Navigation -->
63
+ <nav class="bg-gray-800/80 backdrop-blur-md fixed w-full z-50">
64
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
65
+ <div class="flex items-center justify-between h-16">
66
+ <div class="flex items-center">
67
+ <div class="flex-shrink-0">
68
+ <h1 class="text-xl font-bold text-white">NeuronNet Explorer</h1>
69
+ </div>
70
+ <div class="hidden md:block">
71
+ <div class="ml-10 flex items-baseline space-x-4">
72
+ <a href="#" class="text-primary-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Dashboard</a>
73
+ <a href="#" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Models</a>
74
+ <a href="#" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Analytics</a>
75
+ <a href="#" class="text-gray-300 hover:text-white px-3 py-2 rounded-md text-sm font-medium">Documentation</a>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ <div class="flex items-center space-x-4">
80
+ <button class="bg-primary-600 hover:bg-primary-700 px-4 py-2 rounded-md text-sm font-medium">
81
+ Upload Model
82
+ </button>
83
+ <div class="md:hidden">
84
+ <button type="button" class="text-gray-400 hover:text-white">
85
+ <i data-feather="menu"></i>
86
+ </button>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </nav>
92
+
93
+ <!-- Hero Section -->
94
+ <section class="gradient-bg pt-24 pb-32">
95
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
96
+ <div class="text-center">
97
+ <h1 class="text-4xl md:text-6xl font-bold mb-6">
98
+ Explore Neural Networks
99
+ <span class="text-secondary-400">with Precision</span>
100
+ </h1>
101
+ <p class="text-xl text-gray-300 mb-8 max-w-3xl mx-auto">
102
+ Visualize, analyze, and understand your AI models with our advanced neural network explorer.
103
+ Dive deep into model architectures and weights with unprecedented clarity.
104
+ </p>
105
+ <div class="flex flex-col sm:flex-row gap-4 justify-center">
106
+ <button class="bg-primary-600 hover:bg-primary-700 px-8 py-3 rounded-lg font-semibold text-lg transition duration-300">
107
+ <i data-feather="play" class="inline w-5 h-5 mr-2"></i>
108
+ Load Model
109
+ </button>
110
+ <button class="border border-primary-400 text-primary-300 hover:bg-primary-900 px-8 py-3 rounded-lg font-semibold text-lg transition duration-300">
111
+ View Documentation
112
+ </button>
113
+ </div>
114
+ </div>
115
+ </div>
116
+ </section>
117
+
118
+ <!-- Features Section -->
119
+ <section class="py-20 bg-gray-800">
120
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
121
+ <div class="text-center mb-16">
122
+ <h2 class="text-3xl md:text-4xl font-bold mb-4">Advanced Model Analysis</h2>
123
+ <p class="text-gray-400 text-lg">Powerful tools for understanding your AI models</p>
124
+ </div>
125
+
126
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
127
+ <!-- Feature 1 -->
128
+ <div class="bg-gray-700/50 rounded-xl p-6 neuron-glow hover:transform hover:scale-105 transition duration-300">
129
+ <div class="w-12 h-12 bg-primary-600 rounded-lg flex items-center justify-center mb-4">
130
+ <i data-feather="layers" class="w-6 h-6"></i>
131
+ </div>
132
+ <h3 class="text-xl font-semibold mb-3">Layer Visualization</h3>
133
+ <p class="text-gray-300">
134
+ Visualize every layer of your neural network with interactive 3D representations
135
+ and comprehensive weight analysis.
136
+ </p>
137
+ </div>
138
+
139
+ <!-- Feature 2 -->
140
+ <div class="bg-gray-700/50 rounded-xl p-6 neuron-glow hover:transform hover:scale-105 transition duration-300">
141
+ <div class="w-12 h-12 bg-secondary-600 rounded-lg flex items-center justify-center mb-4">
142
+ <i data-feather="activity" class="w-6 h-6"></i>
143
+ </div>
144
+ <h3 class="text-xl font-semibold mb-3">Real-time Analytics</h3>
145
+ <p class="text-gray-300">
146
+ Monitor model performance in real-time with detailed metrics,
147
+ activation patterns, and gradient flow visualization.
148
+ </p>
149
+ </div>
150
+
151
+ <!-- Feature 3 -->
152
+ <div class="bg-gray-700/50 rounded-xl p-6 neuron-glow hover:transform hover:scale-105 transition duration-300">
153
+ <div class="w-12 h-12 bg-primary-600 rounded-lg flex items-center justify-center mb-4">
154
+ <i data-feather="code" class="w-6 h-6"></i>
155
+ </div>
156
+ <h3 class="text-xl font-semibold mb-3">Code Integration</h3>
157
+ <p class="text-gray-300">
158
+ Seamlessly integrate with your Python workflow. Load models directly from
159
+ Hugging Face, PyTorch, or TensorFlow.
160
+ </p>
161
+ </div>
162
+ </div>
163
+ </div>
164
+ </section>
165
+
166
+ <!-- Model Showcase -->
167
+ <section class="py-20 bg-gray-900">
168
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
169
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
170
+ <div>
171
+ <h2 class="text-3xl md:text-4xl font-bold mb-6">Load & Analyze Any Model</h2>
172
+ <p class="text-gray-400 text-lg mb-8">
173
+ Our platform supports multiple model formats including SafeTensors,
174
+ PyTorch checkpoints, and Hugging Face models. Get detailed insights
175
+ into model architecture and weights.
176
+ </p>
177
+
178
+ <div class="space-y-4">
179
+ <div class="flex items-center">
180
+ <div class="w-8 h-8 bg-primary-600 rounded-full flex items-center justify-center mr-4">
181
+ <i data-feather="check" class="w-4 h-4"></i>
182
+ </div>
183
+ <span class="text-gray-300">Support for SafeTensors format</span>
184
+ </div>
185
+ <div class="flex items-center">
186
+ <div class="w-8 h-8 bg-primary-600 rounded-full flex items-center justify-center mr-4">
187
+ <i data-feather="check" class="w-4 h-4"></i>
188
+ </div>
189
+ <span class="text-gray-300">Hugging Face integration</span>
190
+ </div>
191
+ <div class="flex items-center">
192
+ <div class="w-8 h-8 bg-primary-600 rounded-full flex items-center justify-center mr-4">
193
+ <i data-feather="check" class="w-4 h-4"></i>
194
+ </div>
195
+ <span class="text-gray-300">PyTorch & TensorFlow support</span>
196
+ </div>
197
+ </div>
198
+
199
+ <button class="mt-8 bg-secondary-600 hover:bg-secondary-700 px-6 py-3 rounded-lg font-semibold transition duration-300">
200
+ Try Demo Model
201
+ </button>
202
+ </div>
203
+
204
+ <div class="bg-gray-800 rounded-2xl p-8 neuron-glow">
205
+ <div class="bg-gray-900 rounded-lg p-6">
206
+ <div class="flex items-center mb-4">
207
+ <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
208
+ <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
209
+ <div class="w-3 h-3 bg-green-500 rounded-full"></div>
210
+ </div>
211
+ <pre class="text-sm text-gray-300 overflow-x-auto">
212
+ <span class="text-green-400">import</span> mmap
213
+ <span class="text-green-400">import</span> torch
214
+ <span class="text-green-400">from</span> huggingface_hub <span class="text-green-400">import</span> hf_hub_download
215
+
216
+ <span class="text-blue-400">def</span> <span class="text-yellow-400">load_model</span>():
217
+ filename = hf_hub_download(<span class="text-orange-400">"gpt2"</span>,
218
+ filename=<span class="text-orange-400">"model.safetensors"</span>)
219
+ weights = load_file(filename, <span class="text-orange-400">"cpu"</span>)
220
+ <span class="text-green-400">return</span> weights
221
+
222
+ <span class="text-gray-600"># Model loaded successfully</span>
223
+ <span class="text-gray-600"># Analyzing 124M parameters...</span></pre>
224
+ </div>
225
+ </div>
226
+ </div>
227
+ </div>
228
+ </section>
229
+
230
+ <!-- Stats Section -->
231
+ <section class="py-20 bg-gray-800">
232
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
233
+ <div class="grid grid-cols-2 md:grid-cols-4 gap-8 text-center">
234
+ <div class="p-6">
235
+ <div class="text-3xl md:text-4xl font-bold text-primary-400 mb-2">124M+</div>
236
+ <div class="text-gray-400">Parameters Analyzed</div>
237
+ </div>
238
+ <div class="p-6">
239
+ <div class="text-3xl md:text-4xl font-bold text-secondary-400 mb-2">50K+</div>
240
+ <div class="text-gray-400">Models Processed</div>
241
+ </div>
242
+ <div class="p-6">
243
+ <div class="text-3xl md:text-4xl font-bold text-primary-400 mb-2">99.9%</div>
244
+ <div class="text-gray-400">Uptime</div>
245
+ </div>
246
+ <div class="p-6">
247
+ <div class="text-3xl md:text-4xl font-bold text-secondary-400 mb-2">24/7</div>
248
+ <div class="text-gray-400">Support</div>
249
+ </div>
250
+ </div>
251
+ </div>
252
+ </section>
253
+
254
+ <!-- CTA Section -->
255
+ <section class="py-20 gradient-bg">
256
+ <div class="max-w-4xl mx-auto text-center px-4 sm:px-6 lg:px-8">
257
+ <h2 class="text-3xl md:text-4xl font-bold mb-6">Ready to Explore Your Models?</h2>
258
+ <p class="text-xl text-gray-300 mb-8">
259
+ Start analyzing your neural networks with our powerful visualization tools.
260
+ No setup required - just upload and explore.
261
+ </p>
262
+ <div class="flex flex-col sm:flex-row gap-4 justify-center">
263
+ <button class="bg-white text-gray-900 hover:bg-gray-100 px-8 py-3 rounded-lg font-semibold text-lg transition duration-300">
264
+ Get Started Free
265
+ </button>
266
+ <button class="border border-white text-white hover:bg-white/10 px-8 py-3 rounded-lg font-semibold text-lg transition duration-300">
267
+ Schedule Demo
268
+ </button>
269
+ </div>
270
+ </div>
271
+ </section>
272
+
273
+ <!-- Footer -->
274
+ <footer class="bg-gray-900 border-t border-gray-800">
275
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
276
+ <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
277
+ <div>
278
+ <h3 class="text-lg font-semibold mb-4">NeuronNet Explorer</h3>
279
+ <p class="text-gray-400">
280
+ Advanced neural network visualization and analysis platform for AI researchers and developers.
281
+ </p>
282
+ </div>
283
+ <div>
284
+ <h4 class="font-semibold mb-4">Product</h4>
285
+ <ul class="space-y-2 text-gray-400">
286
+ <li><a href="#" class="hover:text-white">Features</a></li>
287
+ <li><a href="#" class="hover:text-white">Pricing</a></li>
288
+ <li><a href="#" class="hover:text-white">Documentation</a></li>
289
+ </ul>
290
+ </div>
291
+ <div>
292
+ <h4 class="font-semibold mb-4">Resources</h4>
293
+ <ul class="space-y-2 text-gray-400">
294
+ <li><a href="#" class="hover:text-white">Blog</a></li>
295
+ <li><a href="#" class="hover:text-white">Tutorials</a></li>
296
+ <li><a href="#" class="hover:text-white">Support</a></li>
297
+ </ul>
298
+ </div>
299
+ <div>
300
+ <h4 class="font-semibold mb-4">Connect</h4>
301
+ <div class="flex space-x-4">
302
+ <a href="#" class="text-gray-400 hover:text-white">
303
+ <i data-feather="github" class="w-5 h-5"></i>
304
+ </a>
305
+ <a href="#" class="text-gray-400 hover:text-white">
306
+ <i data-feather="twitter" class="w-5 h-5"></i>
307
+ </a>
308
+ <a href="#" class="text-gray-400 hover:text-white">
309
+ <i data-feather="linkedin" class="w-5 h-5"></i>
310
+ </a>
311
+ </div>
312
+ </div>
313
+ </div>
314
+ <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-400">
315
+ <p>&copy; 2024 NeuronNet Explorer. All rights reserved.</p>
316
+ </div>
317
+ </div>
318
+ </footer>
319
+
320
+ <script>
321
+ feather.replace();
322
+
323
+ // Simple animation for demo purposes
324
+ document.addEventListener('DOMContentLoaded', function() {
325
+ const elements = document.querySelectorAll('.neuron-glow');
326
+ elements.forEach((el, index) => {
327
+ setTimeout(() => {
328
+ el.classList.add('pulse-animation');
329
+ }, index * 200);
330
+ });
331
+ });
332
+ </script>
333
+ </body>
334
  </html>