@ptrblck , here the inputs of the decoder are (sample, con_dim). con_dim was int I changed that to tensor but now I got this error:
---> 31     samples_model = cvae.sample()
     32     samples_gt = gen_batch(2048)
     33     kde_skl = KernelDensity(kernel='gaussian', bandwidth=0.2)

<ipython-input-86-826f0d9710ca> in sample(self, n)
     28         """
     29         sample = torch.randn(n, K).to(device)
---> 30         out = cvae.decode(sample, cond_dim)
     31 
     32         return out.cpu().detach().numpy()

<ipython-input-86-826f0d9710ca> in decode(self, z, c)
     34 
     35     def decode(self, z, c):
---> 36         concat_input = torch.cat([z, c], 1)
     37         return self.fc5(F.selu(self.fc4(F.selu(self.fc3(concat_input)))))
     38 

RuntimeError: zero-dimensional tensor (at position 1) cannot be concatenated

because the size of sample is 2048x20 but cond_dim has no dimension
cond_dim.shape
torch.Size([])
Then I tried to use torch.stack instead of torch.cat for k=8 but I got the following error, I think the logic of my choice for condition is wrong and every time I got new error:((
<ipython-input-73-3eb5f1d14a58> in train(epoch)
     16         data, cond = data.to(device), one_hot(cond, cond_dim).to(device)
     17         optimizer.zero_grad()
---> 18         recon_batch, mu, logvar = cvae(data, cond)
     19         print("mu", mu)
     20         print("logvar", logvar)

~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
   1049         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1050                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1051             return forward_call(*input, **kwargs)
   1052         # Do not call functions when jit is used
   1053         full_backward_hooks, non_full_backward_hooks = [], []

<ipython-input-68-127374cfac97> in forward(self, x, c)
     40         mu, logvar = self.encode(x.view(-1, 2), c)
     41         z = self.reparameterize(mu, logvar)
---> 42         return self.decode(z, c), mu, logvar

<ipython-input-68-127374cfac97> in decode(self, z, c)
     35     def decode(self, z, c):
     36         concat_input = torch.stack([z, c], 1)
---> 37         return self.fc5(F.selu(self.fc4(F.selu(self.fc3(concat_input)))))
     38 
     39     def forward(self, x, c):

~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
   1049         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1050                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1051             return forward_call(*input, **kwargs)
   1052         # Do not call functions when jit is used
   1053         full_backward_hooks, non_full_backward_hooks = [], []

~\anaconda3\lib\site-packages\torch\nn\modules\linear.py in forward(self, input)
     94 
     95     def forward(self, input: Tensor) -> Tensor:
---> 96         return F.linear(input, self.weight, self.bias)
     97 
     98     def extra_repr(self) -> str:

~\anaconda3\lib\site-packages\torch\nn\functional.py in linear(input, weight, bias)
   1845     if has_torch_function_variadic(input, weight):
   1846         return handle_torch_function(linear, (input, weight), input, weight, bias=bias)
-> 1847     return torch._C._nn.linear(input, weight, bias)
   1848 
   1849 

RuntimeError: mat1 and mat2 shapes cannot be multiplied (4096x8 and 16x8)