google-research / google-research/tabfm
TabFM constructor accepts zero/negative dimensions; col_num_blocks=0 builds a model with no attention blocks
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 270
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 1
Description
Separate from #91 (which is about `config.json` keys being merged in unvalidated) — this is about the constructor itself, and it affects anyone calling `TabFM(...)` directly in Python.
I tested every dimensional parameter at `0` and `-1` on `b15593e4c1111ddb5f4f30dd2957df2edbaa04ca`, in a clean container. **Ten of thirteen accept `0` and build a model with no error.** Three accept `-1` as well.
```
param value outcome
------------------------------------------------------------------------
embed_dim 0 BUILT OK (no validation)
embed_dim -1 RuntimeError: Trying to create tensor with negative di
max_classes 0 BUILT OK (no validation)
max_classes -1 RuntimeError: Trying to create tensor with negative di
col_num_blocks 0 BUILT OK (no validation)
col_num_blocks -1 BUILT OK (no validation)
col_nhead 0 ZeroDivisionError
col_nhead -1 RuntimeError: Trying to create tensor with negative di
col_num_inds 0 BUILT OK (no validation)
col_num_inds -1 RuntimeError: zeros: Dimension size must be non-negati
row_num_blocks 0 BUILT OK (no validation)
row_num_blocks -1 BUILT OK (no validation)
row_nhead 0 ZeroDivisionError
row_nhead -1 RuntimeError: upper bound and lower bound inconsistent
row_num_cls 0 BUILT OK (no validation)
row_num_cls -1 RuntimeError: zeros: Dimension size must be non-negati
icl_num_blocks 0 BUILT OK (no validation)
icl_num_blocks -1 BUILT OK (no validation)
icl_nhead 0 ZeroDivisionError
icl_nhead -1 RuntimeError: Trying to create tensor with negative di
ff_factor 0 BUILT OK (no validation)
ff_factor -1 RuntimeError: Trying to create tensor with negative di
feature_group_size 0 BUILT OK (no validation)
feature_group_size -1 RuntimeError: zeros: Dimension size must be non-negati
num_freq 0 BUILT OK (no validation)
num_freq -1 RuntimeError: zeros: Dimension size must be non-negati
```
The one I would draw your attention to is `*_num_blocks`. Passing `0` or `-1` makes `range(...)` empty, so the `ModuleList` is empty and the model is built **with no attention blocks at all**. It still runs and still returns predictions. Nothing warns. That is a worse outcome than the crashes elsewhere in the table, because a crash is at least honest about what happened.
Where errors do occur they come from PyTorch rather than from tabfm, so the message describes a tensor shape rather than the parameter the caller actually got wrong — `Trying to create tensor with negative dimension` does not tell someone that `ff_factor` was the problem.
A small guard at the top of `__init__` rejecting non-positive values for these parameters would turn all twenty-six rows into one clear message. I am happy to send that PR if you would like it — I did not want to presume which parameters you consider legitimately zero-able (`decoder_hidden` is already `None`-able, so there may be others by design).
Disclosure: I used an AI assistant to help find this. I ran the matrix myself.
Contributor guide
Research direction
Start at the TabFM constructor (__init__) and reproduce the reported zero and negative dimension cases in a clean container. Check how the dimensional parameters reach PyTorch and ModuleList construction; done means non-positive inputs produce one clear tabfm validation error rather than building empty attention blocks or failing with an unrelated tensor-shape message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100