Skip to content

Commit 6c03ae3

Browse files
committed
fix(colab): fix Tensor.shape property usage and pip install in quickstart notebook
1 parent 748bc4b commit 6c03ae3

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

‎examples/oxideon_quickstart.ipynb‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"metadata": {},
2222
"outputs": [],
2323
"source": [
24-
"!pip install -q oxideon numpy torch"
24+
"!pip install -q oxideon"
2525
]
2626
},
2727
{
@@ -36,13 +36,13 @@
3636
"x = ox.Tensor.arange(0.0, 24.0, 1.0).reshape([2, 3, 4])\n",
3737
"v = x.transpose(0, 2)\n",
3838
"assert v.shares_storage(x)\n",
39-
"print(\"v shape:\", v.shape(), \"shares_storage:\", v.shares_storage(x))\n",
39+
"print(\"v shape:\", list(v.shape), \"shares_storage:\", v.shares_storage(x))\n",
4040
"\n",
4141
"# 2. Einops-style rearrange & channels_last\n",
4242
"img = ox.randn([2, 8, 4, 4])\n",
4343
"nhwc = img.rearrange(\"b c h w -> b h w c\")\n",
4444
"cl = img.to_channels_last()\n",
45-
"print(\"rearranged shape:\", nhwc.shape(), \"is_channels_last:\", cl.is_channels_last())"
45+
"print(\"rearranged shape:\", list(nhwc.shape), \"is_channels_last:\", cl.is_channels_last())"
4646
]
4747
},
4848
{
@@ -98,28 +98,30 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"# 5. Quick CPU benchmark vs PyTorch (AdamW + Softmax + LayerNorm)\n",
101+
"# 5. Zero-copy NumPy / DLPack interop & quick CPU benchmark vs PyTorch\n",
102102
"import time\n",
103-
"import torch\n",
104103
"\n",
105104
"x_np = ox.randn([32, 128, 768]).numpy()\n",
106105
"xo = ox.from_numpy(x_np)\n",
107-
"xt = torch.from_numpy(x_np)\n",
108-
"\n",
109106
"for _ in range(3):\n",
110107
" _ = xo.softmax(-1)\n",
111-
" _ = torch.softmax(xt, -1)\n",
112-
"\n",
113108
"t0 = time.perf_counter()\n",
114109
"for _ in range(20):\n",
115110
" _ = xo.softmax(-1)\n",
116111
"ox_ms = (time.perf_counter() - t0) / 20 * 1000\n",
117112
"\n",
118-
"t0 = time.perf_counter()\n",
119-
"for _ in range(20):\n",
120-
" _ = torch.softmax(xt, -1)\n",
121-
"pt_ms = (time.perf_counter() - t0) / 20 * 1000\n",
122-
"print(f\"softmax [32,128,768]: Oxideon={ox_ms:.2f} ms, PyTorch={pt_ms:.2f} ms\")"
113+
"try:\n",
114+
" import torch\n",
115+
" xt = torch.utils.dlpack.from_dlpack(xo)\n",
116+
" for _ in range(3):\n",
117+
" _ = torch.softmax(xt, -1)\n",
118+
" t0 = time.perf_counter()\n",
119+
" for _ in range(20):\n",
120+
" _ = torch.softmax(xt, -1)\n",
121+
" pt_ms = (time.perf_counter() - t0) / 20 * 1000\n",
122+
" print(f\"softmax [32,128,768]: Oxideon={ox_ms:.2f} ms, PyTorch={pt_ms:.2f} ms\")\n",
123+
"except ImportError:\n",
124+
" print(f\"softmax [32,128,768]: Oxideon={ox_ms:.2f} ms (install torch to compare)\")"
123125
]
124126
}
125127
],

0 commit comments

Comments
 (0)