diff --git a/docs/source/nanotabicl.md b/docs/source/nanotabicl.md index 0824bd8781..99535ceb2c 100644 --- a/docs/source/nanotabicl.md +++ b/docs/source/nanotabicl.md @@ -1,4 +1,4 @@ -# NanoTabICL in SDM +# NanoTabICL The [`sdm.nn`](api/nn) package provides reusable, GPU-accelerated building blocks for developing foundation models for structured data from scratch. In this guide, we show how to build a minimal [TabICLv2](https://arxiv.org/abs/2602.11139)-inspired Tabular Foundation Model (TFM) with it. @@ -268,9 +268,10 @@ The remaining rows are treated as query rows whose labels the model predicts. Categorical encoding, missing-value handling, and feature scaling are typically performed in a pre-processing stage before the model's {py:meth}`~torch.nn.Module.forward` call. ```python -x = torch.randn(128, 32, device="cuda") -y = torch.randint(0, 10, (64, ), device="cuda") +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +x = torch.randn(128, 32, device=device) +y = torch.randint(0, 10, (64, ), device=device) -model = NanoTabICL().cuda() +model = NanoTabICL().to(device) out = model(x, y) ``` diff --git a/test/docs/test_nanotabicl.py b/test/docs/test_nanotabicl.py new file mode 100644 index 0000000000..619c5709b4 --- /dev/null +++ b/test/docs/test_nanotabicl.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +import re +from pathlib import Path +from typing import Any + + +def test_nanotabicl() -> None: + path = Path(__file__).parents[2] / "docs/source/nanotabicl.md" + text = path.read_text() + namespace: dict[str, Any] = {} + + for match in re.finditer(r"^```python\n(.*?)^```", text, re.M | re.S): + source = "\n" * text.count("\n", 0, match.start(1)) + match[1] + exec(compile(source, str(path), "exec"), namespace) + + out = namespace["out"] + assert out.size() == (64, 10) + assert out.isfinite().all()