microsoft / CodeXGLUE

CodeXGLUE
MIT License
1.51k stars 363 forks source link

Error in line-completion evaluation - even after the known fix #101

Closed urialon closed 2 years ago

urialon commented 2 years ago

Hi, Thank you for releasing this project!

I got an error while running line-completion evaluation using the command line here: https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/CodeCompletion-line#inference

Then I found a past issue ( https://github.com/microsoft/CodeXGLUE/issues/74#issuecomment-990986297 ) where @LIANGQINGYUAN suggested changing this line https://github.com/microsoft/CodeXGLUE/blob/main/Code-Code/CodeCompletion-line/code/run_lm.py#L376 from:

past_hidden = [x[:, i:i+1].expand(-1, beam_size, -1, -1, -1) for x in outputs]

to this:

past = [torch.cat([x[0].unsqueeze(0),x[1].unsqueeze(0)],dim=0) if type(x)==tuple else x for x in outputs]
past_hidden = [x.data.index_select(1, beam.getCurrentOrigin()) for x in past]

However, this change requires also moving the initialization of the Beam object from https://github.com/microsoft/CodeXGLUE/blob/main/Code-Code/CodeCompletion-line/code/run_lm.py#L377 to before the change to the past_hidden line. If I fix this by moving up the beam initialization, I encounter another error:

  File ".../CodeXGLUE/Code-Code/CodeCompletion-line/code/run_lm.py", line 379, in <listcomp>
    past_hidden = [x.data.index_select(1, beam.getCurrentOrigin()) for x in past]
  File "...//CodeXGLUE/Code-Code/CodeCompletion-line/code/beam.py", line 32, in getCurrentOrigin
    return self.prevKs[-1]
IndexError: list index out of range

any advice? Thanks!

celbree commented 2 years ago

Hi, maybe we don't need move the Beam initialization. By changing

past = [torch.cat([x[0].unsqueeze(0),x[1].unsqueeze(0)],dim=0) if type(x)==tuple else x for x in outputs]
past_hidden = [x.data.index_select(1, beam.getCurrentOrigin()) for x in past]

to

past = [torch.cat([x[0].unsqueeze(0),x[1].unsqueeze(0)],dim=0) if type(x)==tuple else x for x in outputs]
past_hidden = [x[:, i:i+1].expand(-1, beam_size, -1, -1, -1) for x in past]

Then it works.

BTW, I have commit this changes to the file https://github.com/microsoft/CodeXGLUE/commit/78e6812a3315c6096b764048e8235d592c00da35

urialon commented 2 years ago

Thank you for the quick response!