FBNet icon indicating copy to clipboard operation
FBNet copied to clipboard

shape error with gumbel softmax

Open haibao-yu opened this issue 5 years ago • 6 comments

Hi, latifisalar, thanks for your great work.

When I run python supernet_main_file.py --train_or_sample train under Pytorch0.4.1, here is running error: ""assert len(shape) == 2" in line 22 in "supernet_functions/model_supernet.py"", and self.thetas is 1-dim tensor. What's wrong for self.thetas? Thanks~

haibao-yu avatar Jul 14 '19 09:07 haibao-yu

@walk2out hi! It's strange because we have the same PyTorch version. Can you share a Dockerfile? I will look next week

AnnaAraslanova avatar Jul 14 '19 18:07 AnnaAraslanova

Thanks, and I have dealt with this problem by replacing the gumbel softmax with following code u = Variable((torch.zeros_like(log_alpha)).uniform_()) softmax = torch.nn.Softmax(-1) soft_mask_variables = softmax((log_alpha + (-((-(u.log())).log())).cuda()) / self._temp)

However, there is another problem: the output size of the last stages is [1000, 352, 1, 1] which cause the size error, and I think maybe the super_net is not available, is there any problem? Is the dataset ImageNet instead of Cifar10?

Thanks~

haibao-yu avatar Jul 16 '19 07:07 haibao-yu

Thanks, and I have dealt with this problem by replacing the gumbel softmax with following code u = Variable((torch.zeros_like(log_alpha)).uniform_()) softmax = torch.nn.Softmax(-1) soft_mask_variables = softmax((log_alpha + (-((-(u.log())).log())).cuda()) / self._temp)

However, there is another problem: the output size of the last stages is [1000, 352, 1, 1] which cause the size error, and I think maybe the super_net is not available, is there any problem? Is the dataset ImageNet instead of Cifar10?

Thanks~

I have found that the super_net is for ImageNet instead of Cifar10, and I have modified the code, all is ok, thanks~

haibao-yu avatar Jul 17 '19 03:07 haibao-yu

Hi @walk2out I met the same problem as you my env is also under Pytorch0.4.1. But your solution doesn't make sense for me. It involves some unknown variables like log_alpha and temp: u = Variable((torch.zeros_like(log_alpha)).uniform()) softmax = torch.nn.Softmax(-1) soft_mask_variables = softmax((log_alpha + (-((-(u.log())).log())).cuda()) / self._temp) could you please give more details on how you solve the issue Thanks! Also @AnnaAraslanova is it the correct way as stated by walk2out to solve the issue? Thanks!

bloatybo avatar Aug 02 '19 19:08 bloatybo

Hi @walk2out I met the same problem as you my env is also under Pytorch0.4.1. But your solution doesn't make sense for me. It involves some unknown variables like log_alpha and temp: u = Variable((torch.zeros_like(log_alpha)).uniform()) softmax = torch.nn.Softmax(-1) soft_mask_variables = softmax((log_alpha + (-((-(u.log())).log())).cuda()) / self._temp) could you please give more details on how you solve the issue Thanks! Also @AnnaAraslanova is it the correct way as stated by walk2out to solve the issue? Thanks!

I wrote wrong code, correct code is: u = Variable((torch.zeros_like(self.thetas)).uniform_()) softmax = torch.nn.Softmax(-1) soft_mask_variables = softmax((self.thetas + (-((-(u.log())).log())).cuda()) / temperature)

Thanks

haibao-yu avatar Aug 13 '19 03:08 haibao-yu

A simple way to implement it is to use the 'private' function:

soft_mask_variables = nn.functional._gumbel_softmax_sample(self.thetas, temperature)

Actually, you have implemented the 'gumbel_softmax_sample' function. Good For You! @walk2out

ShipXu avatar May 05 '20 04:05 ShipXu