
# This script creates a super tiny model that is useful inside tests, when we just want to test that
# the machinery works, without needing to the check the quality of the outcomes.
#
# This version creates a tiny model through reduction of a normal pre-trained model, but keeping the
# full vocab, merges file, and thus also resulting in a larger model due to a large vocab size.
# This gives ~3MB in total for all files.
#
# If you want a 50 times smaller than this see `fsmt-make-super-tiny-model.py`, which is slightly more complicated
#
#
# It will be used then as "stas/tiny-wmt19-en-de"

# Build
from transformers import FSMTTokenizer, FSMTConfig, FSMTForConditionalGeneration

__lowerCAmelCase			:     Tuple           =   'facebook/wmt19-en-de'
__lowerCAmelCase			:     Union[str, Any]           =   FSMTTokenizer.from_pretrained(mname)
# get the correct vocab sizes, etc. from the master model
__lowerCAmelCase			:     Dict           =   FSMTConfig.from_pretrained(mname)
config.update(
    dict(
        d_model=4,
        encoder_layers=1,
        decoder_layers=1,
        encoder_ffn_dim=4,
        decoder_ffn_dim=4,
        encoder_attention_heads=1,
        decoder_attention_heads=1,
    )
)

__lowerCAmelCase			:     List[str]           =   FSMTForConditionalGeneration(config)
print(F'''num of params {tiny_model.num_parameters()}''')

# Test
__lowerCAmelCase			:     Optional[int]           =   tokenizer(['Making tiny model'], return_tensors='pt')
__lowerCAmelCase			:     List[str]           =   tiny_model(**batch)

print('test output:', len(outputs.logits[0]))

# Save
__lowerCAmelCase			:     Any           =   'tiny-wmt19-en-de'
tiny_model.half()  # makes it smaller
tiny_model.save_pretrained(mname_tiny)
tokenizer.save_pretrained(mname_tiny)

print(F'''Generated {mname_tiny}''')

# Upload
# transformers-cli upload tiny-wmt19-en-de



import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY


@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class 				lowercase					(		unittest.TestCase   ):
		__lowercase       :       Any	     =				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



		def __UpperCamelCase ( self				,      A_				,      A_				,      A_       )  ->					List[Any]:
				"""simple docstring"""
				UpperCamelCase		=     hf_hub_download(
				    repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     VideoClassificationPipeline(model=A_				,      image_processor=A_				,      top_k=2       )
				UpperCamelCase		=     [
				    example_video_filepath,
				    'https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4',
				]
				return video_classifier, examples



		def __UpperCamelCase ( self				,      A_				,      A_       )  ->					Optional[int]:
				"""simple docstring"""
				for example in examples:
						UpperCamelCase		=     video_classifier(A_       )

						self.assertEqual(
						    A_				,      [
						        {'score': ANY(A_       ), 'label': ANY(A_       )},
						        {'score': ANY(A_       ), 'label': ANY(A_       )},
						    ]				,      )



		@require_torch
		def __UpperCamelCase ( self       )  ->					Optional[Any]:
				"""simple docstring"""
				UpperCamelCase		=     'hf-internal-testing/tiny-random-VideoMAEForVideoClassification'
				UpperCamelCase		=     VideoMAEFeatureExtractor(
				    size={'shortest_edge': 10}				,      crop_size={'height': 10, 'width': 10}       )
				UpperCamelCase		=     pipeline(
				    'video-classification'				,      model=A_				,      feature_extractor=A_				,      frame_sampling_rate=4       )

				UpperCamelCase		=     hf_hub_download(repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     video_classifier(A_				,      top_k=2       )
				self.assertEqual(
				    nested_simplify(A_				,      decimals=4       )				,      [{'score': 0.5199, 'label': 'LABEL_0'}, {'score': 0.4801, 'label': 'LABEL_1'}]				,      )

				UpperCamelCase		=     video_classifier(
				    [
				        video_file_path,
				        video_file_path,
				    ]				,      top_k=2				,      )
				self.assertEqual(
				    nested_simplify(A_				,      decimals=4       )				,      [
				        [{'score': 0.5199, 'label': 'LABEL_0'}, {'score': 0.4801, 'label': 'LABEL_1'}],
				        [{'score': 0.5199, 'label': 'LABEL_0'}, {'score': 0.4801, 'label': 'LABEL_1'}],
				    ]				,      )



		@require_tf
		def __UpperCamelCase ( self       )  ->					Tuple:
				"""simple docstring"""
				pass
