Document FP16 inference
Browse files
README.md
CHANGED
|
@@ -20,28 +20,38 @@ pip install structured-data-models
|
|
| 20 |
Use labeled examples as context to predict class probabilities for new data:
|
| 21 |
|
| 22 |
```python
|
|
|
|
| 23 |
from sklearn.datasets import load_breast_cancer
|
|
|
|
| 24 |
import sdm
|
| 25 |
|
| 26 |
df = load_breast_cancer(as_frame=True).frame
|
|
|
|
| 27 |
|
| 28 |
table = sdm.TableTensor.from_pandas(
|
| 29 |
df=df,
|
| 30 |
stypes=sdm.infer_stypes(df, overrides={"target": "categorical"}),
|
| 31 |
-
device=
|
| 32 |
-
)
|
| 33 |
-
model = sdm.models.KumoTabular(task="classification", device="cuda")
|
| 34 |
-
|
| 35 |
-
probs = model(
|
| 36 |
-
x_context=table[:300].drop_columns("target"),
|
| 37 |
-
y_context=table[:300, "target"],
|
| 38 |
-
x_query=table[300:].drop_columns("target"),
|
| 39 |
-
num_estimators=8,
|
| 40 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
print(probs)
|
| 43 |
```
|
| 44 |
|
|
|
|
|
|
|
| 45 |
To learn more, visit [structured-data-models](https://github.com/NVIDIA/structured-data-models).
|
| 46 |
|
| 47 |
## License
|
|
|
|
| 20 |
Use labeled examples as context to predict class probabilities for new data:
|
| 21 |
|
| 22 |
```python
|
| 23 |
+
import torch
|
| 24 |
from sklearn.datasets import load_breast_cancer
|
| 25 |
+
|
| 26 |
import sdm
|
| 27 |
|
| 28 |
df = load_breast_cancer(as_frame=True).frame
|
| 29 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 30 |
|
| 31 |
table = sdm.TableTensor.from_pandas(
|
| 32 |
df=df,
|
| 33 |
stypes=sdm.infer_stypes(df, overrides={"target": "categorical"}),
|
| 34 |
+
device=device,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
+
model = sdm.models.KumoTabular(task="classification", device=device)
|
| 37 |
+
|
| 38 |
+
with torch.amp.autocast(
|
| 39 |
+
device.type,
|
| 40 |
+
dtype=torch.float16,
|
| 41 |
+
enabled=device.type == "cuda",
|
| 42 |
+
):
|
| 43 |
+
probs = model(
|
| 44 |
+
x_context=table[:300].drop_columns("target"),
|
| 45 |
+
y_context=table[:300, "target"],
|
| 46 |
+
x_query=table[300:].drop_columns("target"),
|
| 47 |
+
num_estimators=8,
|
| 48 |
+
)
|
| 49 |
|
| 50 |
print(probs)
|
| 51 |
```
|
| 52 |
|
| 53 |
+
Published GPU benchmarks use FP16 mixed precision for model execution. SDM respects the caller's active PyTorch autocast context but does not enable autocasting automatically, so use the context shown above for comparable GPU throughput.
|
| 54 |
+
|
| 55 |
To learn more, visit [structured-data-models](https://github.com/NVIDIA/structured-data-models).
|
| 56 |
|
| 57 |
## License
|