KEMBAR78
Fix code examples for doctests by stevhliu · Pull Request #17013 · huggingface/transformers · GitHub
Skip to content

Conversation

@stevhliu
Copy link
Member

This PR fixes some code examples to pass the doctests for the pipeline and AutoClass tutorials.

I was unable to pass the audio code examples on my local machine because soundfile is not supported on M1 yet. I was able to run and reproduce the code snippets in Colab though so I think they should also pass on the CI.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 29, 2022

The documentation is not available anymore as the PR was closed or merged.

@stevhliu stevhliu requested review from sgugger and ydshieh April 29, 2022 20:53
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

Comment on lines 150 to 151
>>> print(preds)
[{'score': 0.4403, 'label': 'lynx, catamount'}, {'score': 0.0343, 'label': 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor'}, {'score': 0.0321, 'label': 'snow leopard, ounce, Panthera uncia'}, {'score': 0.0235, 'label': 'Egyptian cat'}, {'score': 0.023, 'label': 'tiger cat'}]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we show the results as above? The doc test will pass if your replace any space by a new line, it only cares that there is whitespace.

@ydshieh
Copy link
Collaborator

ydshieh commented Apr 30, 2022

Thanks for the work.

Other than the >>> things, there are 2 failures when I ran it.

For audio pipeline:

Expected:
    [{'label': 'calm', 'score': 0.1315},
     {'label': 'neutral', 'score': 0.1307},
     {'label': 'sad', 'score': 0.1274},
     {'label': 'fearful', 'score': 0.1261},
     {'label': 'happy', 'score': 0.1242}]
Got:
    [{'score': 0.1315, 'label': 'calm'}, {'score': 0.1307, 'label': 'neutral'}, {'score': 0.1274, 'label': 'sad'}, {'score': 0.1261, 'label': 'fearful'}, {'score': 0.1242, 'label': 'happy'}]

(this is just a format issue I think)

For vision pipeline:

Expected:
    [{'score': 0.4403, 'label': 'lynx, catamount'}, {'score': 0.0343, 'label': 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor'}, {'score': 0.0321, 'label': 'snow leopard, ounce, Panthera uncia'}, {'score': 0.0235, 'label': 'Egyptian cat'}, {'score': 0.023, 'label': 'tiger cat'}]
Got:
    [{'score': 0.4335, 'label': 'lynx, catamount'}, {'score': 0.0348, 'label': 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor'}, {'score': 0.0324, 'label': 'snow leopard, ounce, Panthera uncia'}, {'score': 0.0239, 'label': 'Egyptian cat'}, {'score': 0.0229, 'label': 'tiger cat'}]

(This might be due to some random ops. I remembered I have similar situations before. I can take a look too.)
I get deterministic results, which is on Ubuntu 20.04. It's not very clear why the result is different than the previous one in the doc. I also get the same results on my local Windows machine. Maybe we could just update the values, cc @sgugger?

@sgugger
Copy link
Collaborator

sgugger commented May 2, 2022

I don't know why you ask me @ydshieh this is not my PR ;-)

@ydshieh
Copy link
Collaborator

ydshieh commented May 2, 2022

I don't know why you ask me @ydshieh this is not my PR ;-)

I know. Just to make sure you are also fine with my suggestion about just update the values. But I guess I should be more confident 😄

stevhliu and others added 21 commits May 3, 2022 13:36
…gface#17007)

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
)

* Replace dict/BatchEncoding instance checks by Mapping

* Typo
* Result of new doc style with fixes

* Add last two files

* Bump hf-doc-builder
* Add the check

* add missing ckpts

* add a list to ignore

* call the added check script

* better regex pattern

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
* Add meta proxy

* Uses meta data to trace data dependent control-flow

* Remove commented class

* Handles torch creating functions

* Added type annotation to fix tracing

* Tracing works for everything but T5 and GPT-J

* Almost all previously supported models pass

* All architectures can be traced except T5

* Intermediate commit to have a trace of the comparison operators for HFProxy

* Everything works, except loss computation

* Everything works

* Removed unused import

* Overriden methods do not use underlying ops (linear and torch.matmul), and model attributes are copied to the traced version

* Fix torch_matmul_override

* Change attributes reference to deepcopy

* Remove breakpoint and add torch_index_override

* Small fix

* Fix typo

* Replace asserts by explicit exceptions
…#17036)

* [FlaxSpeechEncoderDecoder] Fix bug in `decoder_module`

* [FlaxEncoderDecoder] Fix bug in `decoder_module`
* add torch.no_grad when in eval mode

* make style quality
NielsRogge and others added 16 commits May 3, 2022 14:12
* Clean up tests

* Make fixup

Co-authored-by: Niels Rogge <nielsrogge@Nielss-MacBook-Pro.local>
* First draft

* Add YolosForObjectDetection

* Make forward pass work

* Add mid position embeddings

* Add interpolation of position encodings

* Add expected values

* Add YOLOS to tests

* Add integration test

* Support tiny model as well

* Support all models in conversion script

* Remove mid_pe_size attribute

* Make more tests pass

* Add model to README and fix config

* Add copied from statements

* Rename base_model_prefix to vit

* Add missing YOLOS_PRETRAINED_CONFIG_ARCHIVE_MAP

* Apply suggestions from code review

* Apply more suggestions from code review

* Convert remaining checkpoints

* Improve docstrings

* Add YolosFeatureExtractor

* Add feature extractor to docs

* Add corresponding tests

* Fix style

* Fix docs

* Apply suggestion from code review

* Fix bad rebase

* Fix some more bad rebase

* Fix missing character

* Improve docs and variable names

Co-authored-by: Niels Rogge <nielsrogge@Nielss-MacBook-Pro.local>
* Clean up setup.py

* Trigger CI

* Upgrade Python used
huggingface#16990)

* [T5 Tokenizer] Model has no fixed position ids - there is no hardcoded max length

* [T5 Tokenizer] Model has no fixed position ids - there is no hardcoded max length

* correct t5 tokenizer

* correct t5 tokenizer

* fix test

* Apply suggestions from code review

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

* finish

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
* [FlaxBert] Add ForCausalLM

* make style

* fix output attentions

* Add RobertaForCausalLM

* remove comment

* fix fx-to-pt model loading

* remove comment

* add modeling tests

* add enc-dec model tests

* add big_bird

* add electra

* make style

* make repo-consitency

* add to docs

* remove roberta test

* quality

* amend cookiecutter

* fix attention_mask bug in flax bert model tester

* tighten pt-fx thresholds to 1e-5

* add 'copied from' statements

* amend 'copied from' statements

* amend 'copied from' statements

* quality
* move test model folders (TODO: fix imports and others)

* fix (potentially partially) imports (in model test modules)

* fix (potentially partially) imports (in tokenization test modules)

* fix (potentially partially) imports (in feature extraction test modules)

* fix import utils.test_modeling_tf_core

* fix path ../fixtures/

* fix imports about generation.test_generation_flax_utils

* fix more imports

* fix fixture path

* fix get_test_dir

* update module_to_test_file

* fix get_tests_dir from wrong transformers.utils

* update config.yml (CircleCI)

* fix style

* remove missing imports

* update new model script

* update check_repo

* update SPECIAL_MODULE_TO_TEST_MAP

* fix style

* add __init__

* update self-scheduled

* fix add_new_model scripts

* check one way to get location back

* python setup.py build install

* fix import in test auto

* update self-scheduled.yml

* update slack notification script

* Add comments about artifact names

* fix for yolos

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
* Make Trainer compatible with sharded checkpoints

* Add doc
…17055)

* Fix RNG reload in resume training from epoch checkpoint

* Fix test
@stevhliu stevhliu mentioned this pull request May 3, 2022
@stevhliu stevhliu closed this May 3, 2022
@stevhliu stevhliu deleted the add-doctests branch May 4, 2022 00:50
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.