KareemYousrii/SPL

AttributeError: 'PSddNode' object has no attribute 'num_reps'

Closed this issue · 1 comments

Following #4 ,

My code is now :

from SPL.grids.compute_mpe import CircuitMPE
cmpe = CircuitMPE('ex1.vtree', 'ex1.sdd')

scores = network(inputs) # shape torch.Size([6, 5])

bsz = 6
logprobs = F.logsigmoid(scores)
litweights = [[log1mexp(-p), p] for p in logprobs.unbind(axis=1)]
cmpe.parameterize_ff(litweights)
suggested_path = cmpe.get_mpe_inst(bsz)

And I get the error :

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[c:\Users\arthur.ledag---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[c:\Users\arthur.ledaguenel\Documents\Experiences\NeSy\test.ipynb](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/test.ipynb) Cell 31 in ()
----> [1](vscode-notebook-cell:/c%3A/Users/arthur.ledaguenel/Documents/Experiences/NeSy/test.ipynb#Y116sZmlsZQ%3D%3D?line=0) suggested_path = cmpe.get_mpe_inst(bsz)

File [c:\Users\arthur.ledaguenel\Documents\Experiences\NeSy\SPL\grids\compute_mpe.py:62](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/SPL/grids/compute_mpe.py:62), in CircuitMPE.get_mpe_inst(self, batch_size)
     61 def get_mpe_inst(self, batch_size):
---> 62     mpe_inst = self.beta.get_mpe(batch_size)
     63     argmax = self.beta.mixing.argmax(dim=-1)
     64     return mpe_inst[torch.arange(batch_size), :, argmax]

File [c:\Users\arthur.ledaguenel\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\utils\_contextlib.py:115](file:///C:/Users/arthur.ledaguenel/AppData/Local/Programs/Python/Python310/lib/site-packages/torch/utils/_contextlib.py:115), in context_decorator..decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File [c:\Users\arthur.ledaguenel\Documents\Experiences\NeSy\./SPL/grids/pypsdd\pypsdd\sdd.py:670](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/SPL/grids/pypsdd/pypsdd/sdd.py:670), in NormalizedSddNode.get_mpe(self, batch_size, clear_data)
    667     #assert(len(data.shape) == 3 and data.shape[0] == len(node.theta) and data.shape[1] == 1)
    669 elif node.is_literal():
--> 670     data = torch.tensor([node.literal], device=DEVICE, dtype=tint).unsqueeze(0).unsqueeze(-1).expand(batch_size, 1, self.num_reps)
    671     #data = torch.full((batch_size, 1, self.num_reps), node.literal, device=DEVICE, dtype=torch.int)
    673 elif node.is_mixing():

AttributeError: 'PSddNode' object has no attribute 'num_reps'uenel\Documents\Experiences\NeSy\test.ipynb](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/test.ipynb) Cell 31 in ()
----> [1](vscode-notebook-cell:/c%3A/Users/arthur.ledaguenel/Documents/Experiences/NeSy/test.ipynb#Y116sZmlsZQ%3D%3D?line=0) suggested_path = cmpe.get_mpe_inst(bsz)

File [c:\Users\arthur.ledaguenel\Documents\Experiences\NeSy\SPL\grids\compute_mpe.py:62](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/SPL/grids/compute_mpe.py:62), in CircuitMPE.get_mpe_inst(self, batch_size)
     61 def get_mpe_inst(self, batch_size):
---> 62     mpe_inst = self.beta.get_mpe(batch_size)
     63     argmax = self.beta.mixing.argmax(dim=-1)
     64     return mpe_inst[torch.arange(batch_size), :, argmax]

File [c:\Users\arthur.ledaguenel\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\utils\_contextlib.py:115](file:///C:/Users/arthur.ledaguenel/AppData/Local/Programs/Python/Python310/lib/site-packages/torch/utils/_contextlib.py:115), in context_decorator..decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File [c:\Users\arthur.ledaguenel\Documents\Experiences\NeSy\./SPL/grids/pypsdd\pypsdd\sdd.py:670](file:///C:/Users/arthur.ledaguenel/Documents/Experiences/NeSy/SPL/grids/pypsdd/pypsdd/sdd.py:670), in NormalizedSddNode.get_mpe(self, batch_size, clear_data)
    667     #assert(len(data.shape) == 3 and data.shape[0] == len(node.theta) and data.shape[1] == 1)
    669 elif node.is_literal():
--> 670     data = torch.tensor([node.literal], device=DEVICE, dtype=tint).unsqueeze(0).unsqueeze(-1).expand(batch_size, 1, self.num_reps)
    671     #data = torch.full((batch_size, 1, self.num_reps), node.literal, device=DEVICE, dtype=torch.int)
    673 elif node.is_mixing():

AttributeError: 'PSddNode' object has no attribute 'num_reps'

Best regards,
Arthur

PS : I have handled the DEVICE problem in the sdd.py file directly so this should not be a source of errors

The problem was that the num_reps attribute is not fixed automatically when the PSddNode is created, but in the Trainer initialization. Adding cmpe.beta.num_reps = 1 did the trick.