Skip to content

run_squad questions #3

Closed
Closed

Description

@ZhaoyueCheng

Thanks a lot for the port! I have some minor questions, for the run_squad file, I see two options for accumulating gradients, accumulate_gradients and gradient_accumulation_steps but it seems to me that it can be combined into one. The other one is for the global_step variable, seems we are only counting but not using this variable in gradient accumulating. Thanks again!

Activity

  1. ZhaoyueCheng commented on Nov 5, 2018

    @ZhaoyueCheng
    Author

    It also seems to me that the SQuAD 1.1 can not reproduce the google tensorflow version performance.

  2. self-assigned this
    on Nov 5, 2018
  3. abeljim commented on Nov 5, 2018

    @abeljim
    Contributor

    It also seems to me that the SQuAD 1.1 can not reproduce the google tensorflow version performance.

    What batch size are you running?

  4. ZhaoyueCheng commented on Nov 6, 2018

    @ZhaoyueCheng
    Author

    I'm running on 4 GPU with a batch size of 48, the result is {"exact_match": 21.551561021759696, "f1": 41.785968963154055}

  5. abeljim commented on Nov 6, 2018

    @abeljim
    Contributor

    Just ran on 1 GPU batch size of 10, the result is {"exact_match": 21.778618732261116, "f1": 41.83593185416649}
    Actually it might be with the eval code Ill look into it

  6. ZhaoyueCheng commented on Nov 6, 2018

    @ZhaoyueCheng
    Author

    Sure, Thanks, I'm checking for the reason too, will report if find anything.

  7. abeljim commented on Nov 6, 2018

    @abeljim
    Contributor

    The predictions file is only outputting one word. Need to find out if the bug is in the model itself or write predictions function in run_squad.py. The correct answer always seems to be in the nbest_predictions, but its never selected.

  8. changed the title [-]Minor run_squad questions[/-] [+]run_squad questions[/+] on Nov 6, 2018
  9. ethanjperez commented on Nov 6, 2018

    @ethanjperez
    Contributor

    What performance does Hugging Face get on SQuAD using this reimplementation?

  10. thomwolf commented on Nov 6, 2018

    @thomwolf
    Member

    Hi all,
    We were not able to try SQuAD on a multi-GPU with the correct batch_size until recently so we relied on the standard deviations computed in the notebooks to compare the predicted hidden states and losses for the SQuAD script. I was able to try on a multi-GPU today and there is indeed a strong difference.
    We got about the same results that you get: F1 of 41.8 and exact match of 21.7.
    I am investigating that right now, my personal guess is that this may be related to things outside the model it-self like the optimizer or the post-processing in SQuAD as these were not compared between the TF and PT models.
    I will keep you guys updated in this issue and I add a mention in the readme that the SQuAD example doesn't work yet.
    If you have some insights, feel free to participate in the discussion.

  11. self-assigned this
    on Nov 6, 2018
  12. ethanjperez commented on Nov 6, 2018

    @ethanjperez
    Contributor

    If you're comparing activations, it may be worth comparing gradients as well to see if you receive similarly low gradients standard deviations for identical batches. You might see that the gradient is not comparable from the last layer itself (due to e.g. difference in how PyTorch may handle weight decay / optimization differently); you may also see that gradients only become not comparable only after a particular point in backpropagation, and that would show perhaps that the backward pass for a particular function differs between PyTorch and Tensorflow

  13. thomwolf commented on Nov 7, 2018

    @thomwolf
    Member

    Ok guys thanks for waiting, we've nailed down the culprit which was in fact a bug in the pre-processing logic (more exactly this dumb typo https://github.com/huggingface/pytorch-pretrained-BERT/blob/master/run_squad.py#L865).

    I took the occasion to clean up a few things I noticed while walking through the code:

    • the weight initialization was not optimal (tf. truncated_normal_initializer(stddev=0.02) was translated in weight.data.normal_(0.02) instead of weight.data.normal_(mean=0.0, std=0.02) which likely affected the performance of run_classifer.py also.
    • gradient accumulation loss was not averaged over the accumulation steps which would have required to change the hyper-parameters for using accumulation.
    • the evaluation was not done with torch.no_grad() and thus sub-optimal in terms of speed/memory.

    These fixes are pushed on the develop branch right now.

    All in all I think we are pretty good now and none of these issues affected the core PyTorch model (the BERT Transformer it-self) so if you only used extract_features.py you were good from the beginning. And run_classifer.py was ok apart from the sub-optimal additional weights initialization.

    I will merge the develop branch as soon as we got the final results confirmed (currently it's been training for 20 minutes (0.3 epoch) on 4GPU with a batch size of 56 and we are already above 85 on F1 on SQuAD and 77 in exact match so I'm rather confident and I think you guys can play with it too now).

    I am also cleaning up the code base to prepare for a first release that we will put on pip for easier access.

  14. ethanjperez commented on Nov 8, 2018

    @ethanjperez
    Contributor

    @thomwolf This is awesome - thank you! Do you know what the final SQuAD results were from the training run you started?

  15. 86 remaining items

  16. added a commit that references this issue on Oct 28, 2025
  17. added a commit that references this issue on Nov 19, 2025
  18. added a commit that references this issue on Apr 22, 2026
  19. added a commit that references this issue on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions