text stringlengths 0 9.36M |
|---|
from transformers.testing_utils import pytest_terminal_summary_main |
make_reports = terminalreporter.config.getoption("--make-reports") |
if make_reports: |
pytest_terminal_summary_main(terminalreporter, id=make_reports) |
def pytest_sessionfinish(session, exitstatus): |
# If no tests are collected, pytest exists with code 5, which makes the CI fail. |
if exitstatus == 5: |
session.exitstatus = 0 |
# Doctest custom flag to ignore output. |
IGNORE_RESULT = doctest.register_optionflag('IGNORE_RESULT') |
OutputChecker = doctest.OutputChecker |
class CustomOutputChecker(OutputChecker): |
def check_output(self, want, got, optionflags): |
if IGNORE_RESULT & optionflags: |
return True |
return OutputChecker.check_output(self, want, got, optionflags) |
doctest.OutputChecker = CustomOutputChecker |
File: hubconf.py |
Contents: |
# Copyright 2020 The HuggingFace Team. All rights reserved. |
# |
# Licensed under the Apache License, Version 2.0 (the "License"); |
# you may not use this file except in compliance with the License. |
# You may obtain a copy of the License at |
# |
# http://www.apache.org/licenses/LICENSE-2.0 |
# |
# Unless required by applicable law or agreed to in writing, software |
# distributed under the License is distributed on an "AS IS" BASIS, |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
# See the License for the specific language governing permissions and |
# limitations under the License. |
import os |
import sys |
SRC_DIR = os.path.join(os.path.dirname(__file__), "src") |
sys.path.append(SRC_DIR) |
from transformers import ( |
AutoConfig, |
AutoModel, |
AutoModelForCausalLM, |
AutoModelForMaskedLM, |
AutoModelForQuestionAnswering, |
AutoModelForSequenceClassification, |
AutoTokenizer, |
add_start_docstrings, |
) |
dependencies = ["torch", "numpy", "tokenizers", "filelock", "requests", "tqdm", "regex", "sentencepiece", "sacremoses", "importlib_metadata", "huggingface_hub"] |
@add_start_docstrings(AutoConfig.__doc__) |
def config(*args, **kwargs): |
r""" |
# Using torch.hub ! |
import torch |
config = torch.hub.load('huggingface/transformers', 'config', 'bert-base-uncased') # Download configuration from huggingface.co and cache. |
config = torch.hub.load('huggingface/transformers', 'config', './test/bert_saved_model/') # E.g. config (or model) was saved using `save_pretrained('./test/saved_model/')` |
config = torch.hub.load('huggingface/transformers', 'config', './test/bert_saved_model/my_configuration.json') |
config = torch.hub.load('huggingface/transformers', 'config', 'bert-base-uncased', output_attentions=True, foo=False) |
assert config.output_attentions == True |
config, unused_kwargs = torch.hub.load('huggingface/transformers', 'config', 'bert-base-uncased', output_attentions=True, foo=False, return_unused_kwargs=True) |
assert config.output_attentions == True |
assert unused_kwargs == {'foo': False} |
""" |
return AutoConfig.from_pretrained(*args, **kwargs) |
@add_start_docstrings(AutoTokenizer.__doc__) |
def tokenizer(*args, **kwargs): |
r""" |
# Using torch.hub ! |
import torch |
tokenizer = torch.hub.load('huggingface/transformers', 'tokenizer', 'bert-base-uncased') # Download vocabulary from huggingface.co and cache. |
tokenizer = torch.hub.load('huggingface/transformers', 'tokenizer', './test/bert_saved_model/') # E.g. tokenizer was saved using `save_pretrained('./test/saved_model/')` |
""" |
return AutoTokenizer.from_pretrained(*args, **kwargs) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.