Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-enable decoder sequence classification #1679

Merged
merged 5 commits into from
Feb 8, 2024

Conversation

dwyatte
Copy link
Contributor

@dwyatte dwyatte commented Feb 2, 2024

What does this PR do?

Re-enables sequence classification for decoder-based models. This requires a user to pass in --pad_token_id which required a change to the tests

I also removed a default pad token override for GPT-2 which seemed like a bad idea (sets it to 0, which corresponds to !) -- let me know if this is problematic

This passes a fair number of tests in tests/exporters/onnx/ for me, but I deselected some so we may need to iterate here

Fixes #1527

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@dwyatte dwyatte marked this pull request as ready for review February 2, 2024 23:04
Copy link
Contributor

@fxmarty fxmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you for the fix!

@dwyatte
Copy link
Contributor Author

dwyatte commented Feb 6, 2024

Digging into some test failures

Failing on main:

FAILED onnxruntime/test_quantization.py::ORTDynamicQuantizationTest::test_dynamic_quantization_subgraphs - AttributeError: 'NoneType' object has no attribute 'HasField'

Failing on this branch:

FAILED exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_060_bloom_feature_extraction_with_past_default_hf_internal_testing_tiny_random_BloomModel - RuntimeError: dictionary changed size during iteration
FAILED exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_061_bloom_feature_extraction_with_past_no_postprocess_default_hf_internal_testing_tiny_random_BloomModel - RuntimeError: dictionary changed size during iteration
FAILED exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_no_dynamic_axes_07_gpt2_feature_extraction_with_past_default_hf_internal_testing_tiny_random_gpt2 - RuntimeError: dictionary changed size during iteration
FAILED exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_no_dynamic_axes_08_gpt2_feature_extraction_with_past_no_postprocess_default_hf_internal_testing_tiny_random_gpt2 - RuntimeError: dictionary changed size during iteration

but they pass locally for me. They appear to print out some warnings about tracing, wonder if my env is different than the CI env

========================================================================================================================================= warnings summary ==========================================================================================================================================
tests/exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_230_gpt2_feature_extraction_with_past_default_hf_internal_testing_tiny_random_gpt2
  /mnt/nfs/dwyatte/Development/cash-customer-support-ml/user-folders/dwyatte/optimum/venv/lib/python3.9/site-packages/torch/_utils.py:831: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    return self.fget.__get__(instance, owner)()

tests/exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_230_gpt2_feature_extraction_with_past_default_hf_internal_testing_tiny_random_gpt2
tests/exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_231_gpt2_feature_extraction_with_past_no_postprocess_default_hf_internal_testing_tiny_random_gpt2
tests/exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_no_dynamic_axes_07_gpt2_feature_extraction_with_past_default_hf_internal_testing_tiny_random_gpt2
tests/exporters/onnx/test_exporters_onnx_cli.py::OnnxCLIExportTestCase::test_exporters_cli_pytorch_cpu_no_dynamic_axes_08_gpt2_feature_extraction_with_past_no_postprocess_default_hf_internal_testing_tiny_random_gpt2
  /mnt/nfs/dwyatte/Development/cash-customer-support-ml/user-folders/dwyatte/optimum/venv/lib/python3.9/site-packages/transformers/models/gpt2/modeling_gpt2.py:801: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
    if batch_size <= 0:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
====================================================================================================================== 614 passed, 2 skipped, 7 warnings in 163.98s (0:02:43) =======================================================================================================================

Results of optimum-cli env:

Copy-and-paste the text below in your GitHub issue:

- `optimum` version: 1.17.0.dev0
- `transformers` version: 4.37.2
- Platform: Linux-4.19.0-25-cloud-amd64-x86_64-with-glibc2.35
- Python version: 3.9.17
- Huggingface_hub version: 0.19.4
- PyTorch version (GPU?): 2.1.2+cu121 (cuda availabe: False)
- Tensorflow version (GPU?): not installed (cuda availabe: NA)

@fxmarty
Copy link
Contributor

fxmarty commented Feb 7, 2024

Thank you @dwyatte, these failing tests are fine as unrelated, and fixed in #1683 & microsoft/onnxruntime#19421

@dwyatte dwyatte force-pushed the fix_causallm_classification branch from 7256b14 to 0add749 Compare February 7, 2024 15:15
@dwyatte
Copy link
Contributor Author

dwyatte commented Feb 7, 2024

Great, just rebased so I think this should be ready to go now

@fxmarty
Copy link
Contributor

fxmarty commented Feb 8, 2024

Thank you!

@fxmarty fxmarty merged commit 3988bbd into huggingface:main Feb 8, 2024
50 of 62 checks passed
young-developer pushed a commit to young-developer/optimum that referenced this pull request May 10, 2024
* re-enable decoder sequence classification

* update tests

* revert to better pad token handling logic

* minor updates

* format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support exporting text-generation models for sequence classification to ONNX
2 participants