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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html lang="en">
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>Transformer Matrix Visualization - Aligned</title>
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
margin: 0;
|
| 11 |
+
font-family: 'Segoe UI', 'Roboto', 'Oxygen', sans-serif;
|
| 12 |
+
background-color: #000000;
|
| 13 |
+
color: #e0e0e0;
|
| 14 |
+
overflow: hidden;
|
| 15 |
+
}
|
| 16 |
+
#button-container {
|
| 17 |
+
position: absolute;
|
| 18 |
+
top: 20px;
|
| 19 |
+
left: 50%;
|
| 20 |
+
transform: translateX(-50%);
|
| 21 |
+
z-index: 100;
|
| 22 |
+
display: flex;
|
| 23 |
+
gap: 15px;
|
| 24 |
+
background-color: rgba(10, 10, 10, 0.7);
|
| 25 |
+
padding: 10px 20px;
|
| 26 |
+
border-radius: 12px;
|
| 27 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
| 28 |
+
}
|
| 29 |
+
.focus-btn {
|
| 30 |
+
background-color: #222;
|
| 31 |
+
color: #ddd;
|
| 32 |
+
border: 1px solid #444;
|
| 33 |
+
padding: 8px 16px;
|
| 34 |
+
border-radius: 8px;
|
| 35 |
+
cursor: pointer;
|
| 36 |
+
font-size: 16px;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
transition: background-color 0.3s, color 0.3s;
|
| 39 |
+
}
|
| 40 |
+
.focus-btn:hover {
|
| 41 |
+
background-color: #0077be;
|
| 42 |
+
color: #fff;
|
| 43 |
+
}
|
| 44 |
+
#tooltip {
|
| 45 |
+
position: absolute;
|
| 46 |
+
display: none;
|
| 47 |
+
padding: 12px;
|
| 48 |
+
background-color: rgba(10, 10, 25, 0.9);
|
| 49 |
+
border: 1px solid #0077be;
|
| 50 |
+
border-radius: 8px;
|
| 51 |
+
pointer-events: none;
|
| 52 |
+
font-size: 14px;
|
| 53 |
+
z-index: 101;
|
| 54 |
+
}
|
| 55 |
+
#tooltip h3 { margin: 0 0 8px 0; color: #8ac8ff; }
|
| 56 |
+
#tooltip p { margin: 0; }
|
| 57 |
+
canvas { display: block; }
|
| 58 |
+
</style>
|
| 59 |
+
</head>
|
| 60 |
+
<body>
|
| 61 |
+
<div id="button-container"></div>
|
| 62 |
+
<div id="tooltip"></div>
|
| 63 |
+
<div id="canvas-container"></div>
|
| 64 |
+
|
| 65 |
+
<script type="importmap">
|
| 66 |
+
{
|
| 67 |
+
"imports": {
|
| 68 |
+
"three": "https://unpkg.com/three@0.165.0/build/three.module.js",
|
| 69 |
+
"three/addons/": "https://unpkg.com/three@0.165.0/examples/jsm/",
|
| 70 |
+
"gsap": "https://unpkg.com/gsap@3.12.5/index.js"
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
</script>
|
| 74 |
+
|
| 75 |
+
<script type="module">
|
| 76 |
+
import * as THREE from 'three';
|
| 77 |
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 78 |
+
import { gsap } from 'gsap';
|
| 79 |
+
|
| 80 |
+
// --- Scene Setup ---
|
| 81 |
+
const scene = new THREE.Scene();
|
| 82 |
+
const container = document.getElementById('canvas-container');
|
| 83 |
+
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 200000);
|
| 84 |
+
camera.position.set(0, 200, 1500);
|
| 85 |
+
|
| 86 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 87 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 88 |
+
renderer.setPixelRatio(window.devicePixelRatio);
|
| 89 |
+
container.appendChild(renderer.domElement);
|
| 90 |
+
|
| 91 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 92 |
+
controls.enableDamping = true;
|
| 93 |
+
controls.dampingFactor = 0.05;
|
| 94 |
+
|
| 95 |
+
const gridHelper = new THREE.GridHelper(400000, 400, 0x333333, 0x222222);
|
| 96 |
+
scene.add(gridHelper);
|
| 97 |
+
|
| 98 |
+
// This group will hold all models to make centering easy
|
| 99 |
+
const allModelsGroup = new THREE.Group();
|
| 100 |
+
scene.add(allModelsGroup);
|
| 101 |
+
|
| 102 |
+
const models = [];
|
| 103 |
+
const collidableObjects = [];
|
| 104 |
+
|
| 105 |
+
const colorPalette = [
|
| 106 |
+
new THREE.Color(0x6a0dad), new THREE.Color(0x0077be),
|
| 107 |
+
new THREE.Color(0x00a896), new THREE.Color(0xdc3958),
|
| 108 |
+
new THREE.Color(0xf7ac3d),
|
| 109 |
+
];
|
| 110 |
+
|
| 111 |
+
function createMatrixModel(name, params) {
|
| 112 |
+
const modelGroup = new THREE.Group();
|
| 113 |
+
|
| 114 |
+
const representativeCount = Math.floor(Math.max(400, params / 2e6));
|
| 115 |
+
const gridSide = Math.floor(Math.sqrt(representativeCount));
|
| 116 |
+
const instanceCount = gridSide * gridSide;
|
| 117 |
+
|
| 118 |
+
const squareSize = 5;
|
| 119 |
+
const modelWidth = gridSide * squareSize;
|
| 120 |
+
|
| 121 |
+
const geometry = new THREE.PlaneGeometry(squareSize * 0.9, squareSize * 0.9);
|
| 122 |
+
const material = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide });
|
| 123 |
+
const mesh = new THREE.InstancedMesh(geometry, material, instanceCount);
|
| 124 |
+
|
| 125 |
+
const dummy = new THREE.Object3D();
|
| 126 |
+
let i = 0;
|
| 127 |
+
for (let x = 0; x < gridSide; x++) {
|
| 128 |
+
for (let y = 0; y < gridSide; y++) {
|
| 129 |
+
dummy.position.set(
|
| 130 |
+
(x - gridSide / 2) * squareSize,
|
| 131 |
+
(y - gridSide / 2) * squareSize,
|
| 132 |
+
0
|
| 133 |
+
);
|
| 134 |
+
dummy.updateMatrix();
|
| 135 |
+
mesh.setMatrixAt(i, dummy.matrix);
|
| 136 |
+
const color = colorPalette[Math.floor(Math.random() * colorPalette.length)];
|
| 137 |
+
mesh.setColorAt(i, color);
|
| 138 |
+
i++;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
mesh.instanceMatrix.needsUpdate = true;
|
| 143 |
+
mesh.instanceColor.needsUpdate = true;
|
| 144 |
+
|
| 145 |
+
modelGroup.add(mesh);
|
| 146 |
+
|
| 147 |
+
modelGroup.userData = { name, params };
|
| 148 |
+
mesh.userData = { modelName: name, params };
|
| 149 |
+
|
| 150 |
+
models.push({ name, group: modelGroup, params });
|
| 151 |
+
collidableObjects.push(mesh);
|
| 152 |
+
|
| 153 |
+
// Return the group and its calculated width for layout purposes
|
| 154 |
+
return { modelGroup, modelWidth };
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// --- NEW: Ordered Model Definitions & Linear Layout ---
|
| 158 |
+
const modelDefinitions = [
|
| 159 |
+
{ name: '1000B', params: 1000e9 }, { name: '405B', params: 405e9 },
|
| 160 |
+
{ name: '70B', params: 70e9 }, { name: '4B', params: 4e9 },
|
| 161 |
+
{ name: '1B', params: 1e9 }, { name: '0.2B', params: 0.2e9 },
|
| 162 |
+
];
|
| 163 |
+
|
| 164 |
+
let currentX = 0;
|
| 165 |
+
modelDefinitions.forEach((def) => {
|
| 166 |
+
const { modelGroup, modelWidth } = createMatrixModel(def.name, def.params);
|
| 167 |
+
|
| 168 |
+
// Add padding based on the size of the model
|
| 169 |
+
const padding = modelWidth * 0.5;
|
| 170 |
+
|
| 171 |
+
// Position the model along the X axis
|
| 172 |
+
modelGroup.position.x = currentX + modelWidth / 2;
|
| 173 |
+
|
| 174 |
+
// Add the model to the main group
|
| 175 |
+
allModelsGroup.add(modelGroup);
|
| 176 |
+
|
| 177 |
+
// Update the X-coordinate for the next model
|
| 178 |
+
currentX += modelWidth + padding;
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
+
// Center the entire line of models at the world origin
|
| 182 |
+
const sceneBox = new THREE.Box3().setFromObject(allModelsGroup);
|
| 183 |
+
const sceneCenter = new THREE.Vector3();
|
| 184 |
+
sceneBox.getCenter(sceneCenter);
|
| 185 |
+
allModelsGroup.position.x = -sceneCenter.x;
|
| 186 |
+
|
| 187 |
+
// --- UI and Camera Control ---
|
| 188 |
+
const buttonContainer = document.getElementById('button-container');
|
| 189 |
+
models.forEach(model => {
|
| 190 |
+
const btn = document.createElement('button');
|
| 191 |
+
btn.className = 'focus-btn';
|
| 192 |
+
btn.innerText = model.name;
|
| 193 |
+
btn.onclick = () => focusOnModel(model);
|
| 194 |
+
buttonContainer.appendChild(btn);
|
| 195 |
+
});
|
| 196 |
+
|
| 197 |
+
function focusOnModel(model) {
|
| 198 |
+
const modelWorldPosition = new THREE.Vector3();
|
| 199 |
+
model.group.getWorldPosition(modelWorldPosition);
|
| 200 |
+
|
| 201 |
+
const modelBox = new THREE.Box3().setFromObject(model.group);
|
| 202 |
+
const modelSize = new THREE.Vector3();
|
| 203 |
+
modelBox.getSize(modelSize);
|
| 204 |
+
|
| 205 |
+
const cameraDistance = modelSize.y / (2 * Math.tan(camera.fov * Math.PI / 360)) * 1.5; // Frame based on height
|
| 206 |
+
const cameraZ = Math.max(cameraDistance, modelSize.x); // Ensure we are far enough to see the width
|
| 207 |
+
|
| 208 |
+
const cameraTargetPosition = new THREE.Vector3(
|
| 209 |
+
modelWorldPosition.x,
|
| 210 |
+
modelWorldPosition.y,
|
| 211 |
+
modelWorldPosition.z + cameraZ
|
| 212 |
+
);
|
| 213 |
+
|
| 214 |
+
gsap.to(camera.position, {
|
| 215 |
+
x: cameraTargetPosition.x,
|
| 216 |
+
y: cameraTargetPosition.y,
|
| 217 |
+
z: cameraTargetPosition.z,
|
| 218 |
+
duration: 2.5,
|
| 219 |
+
ease: 'power3.inOut'
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
gsap.to(controls.target, {
|
| 223 |
+
x: modelWorldPosition.x,
|
| 224 |
+
y: modelWorldPosition.y,
|
| 225 |
+
z: modelWorldPosition.z,
|
| 226 |
+
duration: 2.5,
|
| 227 |
+
ease: 'power3.inOut'
|
| 228 |
+
});
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// --- Interactivity & Render Loop ---
|
| 232 |
+
const raycaster = new THREE.Raycaster();
|
| 233 |
+
const mouse = new THREE.Vector2();
|
| 234 |
+
const tooltip = document.getElementById('tooltip');
|
| 235 |
+
|
| 236 |
+
window.addEventListener('mousemove', (event) => {
|
| 237 |
+
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
| 238 |
+
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
| 239 |
+
tooltip.style.left = (event.clientX + 15) + 'px';
|
| 240 |
+
tooltip.style.top = (event.clientY + 15) + 'px';
|
| 241 |
+
});
|
| 242 |
+
|
| 243 |
+
function animate() {
|
| 244 |
+
requestAnimationFrame(animate);
|
| 245 |
+
controls.update();
|
| 246 |
+
|
| 247 |
+
raycaster.setFromCamera(mouse, camera);
|
| 248 |
+
const intersects = raycaster.intersectObjects(collidableObjects);
|
| 249 |
+
|
| 250 |
+
if (intersects.length > 0) {
|
| 251 |
+
const data = intersects[0].object.userData;
|
| 252 |
+
tooltip.style.display = 'block';
|
| 253 |
+
tooltip.innerHTML = `
|
| 254 |
+
<h3>${data.modelName} Model</h3>
|
| 255 |
+
<p><strong>Parameters:</strong> ${data.params.toLocaleString()}</p>
|
| 256 |
+
`;
|
| 257 |
+
} else {
|
| 258 |
+
tooltip.style.display = 'none';
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
renderer.render(scene, camera);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
// Focus on the first model (1000B) to start
|
| 265 |
+
if (models.length > 0) {
|
| 266 |
+
focusOnModel(models[0]);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
animate();
|
| 270 |
+
</script>
|
| 271 |
+
<footer>fredmo - 2025 </footer>
|
| 272 |
+
</body>
|
| 273 |
+
</html>
|