question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: index -1 is out of bounds for dimension 1 with size 779

See original GitHub issue

Hi, Thanks for sharing the implementation of TabNet, it is very useful. how to fix this. why I get this error?

the shape of df’s are: train_X.shape, Val_X.shape, train_y.shape, Val_y.shape ((74676, 779), (18670, 779), (74676,), (18670,))

Parameter using: clf = TabNetClassifier( # default tabnet hyperparameters n_d=64, n_a=64, n_steps=5, gamma=1.5, n_independent=2, n_shared=2, lambda_sparse=1e-4, momentum=0.3, clip_value=2., optimizer_fn=torch.optim.Adam, optimizer_params=dict(lr=2e-2), scheduler_params = {“gamma”: 0.95, “step_size”: 20}, scheduler_fn=torch.optim.lr_scheduler.StepLR, epsilon=1e-15 )

clf.fit( X_train=X_train, y_train=y_train, X_valid=X_valid, y_valid=y_valid, max_epochs=max_epochs, patience=100, batch_size=10000, virtual_batch_size=256 )

`Will train until validation stopping metric hasn’t improved in 50 rounds.

| EPOCH | train | valid | total time (s)

RuntimeError Traceback (most recent call last) <ipython-input-168-7ff3d7a869b5> in <module> 5 X_valid=X_valid, y_valid=y_valid, 6 max_epochs=max_epochs, patience=50, ----> 7 batch_size=10000, virtual_batch_size=256 8 )

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_model.py in fit(self, X_train, y_train, X_valid, y_valid, loss_fn, weights, max_epochs, patience, batch_size, virtual_batch_size, num_workers, drop_last) 226 self.learning_rates.append(self.optimizer.param_groups[-1][“lr”]) 227 –> 228 fit_metrics = self.fit_epoch(train_dataloader, valid_dataloader) 229 230 # leaving it here, may be used for callbacks later

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_model.py in fit_epoch(self, train_dataloader, valid_dataloader) 345 DataLoader with valid set 346 “”" –> 347 train_metrics = self.train_epoch(train_dataloader) 348 valid_metrics = self.predict_epoch(valid_dataloader) 349

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_model.py in train_epoch(self, train_loader) 609 610 for data, targets in train_loader: –> 611 batch_outs = self.train_batch(data, targets) 612 if self.output_dim == 2: 613 y_preds.append(torch.nn.Softmax(dim=1)(batch_outs[“y_preds”])[:, 1]

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_model.py in train_batch(self, data, targets) 652 self.optimizer.zero_grad() 653 –> 654 output, M_loss = self.network(data) 655 656 loss = self.loss_fn(output, targets)

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 720 result = self._slow_forward(*input, **kwargs) 721 else: –> 722 result = self.forward(*input, **kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_network.py in forward(self, x) 262 def forward(self, x): 263 x = self.embedder(x) –> 264 return self.tabnet(x) 265 266 def forward_masks(self, x):

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 720 result = self._slow_forward(*input, **kwargs) 721 else: –> 722 result = self.forward(*input, **kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_network.py in forward(self, x) 134 135 for step in range(self.n_steps): –> 136 M = self.att_transformers[step](prior, att) 137 M_loss += torch.mean(torch.sum(torch.mul(M, torch.log(M+self.epsilon)), 138 dim=1))

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 720 result = self._slow_forward(*input, **kwargs) 721 else: –> 722 result = self.forward(*input, **kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/tab_network.py in forward(self, priors, processed_feat) 308 x = self.bn(x) 309 x = torch.mul(x, priors) –> 310 x = self.selector(x) 311 return x 312

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) 720 result = self._slow_forward(*input, **kwargs) 721 else: –> 722 result = self.forward(*input, **kwargs) 723 for hook in itertools.chain( 724 _global_forward_hooks.values(),

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/sparsemax.py in forward(self, input) 89 90 def forward(self, input): —> 91 return sparsemax(input, self.dim) 92 93

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/sparsemax.py in forward(ctx, input, dim) 41 max_val, _ = input.max(dim=dim, keepdim=True) 42 input -= max_val # same numerical stability trick as for softmax —> 43 tau, supp_size = SparsemaxFunction._threshold_and_support(input, dim=dim) 44 output = torch.clamp(input - tau, min=0) 45 ctx.save_for_backward(supp_size, output)

~/anaconda3/lib/python3.7/site-packages/pytorch_tabnet/sparsemax.py in _threshold_and_support(input, dim) 74 75 support_size = support.sum(dim=dim).unsqueeze(dim) —> 76 tau = input_cumsum.gather(dim, support_size - 1) 77 tau /= support_size.to(input.dtype) 78 return tau, support_size

RuntimeError: index -1 is out of bounds for dimension 1 with size 779`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Optimoxcommented, Sep 12, 2020

Glad to know that it’s working!

0reactions
Optimoxcommented, Sep 14, 2020

@monk1337 actually this might be due to the last batch having only one element, could you set drop_last to True and see if it works for any batch_size?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError: index 1 is out of bounds for dimension 1 with size 1
Hello! I am having this issue in the training when extracting the prediction: output = model.forward(image) The shape of the image tensor ...
Read more >
IndexError: index is out of bounds for axis 0 with size
I fed the (5,1) x_train back to the next_batch but tried to index it as though it were the original. Changing the iteration...
Read more >
index -1 is out of bounds for dimension 1 with size 4096 ...
I am getting this error while performing Ball Query on the features of a tensor (point cloud). The expected output should be a...
Read more >
List of Run-Time Error Messages - Intel
severe (1): Not a Fortran-specific error. FOR$IOS_NOTFORSPE. ... 1. severe: (139): Array index out of bounds for index "number".
Read more >
Python API: test/test_jit.py Source File - Caffe2
84 RUN_CUDA_MULTI_GPU = RUN_CUDA and torch.cuda.device_count() > 1 ... 1128 # gradients are required and sizes are involved.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found