



import argparse
import os
import sys
from unittest.mock import patch

import pytorch_lightning as pl
import timeout_decorator
import torch
from distillation import SummarizationDistiller, distill_main
from finetune import SummarizationModule, main

from transformers import MarianMTModel
from transformers.file_utils import cached_path
from transformers.testing_utils import TestCasePlus, require_torch_gpu, slow
from utils import load_json


a_			=					"""sshleifer/mar_enro_6_3_student"""



class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    super().setUp()

    __lowerCamelCase													=    cached_path(
        '''https://cdn-datasets.huggingface.co/translation/wmt_en_ro-tr40k-va0.5k-te0.5k.tar.gz'''	,				extract_compressed_file=__UpperCAmelCase	,				)
    __lowerCamelCase													=    F"""{data_cached}/wmt_en_ro-tr40k-va0.5k-te0.5k"""




 @slow
 @require_torch_gpu
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    MarianMTModel.from_pretrained(__UpperCAmelCase				)




 @slow
 @require_torch_gpu
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    {
        '''$MAX_LEN''': 64,
        '''$BS''': 64,
        '''$GAS''': 1,
        '''$ENRO_DIR''': self.data_dir,
        '''facebook/mbart-large-cc25''': MARIAN_MODEL,
        # "val_check_interval=0.25": "val_check_interval=1.0",
        '''--learning_rate=3e-5''': '''--learning_rate 3e-4''',
        '''--num_train_epochs 6''': '''--num_train_epochs 1''',
    }

    # Clean up bash script
    __lowerCamelCase													=    (self.test_file_dir / '''train_mbart_cc25_enro.sh''').open().read().split('''finetune.py'''				)[1].strip()
    __lowerCamelCase													=    bash_script.replace('''\\\n'''	,				''''''				).strip().replace('''"$@"'''	,				''''''				)
    for k, v in env_vars_to_replace.items():
       __lowerCamelCase													=    bash_script.replace(__UpperCAmelCase	,				str(__UpperCAmelCase				)				)
    __lowerCamelCase													=    self.get_auto_remove_tmp_dir()

    # bash_script = bash_script.replace("--fp16 ", "")
    __lowerCamelCase													=    F"""
            --output_dir {output_dir}
            --tokenizer_name Helsinki-NLP/opus-mt-en-ro
            --sortish_sampler
            --do_predict
            --gpus 1
            --freeze_encoder
            --n_train 40000
            --n_val 500
            --n_test 500
            --fp16_opt_level O1
            --num_sanity_val_steps 0
            --eval_beams 2
        """.split()
    # XXX: args.gpus > 1 : handle multi_gpu in the future

    __lowerCamelCase													=    ['''finetune.py'''] + bash_script.split() + args
    with patch.object(__UpperCAmelCase	,				'''argv'''	,				__UpperCAmelCase				):
       __lowerCamelCase													=    argparse.ArgumentParser()
       __lowerCamelCase													=    pl.Trainer.add_argparse_args(__UpperCAmelCase				)
       __lowerCamelCase													=    SummarizationModule.add_model_specific_args(__UpperCAmelCase	,				os.getcwd()				)
       __lowerCamelCase													=    parser.parse_args()
       __lowerCamelCase													=    main(__UpperCAmelCase				)

    # Check metrics
    __lowerCamelCase													=    load_json(model.metrics_save_path				)
    __lowerCamelCase													=    metrics['''val'''][0]
    __lowerCamelCase													=    metrics['''val'''][-1]
    self.assertEqual(len(metrics['''val''']				)	,				(args.max_epochs / args.val_check_interval)				)
    assert isinstance(last_step_stats[F"""val_avg_{model.val_metric}"""]	,				__UpperCAmelCase				)

    self.assertGreater(last_step_stats['''val_avg_gen_time''']	,				0.01				)
    # model hanging on generate. Maybe bad config was saved. (XXX: old comment/assert?)
    self.assertLessEqual(last_step_stats['''val_avg_gen_time''']	,				1.0				)

    # test learning requirements:

    # 1. BLEU improves over the course of training by more than 2 pts
    self.assertGreater(last_step_stats['''val_avg_bleu'''] - first_step_stats['''val_avg_bleu''']	,				2				)

    # 2. BLEU finishes above 17
    self.assertGreater(last_step_stats['''val_avg_bleu''']	,				17				)

    # 3. test BLEU and val BLEU within ~1.1 pt.
    self.assertLess(abs(metrics['''val'''][-1]['''val_avg_bleu'''] - metrics['''test'''][-1]['''test_avg_bleu''']				)	,				1.1				)

    # check lightning ckpt can be loaded and has a reasonable statedict
    __lowerCamelCase													=    os.listdir(__UpperCAmelCase				)
    __lowerCamelCase													=    [x for x in contents if x.endswith('''.ckpt'''				)][0]
    __lowerCamelCase													=    os.path.join(args.output_dir	,				__UpperCAmelCase				)
    __lowerCamelCase													=    torch.load(__UpperCAmelCase	,				map_location='''cpu'''				)
    __lowerCamelCase													=    '''model.model.decoder.layers.0.encoder_attn_layer_norm.weight'''
    assert expected_key in ckpt["state_dict"]
    assert ckpt["state_dict"]["model.model.decoder.layers.0.encoder_attn_layer_norm.weight"].dtype == torch.floataa

    # TODO: turn on args.do_predict when PL bug fixed.
    if args.do_predict:
       __lowerCamelCase													=    {os.path.basename(__UpperCAmelCase				) for p in contents}
       assert "test_generations.txt" in contents
       assert "test_results.txt" in contents
       # assert len(metrics["val"]) ==  desired_n_evals
       assert len(metrics['''test''']				) == 1



class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 @timeout_decorator.timeout(600				)
 @slow
 @require_torch_gpu
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    F"""{self.test_file_dir_str}/test_data/wmt_en_ro"""
    __lowerCamelCase													=    {
        '''--fp16_opt_level=O1''': '''''',
        '''$MAX_LEN''': 128,
        '''$BS''': 16,
        '''$GAS''': 1,
        '''$ENRO_DIR''': data_dir,
        '''$m''': '''sshleifer/student_marian_en_ro_6_1''',
        '''val_check_interval=0.25''': '''val_check_interval=1.0''',
    }

    # Clean up bash script
    __lowerCamelCase													=    (
        (self.test_file_dir / '''distil_marian_no_teacher.sh''').open().read().split('''distillation.py'''				)[1].strip()
    )
    __lowerCamelCase													=    bash_script.replace('''\\\n'''	,				''''''				).strip().replace('''"$@"'''	,				''''''				)
    __lowerCamelCase													=    bash_script.replace('''--fp16 '''	,				''' '''				)

    for k, v in env_vars_to_replace.items():
       __lowerCamelCase													=    bash_script.replace(__UpperCAmelCase	,				str(__UpperCAmelCase				)				)
    __lowerCamelCase													=    self.get_auto_remove_tmp_dir()
    __lowerCamelCase													=    bash_script.replace('''--fp16'''	,				''''''				)
    __lowerCamelCase													=    6
    __lowerCamelCase													=    (
        ['''distillation.py''']
        + bash_script.split()
        + [
            F"""--output_dir={output_dir}""",
            '''--gpus=1''',
            '''--learning_rate=1e-3''',
            F"""--num_train_epochs={epochs}""",
            '''--warmup_steps=10''',
            '''--val_check_interval=1.0''',
            '''--do_predict''',
        ]
    )
    with patch.object(__UpperCAmelCase	,				'''argv'''	,				__UpperCAmelCase				):
       __lowerCamelCase													=    argparse.ArgumentParser()
       __lowerCamelCase													=    pl.Trainer.add_argparse_args(__UpperCAmelCase				)
       __lowerCamelCase													=    SummarizationDistiller.add_model_specific_args(__UpperCAmelCase	,				os.getcwd()				)
       __lowerCamelCase													=    parser.parse_args()
       # assert args.gpus == gpus THIS BREAKS for multi_gpu

       __lowerCamelCase													=    distill_main(__UpperCAmelCase				)

    # Check metrics
    __lowerCamelCase													=    load_json(model.metrics_save_path				)
    __lowerCamelCase													=    metrics['''val'''][0]
    __lowerCamelCase													=    metrics['''val'''][-1]
    assert len(metrics['''val''']				) >= (args.max_epochs / args.val_check_interval)  # +1 accounts for val_sanity_check

    assert last_step_stats["val_avg_gen_time"] >= 0.01

    assert first_step_stats["val_avg_bleu"] < last_step_stats["val_avg_bleu"]  # model learned nothing
    assert 1.0 >= last_step_stats["val_avg_gen_time"]  # model hanging on generate. Maybe bad config was saved.
    assert isinstance(last_step_stats[F"""val_avg_{model.val_metric}"""]	,				__UpperCAmelCase				)

    # check lightning ckpt can be loaded and has a reasonable statedict
    __lowerCamelCase													=    os.listdir(__UpperCAmelCase				)
    __lowerCamelCase													=    [x for x in contents if x.endswith('''.ckpt'''				)][0]
    __lowerCamelCase													=    os.path.join(args.output_dir	,				__UpperCAmelCase				)
    __lowerCamelCase													=    torch.load(__UpperCAmelCase	,				map_location='''cpu'''				)
    __lowerCamelCase													=    '''model.model.decoder.layers.0.encoder_attn_layer_norm.weight'''
    assert expected_key in ckpt["state_dict"]
    assert ckpt["state_dict"]["model.model.decoder.layers.0.encoder_attn_layer_norm.weight"].dtype == torch.floataa

    # TODO: turn on args.do_predict when PL bug fixed.
    if args.do_predict:
       __lowerCamelCase													=    {os.path.basename(__UpperCAmelCase				) for p in contents}
       assert "test_generations.txt" in contents
       assert "test_results.txt" in contents
       # assert len(metrics["val"]) ==  desired_n_evals
       assert len(metrics['''test''']				) == 1











import unittest

from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
from transformers.pipelines import pipeline
from transformers.pipelines.document_question_answering import apply_tesseract
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_detectrona,
    require_pytesseract,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
  from PIL import Image

  from transformers.image_utils import load_image
else:



  class  __lowerCAmelCase     :




   @staticmethod
   def        lowerCamelCase      (						*__UpperCAmelCase	,				**__UpperCAmelCase				):



      '''simple docstring'''
      pass





  def 		a__			(		_UpperCamelCase			: List[str]							):
     return None


# This is a pinned image from a specific revision of a document question answering space, hosted by HuggingFace,
# so we can expect it to be available.
a_			=					(
    """https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png"""
)



@is_pipeline_test
@require_torch
@require_vision
class  __lowerCAmelCase     (	unittest.TestCase   ):
 lowerCAmelCase__       					=  MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING




 @require_pytesseract
 @require_vision
 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model=__UpperCAmelCase	,				tokenizer=__UpperCAmelCase	,				image_processor=__UpperCAmelCase				)

    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    list(zip(*apply_tesseract(load_image(__UpperCAmelCase				)	,				__UpperCAmelCase	,				''''''				)				)				)
    __lowerCamelCase													=    '''What is the placebo?'''
    __lowerCamelCase													=    [
        {
            '''image''': load_image(__UpperCAmelCase				),
            '''question''': question,
        },
        {
            '''image''': image,
            '''question''': question,
        },
        {
            '''image''': image,
            '''question''': question,
            '''word_boxes''': word_boxes,
        },
    ]
    return dqa_pipeline, examples




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    dqa_pipeline(__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(
        __UpperCAmelCase	,				[
            [
                {'''score''': ANY(__UpperCAmelCase				), '''answer''': ANY(__UpperCAmelCase				), '''start''': ANY(__UpperCAmelCase				), '''end''': ANY(__UpperCAmelCase				)},
                {'''score''': ANY(__UpperCAmelCase				), '''answer''': ANY(__UpperCAmelCase				), '''start''': ANY(__UpperCAmelCase				), '''end''': ANY(__UpperCAmelCase				)},
            ]
        ]
        * 3	,				)




 @require_torch
 @require_detectrona
 @require_pytesseract
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    pipeline('''document-question-answering'''	,				model='''hf-internal-testing/tiny-random-layoutlmv2'''				)
    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''How many cats are there?'''

    __lowerCamelCase													=    [
        {'''score''': 0.0_001, '''answer''': '''oy 2312/2019''', '''start''': 38, '''end''': 39},
        {'''score''': 0.0_001, '''answer''': '''oy 2312/2019 DUE''', '''start''': 38, '''end''': 40},
    ]
    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				__UpperCAmelCase				)

    __lowerCamelCase													=    dqa_pipeline({'''image''': image, '''question''': question}	,				top_k=2				)
    self.assertEqual(nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				__UpperCAmelCase				)

    # This image does not detect ANY text in it, meaning layoutlmv2 should fail.
    # Empty answer probably
    __lowerCamelCase													=    '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(__UpperCAmelCase	,				[]				)

    # We can optionnally pass directly the words and bounding boxes
    __lowerCamelCase													=    '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
    __lowerCamelCase													=    []
    __lowerCamelCase													=    []
    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				words=__UpperCAmelCase	,				boxes=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(__UpperCAmelCase	,				[]				)




 @slow
 @require_torch
 @require_detectrona
 @require_pytesseract
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model='''tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa'''	,				revision='''9977165'''	,				)
    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''What is the invoice number?'''

    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_944, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.0_009, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline({'''image''': image, '''question''': question}	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_944, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.0_009, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline(
        [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            [
                {'''score''': 0.9_944, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
                {'''score''': 0.0_009, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            ],
        ]
        * 2	,				)




 @slow
 @require_torch
 @require_detectrona
 @require_pytesseract
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model='''tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa'''	,				revision='''9977165'''	,				max_seq_len=50	,				)
    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''What is the invoice number?'''

    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_974, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
            {'''score''': 0.9_948, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline({'''image''': image, '''question''': question}	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_974, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
            {'''score''': 0.9_948, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline(
        [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            [
                {'''score''': 0.9_974, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
                {'''score''': 0.9_948, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            ]
        ]
        * 2	,				)




 @slow
 @require_torch
 @require_pytesseract
 @require_vision
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    AutoTokenizer.from_pretrained(
        '''impira/layoutlm-document-qa'''	,				revision='''3dc6de3'''	,				add_prefix_space=__UpperCAmelCase				)
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model='''impira/layoutlm-document-qa'''	,				tokenizer=__UpperCAmelCase	,				revision='''3dc6de3'''	,				)
    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''What is the invoice number?'''

    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.4_251, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.0_819, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline({'''image''': image, '''question''': question}	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.4_251, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.0_819, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline(
        [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            [
                {'''score''': 0.4_251, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
                {'''score''': 0.0_819, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
            ]
        ]
        * 2	,				)

    __lowerCamelCase													=    list(zip(*apply_tesseract(load_image(__UpperCAmelCase				)	,				__UpperCAmelCase	,				''''''				)				)				)

    # This model should also work if `image` is set to None
    __lowerCamelCase													=    dqa_pipeline({'''image''': None, '''word_boxes''': word_boxes, '''question''': question}	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.4_251, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.0_819, '''answer''': '''1110212019''', '''start''': 23, '''end''': 23},
        ]	,				)




 @slow
 @require_torch
 @require_pytesseract
 @require_vision
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    AutoTokenizer.from_pretrained(
        '''impira/layoutlm-document-qa'''	,				revision='''3dc6de3'''	,				add_prefix_space=__UpperCAmelCase				)
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model='''impira/layoutlm-document-qa'''	,				tokenizer=__UpperCAmelCase	,				revision='''3dc6de3'''	,				max_seq_len=50	,				)
    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''What is the invoice number?'''

    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_999, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.9_998, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)

    __lowerCamelCase													=    dqa_pipeline(
        [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            [
                {'''score''': 0.9_999, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
                {'''score''': 0.9_998, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            ]
        ]
        * 2	,				)

    __lowerCamelCase													=    list(zip(*apply_tesseract(load_image(__UpperCAmelCase				)	,				__UpperCAmelCase	,				''''''				)				)				)

    # This model should also work if `image` is set to None
    __lowerCamelCase													=    dqa_pipeline({'''image''': None, '''word_boxes''': word_boxes, '''question''': question}	,				top_k=2				)
    self.assertEqual(
        nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[
            {'''score''': 0.9_999, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
            {'''score''': 0.9_998, '''answer''': '''us-001''', '''start''': 16, '''end''': 16},
        ]	,				)




 @slow
 @require_torch
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    pipeline(
        '''document-question-answering'''	,				model='''naver-clova-ix/donut-base-finetuned-docvqa'''	,				tokenizer=AutoTokenizer.from_pretrained('''naver-clova-ix/donut-base-finetuned-docvqa'''				)	,				feature_extractor='''naver-clova-ix/donut-base-finetuned-docvqa'''	,				)

    __lowerCamelCase													=    INVOICE_URL
    __lowerCamelCase													=    '''What is the invoice number?'''
    __lowerCamelCase													=    dqa_pipeline(image=__UpperCAmelCase	,				question=__UpperCAmelCase	,				top_k=2				)
    self.assertEqual(nested_simplify(__UpperCAmelCase	,				decimals=4				)	,				[{'''answer''': '''us-001'''}]				)




 @require_tf
 @unittest.skip('''Document question answering not implemented in TF'''				)
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass






