From 02f5b7a7e34ef7a41598504d5d6545319bba159b Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 21 Sep 2023 17:30:17 +0200 Subject: [PATCH 01/43] [PT FE] Add huggingface hub tests (#19858) * [PT FE] Add huggingface hub tests * Update requirements.txt * natten can't be installed * Remove librosa * Add xfail and skip marks * Remove t5 * Free up space * Apply suggestions from code review * Report free space * Clean pip cache * Temporarily disable det2 models * More du info * Remove tmp info * More du stats * Fix du report * Optimize du * Ignore error * Finalize changes * Update tests/model_hub_tests/torch_tests/test_transformers.py --- .github/workflows/linux.yml | 23 +- .../models_hub_common/test_convert_model.py | 2 +- .../torch_tests/hf_transformers_models | 411 ++++++++++++++++++ .../torch_tests/requirements.txt | 9 + .../torch_tests/requirements_secondary.txt | 3 +- .../torch_tests/test_transformers.py | 287 ++++++++++++ 6 files changed, 731 insertions(+), 4 deletions(-) create mode 100644 tests/model_hub_tests/torch_tests/hf_transformers_models create mode 100644 tests/model_hub_tests/torch_tests/test_transformers.py diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index d7cba0bc390e59..27792b39fb934b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -887,6 +887,13 @@ jobs: MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests steps: + - name: Maximize build space + run: | + sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android + sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET + sudo rm -rf /opt/ghc + echo "Available storage:" + df -h - name: Create Directories run: | mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} @@ -917,16 +924,28 @@ jobs: - name: Install Python wheels run: | python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools - - name: PyTorch Models Tests + - name: Install requirements run: | python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements.txt python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements_secondary.txt + python3 -m pip cache purge + echo "Available storage:" + df -h + du -h -d0 ~/.cache ~/* + - name: PyTorch Models Tests + run: | export PYTHONPATH=${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}:$PYTHONPATH - python3 -m pytest ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/ -m ${{ env.TYPE }} --html=${{ env.INSTALL_TEST_DIR }}/TEST-torch_model_tests.html --self-contained-html + python3 -m pytest ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/ -m ${{ env.TYPE }} --html=${{ env.INSTALL_TEST_DIR }}/TEST-torch_model_tests.html --self-contained-html -v env: TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} TEST_DEVICE: CPU + - name: Available storage after tests + run: | + echo "Available storage:" + df -h + du -h -d0 ~/.cache ~/* + - name: Upload Test Results uses: actions/upload-artifact@v3 if: ${{ always() }} diff --git a/tests/model_hub_tests/models_hub_common/test_convert_model.py b/tests/model_hub_tests/models_hub_common/test_convert_model.py index d35061595fc0cb..56a402bced99fc 100644 --- a/tests/model_hub_tests/models_hub_common/test_convert_model.py +++ b/tests/model_hub_tests/models_hub_common/test_convert_model.py @@ -78,7 +78,7 @@ def compare_results(self, fw_outputs, ov_outputs): for i in range(len(ov_outputs)): cur_fw_res = fw_outputs[i] cur_ov_res = ov_outputs[i] - print(f"fw_re: {cur_fw_res};\n ov_res: {cur_ov_res}") + print(f"fw_res: {cur_fw_res};\n ov_res: {cur_ov_res}") is_ok = compare_two_tensors(cur_ov_res, cur_fw_res, fw_eps) assert is_ok, "Accuracy validation failed" diff --git a/tests/model_hub_tests/torch_tests/hf_transformers_models b/tests/model_hub_tests/torch_tests/hf_transformers_models new file mode 100644 index 00000000000000..051de563ac171b --- /dev/null +++ b/tests/model_hub_tests/torch_tests/hf_transformers_models @@ -0,0 +1,411 @@ +# List of models obtained from huggingface_hub api as one model per architecture with highest likes and downloads +abcp4/mymodel-test,mymodel,skip,Load problem +abeja/gpt-neox-japanese-2.7b,gpt_neox_japanese +acl-submission-anonym/EAM-spectral,examuse,skip,Load problem +adalbertojunior/modular-test,modular,skip,Load problem +aerner/lm-v2,open-llama,skip,Load problem +afonsosamarques/ardt-vanilla-combo_train_hopper_v2-2508_1336-33,decision_transformer,skip,Load problem +aihijo/gec-zh-gector-bert-large,gector,skip,Load problem +albert-base-v2,albert +AlekseyKorshuk/test_reward_model,reward_model,skip,Load problem +alibaba-damo/mgp-str-base,mgp-str,xfail,Compile error: unsupported Einsum +allenai/hvila-block-layoutlm-finetuned-docbank,hierarchical_model,skip,Load problem +allenai/longformer-base-4096,longformer,xfail,Unsupported op aten::as_strided +ameya772/sentence-t5-base-atis-fine-tuned,T5,skip,Load problem +andreasmadsen/efficient_mlm_m0.40,roberta-prelayernorm +anton-l/emformer-base-librispeech,emformer,skip,Load problem +anugunj/omnivore-swinL-in21k,omnivore,skip,Load problem +apple/mobilevitv2-1.0-imagenet1k-256,mobilevitv2,xfail,Unsupported op aten::col2im +ArthurZ/jukebox_prior_0,jukebox_prior,skip,Load problem +ArthurZ/jukebox-vqvae,jukebox_vqvae,skip,Load problem +ArthurZ/persimmon-8b-base,persimmon,skip,Load problem +ashishpatel26/span-marker-bert-base-fewnerd-coarse-super,span-marker,skip,Load problem +asi/albert-act-tiny,albert_act,skip,Load problem +BAAI/AltCLIP,altclip,xfail,Unsupported op aten::numpy_T +BAAI/AquilaCode-py,aquila,skip,Load problem +bana513/opennmt-translator-en-hu,opennmt-translator,skip,Load problem +benjamin/wtp-bert-mini,bert-char,skip,Load problem +benjamin/wtp-canine-s-1l,la-canine,skip,Load problem +beomi/exKcBERT-kowiki,exbert,skip,Load problem +bert-base-uncased,bert +bigscience/bloom-560m,bloom +Bono93/basic-cnn-example,simplecnn,skip,Load problem +caidas/swin2SR-realworld-sr-x4-64-bsrgan-psnr,swin2sr,xfail,Unsupported op prim::Constant +camembert-base,camembert +CarlCochet/trajectory-transformer-ant-expert-v2,trajectory_transformer,skip,Load problem +CEBaB/bert-base-uncased.CEBaB.causalm.ambiance.2-class.exclusive.seed_42,bert_causalm,skip,Load problem +CEBaB/gpt2.CEBaB.causalm.None__None.2-class.exclusive.seed_42,gpt2_causalm,skip,Load problem +CEBaB/lstm.CEBaB.causalm.ambiance__food.2-class.exclusive.seed_42,lstm_causalm,skip,Load problem +CEBaB/roberta-base.CEBaB.causalm.None__None.2-class.exclusive.seed_42,roberta_causalm,skip,Load problem +cestwc/lava-small-gigaword,lava,skip,Load problem +chlab/efficientnet_61_planet_detection,efficientnet_61_planet_detection,skip,Load problem +CIDAS/clipseg-rd64-refined,clipseg +clefourrier/graphormer-base-pcqm4mv2,graphormer,skip,Load problem +cliang1453/deberta-v3-base-rte-teacher-stage1,ted-deberta-v2,skip,Load problem +clip-italian/clip-italian,vision-text-dual-encoder,skip,Load problem +Clyde013/deqbert-base,deqbert,skip,Load problem +connor-henderson/fastspeech2_conformer,fastspeech2_conformer,skip,Load problem +connor-henderson/fastspeech2_conformer_with_hifigan,fastspeech2_conformer_with_hifigan,skip,Load problem +csarron/meter-vqa2-ft,meter,skip,Load problem +ctrl,ctrl +cwkeam/mctc-large,mctc,skip,Load problem +dandelin/vilt-b32-finetuned-vqa,vilt,xfail,Unsupported op aten::_unique2 aten::multinomial +dangkhoadl/custom_CNN_1D,cnn,skip,Load problem +declare-lab/segue-w2v2-base,segue,skip,Load problem +deepesh0x/autotrain-mlsec-1013333726,julien,skip,Load problem +Dewa/Dog_Model_From_Scratch_v2,simple_image_classification,skip,Load problem +dg845/univnet-dev,univnet,skip,Load problem +distilbert-base-uncased,distilbert +DiViorg/REC-Transformer,rec_transformer,skip,Load problem +dreamerlin/chatbind-7b-delta,llava_image_bind_select,skip,Load problem +edugp/data2vec-nlp-base,data2vec,skip,Load problem +EleutherAI/enformer-official-rough,enformer,skip,Load problem +EleutherAI/gpt-neo-125m,gpt_neo +EleutherAI/pythia-6.9b,gpt_neox +facebook/bart-large-mnli,bart +facebook/convnextv2-tiny-22k-384,convnextv2 +facebook/detr-resnet-50,detr +facebook/dinov2-base,dinov2,skip,Load problem +facebook/dpr-question_encoder-single-nq-base,dpr +facebook/encodec_24khz,encodec,skip,Load problem +facebook/esm2_t6_8M_UR50D,esm,xfail,Tracing error: The values for attribute 'shape' do not match +facebook/flava-full,flava,skip,Load problem +facebook/flava-image-codebook,flava_image_codebook,skip,Load problem +facebook/m2m100_418M,m2m_100 +facebook/mask2former-swin-base-coco-panoptic,mask2former,skip,Load problem +facebook/maskformer-swin-base-coco,maskformer +facebook/mms-tts-eng,vits,skip,Load problem +facebook/musicgen-small,musicgen,skip,Load problem +facebook/opt-125m,opt +facebook/rag-token-nq,rag,skip,Load problem +facebook/sam-vit-large,sam,xfail,No node with name original_sizes +facebook/timesformer-base-finetuned-k400,timesformer,xfail,Shape inference of Add node failed: Eltwise shape infer input shapes dim index: 1 mismatch +facebook/vit-mae-base,vit_mae,xfail,Accuracy validation failed +facebook/wmt19-ru-en,fsmt,skip,Load problem +facebook/xlm-roberta-xl,xlm-roberta-xl +facebook/xmod-base,xmod,skip,Load problem +flax-community/ft5-cnn-dm,f_t5,skip,Load problem +fnlp/elasticbert-base,elasticbert,skip,Load problem +FranzStrauss/ponet-base-uncased,ponet,skip,Load problem +funnel-transformer/small,funnel +fusing/latent-diffusion-text2im-large,ldmbert,skip,Load problem +Geor111y/flair-ner-addresses-extractor,flair,skip,Load problem +gia-project/gia,gia,skip,Load problem +gokuls/bert_12_layer_model_v1,hybridbert,skip,Load problem +google/bigbird-roberta-base,big_bird,skip,Load problem +google/bit-50,bit +google/canine-s,canine,xfail,aten::slice: Parameter axis 3 out of the tensor rank range +google/efficientnet-b2,efficientnet,xfail,Compile error: AvgPool: Kernel after dilation has size (dim: 1408) larger than the data shape after padding (dim: 9) at axis 0. +google/electra-base-discriminator,electra +google/flan-t5-base,t5 +google/fnet-base,fnet,xfail,Unsupported op aten::fft_fftn aten::real +google/mobilebert-uncased,mobilebert +google/mobilenet_v1_0.75_192,mobilenet_v1 +google/mt5-base,mt5 +google/owlvit-base-patch32,owlvit +google/pix2struct-docvqa-base,pix2struct,skip,Load problem +google/realm-orqa-nq-openqa,realm,skip,Load problem +google/reformer-crime-and-punishment,reformer,skip,Load problem +google/tapas-large-finetuned-wtq,tapas,skip,Load problem +google/vit-hybrid-base-bit-384,vit-hybrid,skip,Load problem +google/vivit-b-16x2-kinetics400,vivit +Goutham-Vignesh/ContributionSentClassification-scibert,scibert,skip,Load problem +gpt2,gpt2 +Graphcore/groupbert-base-uncased,groupbert,skip,Load problem +haoranzhao419/saffu-100M-0.1,saffu-100M-0.1,skip,Load problem +Helsinki-NLP/opus-mt-fr-en,marian +hf-internal-testing/random-nllb-moe-2-experts,nllb-moe,skip,Load problem +hf-internal-testing/tiny-random-BlenderbotModel,blenderbot,skip,Load problem +hf-internal-testing/tiny-random-CodeGenModel,codegen +hf-internal-testing/tiny-random-convnext,convnext +hf-internal-testing/tiny-random-CvtModel,cvt +hf-internal-testing/tiny-random-Data2VecAudioModel,data2vec-audio,skip,Load problem +hf-internal-testing/tiny-random-Data2VecTextModel,data2vec-text +hf-internal-testing/tiny-random-Data2VecVisionModel,data2vec-vision +hf-internal-testing/tiny-random-DeiTModel,deit +hf-internal-testing/tiny-random-DonutSwinModel,donut-swin,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-EfficientFormerForImageClassification,efficientformer +hf-internal-testing/tiny-random-flaubert,flaubert +hf-internal-testing/tiny-random-FocalNetModel,focalnet,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-GPTBigCodeForCausalLM,gpt_bigcode,skip,Load problem +hf-internal-testing/tiny-random-GPTJModel,gptj +hf-internal-testing/tiny-random-groupvit,groupvit +hf-internal-testing/tiny-random-IBertModel,ibert,skip,Load problem +hf-internal-testing/tiny-random-ImageGPTModel,imagegpt +hf-internal-testing/tiny-random-LevitModel,levit,skip,Load problem +hf-internal-testing/tiny-random-LiltModel,lilt,skip,Load problem +hf-internal-testing/tiny-random-LongT5Model,longt5,skip,Load problem +hf-internal-testing/tiny-random-mbart,mbart,xfail,Compile error: CPU plug-in doesnt support Squeeze operation with dynamic rank +hf-internal-testing/tiny-random-MobileNetV2Model,mobilenet_v2 +hf-internal-testing/tiny-random-mobilevit,mobilevit +hf-internal-testing/tiny-random-MPNetModel,mpnet +hf-internal-testing/tiny-random-MptForCausalLM,mpt,skip,Load problem +hf-internal-testing/tiny-random-NllbMoeForConditionalGeneration,nllb_moe,skip,Load problem +hf-internal-testing/tiny-random-NystromformerModel,nystromformer +hf-internal-testing/tiny-random-PegasusModel,pegasus,skip,Load problem +hf-internal-testing/tiny-random-PoolFormerModel,poolformer,skip,Load problem +hf-internal-testing/tiny-random-RegNetModel,regnet +hf-internal-testing/tiny-random-RemBertModel,rembert +hf-internal-testing/tiny-random-RoCBertModel,roc_bert,skip,Load problem +hf-internal-testing/tiny-random-RoFormerModel,roformer +hf-internal-testing/tiny-random-SegformerModel,segformer +hf-internal-testing/tiny-random-SEWDModel,sew-d,skip,Load problem +hf-internal-testing/tiny-random-SEWModel,sew,skip,Load problem +hf-internal-testing/tiny-random-Speech2TextModel,speech_to_text,skip,Load problem +hf-internal-testing/tiny-random-speech-encoder-decoder,speech-encoder-decoder,skip,Load problem +hf-internal-testing/tiny-random-SplinterModel,splinter,skip,Load problem +hf-internal-testing/tiny-random-SqueezeBertModel,squeezebert +hf-internal-testing/tiny-random-SwinModel,swin,xfail,Unsupported op aten::adaptive_avg_pool1d +hf-internal-testing/tiny-random-unispeech,unispeech,skip,Load problem +hf-internal-testing/tiny-random-UniSpeechSatModel,unispeech-sat,skip,Load problem +hf-internal-testing/tiny-random-vision_perceiver_conv,perceiver +hf-internal-testing/tiny-random-ViTMSNModel,vit_msn +hf-internal-testing/tiny-random-wav2vec2-conformer,wav2vec2-conformer +hf-internal-testing/tiny-random-XLMModel,xlm +hfl/vle-base,vle,skip,Load problem +HJHGJGHHG/GAU-Base-Full,gau,skip,Load problem +huggingface/autoformer-tourism-monthly,autoformer,skip,Load problem +huggingface/informer-tourism-monthly,informer,skip,Load problem +huggingface/time-series-transformer-tourism-monthly,time_series_transformer,skip,Load problem +HuggingFaceM4/tiny-random-idefics,idefics,skip,Load problem +HuggingFaceM4/tiny-random-vllama-clip,vllama,skip,Load problem +HuggingFaceM4/tiny-random-vopt-clip,vopt,skip,Load problem +HuiHuang/gpt3-damo-base-zh,gpt3,skip,Load problem +hustvl/yolos-tiny,yolos +iakarshu/tilt_base,tilt_base_configuration,skip,Load problem +ibm/MoLM-350M-4B,moduleformer,skip,Load problem +IDEA-CCNL/Randeng-Deltalm-362M-En-Zh,Deltalm,skip,Load problem +Inderpreet01/seaformer-semantic-segmentation-large,seaformer,skip,Load problem +Intel/dpt-hybrid-midas,dpt +Intel/tvp-base,tvp,skip,Load problem +isemmanuelolowe/code-embedder,instruct-codebert,skip,Load problem +isemmanuelolowe/instruct-codet5-5,instruct-codet5,skip,Load problem +jaketae/fastspeech2-ljspeech,fastspeech2,skip,Load problem +jambran/depression-classification,DepressionDetection,skip,Load problem +Jellywibble/dalio-reward-charlie-v1,reward-model,skip,Load problem +JonasGeiping/crammed-bert-legacy,crammedBERT,skip,Load problem +jonatasgrosman/wav2vec2-large-xlsr-53-english,wav2vec2,xfail,Unsupported op aten::index_put_ prim::TupleConstruct +Joqsan/test-my-fnet,my_fnet,skip,Load problem +jozhang97/deta-swin-large,deta,skip,Load problem +jploski/retnet-mini-shakespeare,retnet,skip,Load problem +juhi7ag/idea-model2,,skip,Load problem +junnyu/autobert-small-light,autobert,skip,Load problem +junnyu/chinese_GAU-alpha-char_L-24_H-768,gau_alpha,skip,Load problem +junnyu/flash_small_wwm_cluecorpussmall,flash,skip,Load problem +junnyu/flashquad_small_wwm_cluecorpussmall,flash_quad,skip,Load problem +kakaobrain/align-base,align,xfail,Compile error: AvgPool: Kernel after dilation has size (dim: 640) larger than the data shape after padding (dim: 9) at axis 0. +KBLab/megatron-bert-large-swedish-cased-110k,megatron-bert +kiddothe2b/hierarchical-transformer-base-4096-v2,hat,skip,Load problem +k-l-lambda/clip-text-generator,clip_text_generator,skip,Load problem +k-l-lambda/stable-diffusion-v1-4-inv-embed,inv_word_embed,skip,Load problem +KoboldAI/fairseq-dense-13B-Janeway,xglm,skip,Large Model +konverner/qdq-camembert-apolliner,qdqbert +krasserm/perceiver-ar-clm-base,perceiver-ar-causal-language-model,skip,Load problem +krasserm/perceiver-ar-sam-giant-midi,perceiver-ar-symbolic-audio-model,skip,Load problem +krasserm/perceiver-io-img-clf,perceiver-io-image-classifier,skip,Load problem +krasserm/perceiver-io-mlm,perceiver-io-masked-language-model,skip,Load problem +krasserm/perceiver-io-optical-flow,perceiver-io-optical-flow,skip,Load problem +krasserm/perceiver-io-txt-clf-imdb,perceiver-io-text-classifier,skip,Load problem +ksmcg/fan_small_12_p16_224,fan,skip,Load problem +laion/clap-htsat-unfused,clap,skip,Load problem +Langboat/ReGPT-125M-200G,re_gpt,skip,Load problem +lengyue233/content-vec-best,hubert +Lewislou/cellseg_sribd,cell_sribd,skip,Load problem +liamcripwell/o-conbart,context-bart,skip,Load problem +liamcripwell/pgdyn-plan,context-roberta,skip,Load problem +linhdo/graphdoc,graphdoc,skip,Load problem +LinkSoul/Chinese-LLaVA-Baichuan,llava,skip,Load problem +LinkSoul/LLaSM-Cllama2,llaaa,skip,Load problem +lintang/t5-v2-xl-flan,umt5 +liuhaotian/LLaVA-Lightning-MPT-7B-preview,llava_mpt,skip,Load problem +liya0121/my_finetune_0121,progen,skip,Load problem +lucadiliello/BLEURT-20,bleurt,skip,Load problem +lum-ai/metal,metal,skip,Load problem +luodian/OTTER-MPT1B-RPJama-Init,otter,skip,Load problem +luoruipu1/valley-13b-v1-delta,Valley,skip,Load problem +luoruipu1/Valley2-7b,valley,skip,Load problem +Lutech-AI/I-SPIn,I-SPIn,skip,Load problem +MAGAer13/mplug-owl-llama-7b,mplug-owl,skip,Load problem +manu/contrastive_zeroner,contrastive_zeroner,skip,Load problem +manu/lilt-infoxlm-base,liltrobertalike,skip,Load problem +manu/mplt_untrained,mplt,skip,Load problem +matheusntg/character-bert-pt-normal,character_bert,skip,Load problem +MBZUAI/swiftformer-xs,swiftformer +MCG-NJU/videomae-base-finetuned-kinetics,videomae +M-CLIP/XLM-Roberta-Large-Vit-B-32,M-CLIP,skip,Load problem +medhabi/distilbert-base-uncased-score-pred,text-to-rating,skip,Load problem +meta-llama/Llama-2-7b-hf,llama,skip,Load problem +microsoft/beit-base-patch16-224-pt22k-ft22k,beit +microsoft/biogpt,biogpt +microsoft/conditional-detr-resnet-50,conditional_detr +microsoft/deberta-base,deberta +microsoft/git-large-coco,git,skip,Load problem +microsoft/layoutlm-base-uncased,layoutlm +microsoft/layoutlmv2-base-uncased,layoutlmv2,skip,Load problem +microsoft/layoutlmv3-base,layoutlmv3,skip,Load problem +microsoft/markuplm-base,markuplm,skip,Load problem +microsoft/resnet-50,resnet +microsoft/speecht5_hifigan,hifigan,skip,Load problem +microsoft/speecht5_tts,speecht5,skip,Load problem +microsoft/swinv2-tiny-patch4-window8-256,swinv2,xfail,Unsupported op aten::adaptive_avg_pool1d +microsoft/table-transformer-detection,table-transformer +microsoft/wavlm-large,wavlm,skip,Load problem +microsoft/xclip-base-patch32,xclip,skip,Load problem +microsoft/xprophetnet-large-wiki100-cased,xlm-prophetnet,xfail,Unsupported op aten::fill_diagonal_ +miguelvictor/python-fromzero-lstmlm,lstmlm,skip,Load problem +mingzi151/test-hf-wav2vec2bert,wav2vec2bert,skip,Load problem +MIT/ast-finetuned-audioset-10-10-0.4593,audio-spectrogram-transformer,skip,Load problem +Mizuiro-sakura/luke-japanese-large-sentiment-analysis-wrime,luke +mlml-chip/thyme2_colon_e2e,cnlpt,skip,Load problem +mnaylor/mega-base-wikitext,mega,skip,Load problem +mohitsha/tiny-random-testing-bert2gpt2,encoder-decoder +MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli,deberta-v2 +MoritzLaurer/ernie-m-large-mnli-xnli,ernie_m +mrm8488/prunebert-base-uncased-finepruned-topK-squadv2,masked_bert,skip,Load problem +muditb/headline_classifier,BertModel,skip,Load problem +nanashi161382/clip-text-deprojector,clip_text_deprojector_model,skip,Load problem +nateraw/vit-age-classifier,vit +naver-clova-ocr/bros-base-uncased,bros,skip,Load problem +navervision/CompoDiff-Aesthetic,CompoDiff,skip,Load problem +navervision/KELIP,kelip,skip,Load problem +NCAI/NCAI-BERT,lean_albert,skip,Load problem +nglaura/skimformer,skimformer,skip,Load problem +nguyenvulebinh/robustspeech-asr,robustspeech,skip,Load problem +nguyenvulebinh/voice-filter,voicefilter,skip,Load problem +NiCy/seg-ment-tation,seg-ment-tation,skip,Load problem +nielsr/audio-spectogram-transformer-finetuned-audioset-10-10-0.4593,audio-spectogram-transformer,skip,Load problem +nielsr/convnext-tiny-maskrcnn,maskrcnn,skip,Load problem +nielsr/H3-125m,h3,skip,Load problem +nielsr/layoutreader-readingbank,layoutreader,skip,Load problem +nielsr/pix2seq-base,pix2seq,skip,Load problem +nielsr/tapex-large,tapex,skip,Load problem +nielsr/udop-large,udop,skip,Load problem +nielsr/vitmatte-small-composition-1k,vitmatte,skip,Load problem +nllg/poetry-bygpt5-small-en,bygpt5,skip,Load problem +nlpconnect/vit-gpt2-image-captioning,vision-encoder-decoder +OATML-Markslab/Tranception_Small,tranception,skip,Load problem +OFA-Sys/chinese-clip-vit-base-patch16,chinese_clip +openai/clip-vit-large-patch14,clip +openai/jukebox-1b-lyrics,jukebox,skip,Load problem +openai/whisper-medium,whisper,skip,Load problem +openai-gpt,openai-gpt +OpenAssistant/oasst-rm-2-pythia-6.9b-epoch-1,gpt_neox_reward_model,skip,Load problem +openmmlab/upernet-convnext-small,upernet,skip,Load problem +openMUSE/clip-vit-large-patch14-text-enc,clip_text_model,skip,Load problem +PatrickHaller/ngme-llama-264M,ngme,skip,Load problem +patrickvonplaten/bert2gpt2-cnn_dailymail-fp16,encoder_decoder,skip,Load problem +paulhindemith/test-zeroshot,test-zeroshot,skip,Load problem +PGT/orig-nystromformer-s-artificial-balanced-max500-490000-0,graph_nystromformer,skip,Load problem +pie/example-ner-spanclf-conll03,TransformerSpanClassificationModel,skip,Load problem +pie/example-re-textclf-tacred,TransformerTextClassificationModel,skip,Load problem +pleisto/yuren-baichuan-7b,multimodal_llama,skip,Load problem +predictia/europe_reanalysis_downscaler_convbaseline,convbilinear,skip,Load problem +predictia/europe_reanalysis_downscaler_convswin2sr,conv_swin2sr,skip,Load problem +pszemraj/led-large-book-summary,led,xfail,Unsupported op aten::as_strided +qmeeus/whisper-small-ner-combined,whisper_for_slu,skip,Load problem +raman-ai/pcqv2-tokengt-lap16,tokengt,skip,Load problem +range3/pegasus-gpt2-medium,pegasusgpt2,skip,Load problem +regisss/bridgetower-newyorker-a100-8x,bridgetower +rinna/japanese-cloob-vit-b-16,cloob,skip,Load problem +Rocketknight1/tiny-random-falcon-7b,falcon,skip,Load problem +RUCAIBox/mass-base-uncased,mass,skip,Load problem +RWKV/rwkv-4-169m-pile,rwkv,skip,Load problem +sahasrarjn/interbert,BERT,skip,Load problem +saibo/genkalm-medium-gpt2,genkalm,skip,Load problem +SajjadAyoubi/clip-fa-vision,clip_vision_model +Salesforce/blip2-flan-t5-xl,blip-2,skip,Load problem +Salesforce/blip-image-captioning-large,blip,skip,Load problem +Salesforce/instructblip-vicuna-7b,instructblip,skip,Load problem +SamLowe/roberta-base-go_emotions,roberta +sanchit-gandhi/enhanced_direct_s2st_en_to_es,speech-to-speech,skip,Load problem +sciki/finetune_tinybert,finetune-tinybert,skip,Load problem +sebastian-hofstaetter/colbert-distilbert-margin_mse-T2-msmarco,ColBERT,skip,Load problem +sebastian-hofstaetter/distilbert-cat-margin_mse-T2-msmarco,BERT_Cat,skip,Load problem +sebastian-hofstaetter/idcm-distilbert-msmarco_doc,IDCM,skip,Load problem +SenseTime/deformable-detr,deformable_detr,skip,Load problem +shahules786/Reward-model-gptneox-410M,rm_gptneox_config,skip,Load problem +shauray/Llava-Llama-2-7B-hf,llavallama,skip,Load problem +shauray/ViTPose,vitpose,skip,Load problem +sheonhan/ict-imagenet-256,ict,skip,Load problem +shibing624/text2vec-base-chinese-paraphrase,ernie +shikhartuli/flexibert-mini,flexibert,skip,Load problem +shikras/shikra-7b-delta-v1-0708,shikra,skip,Load problem +shi-labs/dinat-mini-in1k-224,dinat,xfail,Unsupported op aten::adaptive_avg_pool1d +shi-labs/nat-mini-in1k-224,nat,xfail,Unsupported op aten::adaptive_avg_pool1d +shi-labs/oneformer_ade20k_swin_large,oneformer,skip,Load problem +shuqi/seed-encoder,seed_encoder,skip,Load problem +sijunhe/nezha-cn-base,nezha +sjiang1/codecse,roberta_for_cl,skip,Load problem +slh/fcnet-base-cased,fcnet,skip,Load problem +snoop2head/Deep-Shallow-Ko2En,transformer,skip,Load problem +Solomonik/SeqTokenModelMultiple,SeqToken,skip,Load problem +solotimes/lavibe_base,donut,skip,Load problem +songlab/gpn-brassicales,ConvNet,skip,Load problem +speechbrain/m-ctc-t-large,mctct +Splend1dchan/wav2vec2-large-lv60_t5lephone-small_lna_bs64,speechmix,skip,Load problem +stefan-it/bort-full,bort,skip,Load problem +SteveZhan/my-resnet50d,resnet_steve,skip,Load problem +suno/bark,bark,skip,Load problem +surajnair/r3m-50,r3m,skip,Load problem +susnato/clvp_dev,clvp,skip,Load problem +Tanrei/GPTSAN-japanese,gptsan-japanese,xfail,Unsupported op aten::clip aten::index_put_ prim::TupleConstruct +tau/bart-large-sled-govreport,tau/sled,skip,Load problem +taufeeque/best-cb-model,codebook,skip,Load problem +Team-PIXEL/pixel-base,pixel,skip,Load problem +tensorpro/clip_vip_pretrained_base_16,clip_vip,skip,Load problem +thomwolf/vqgan_imagenet_f16_1024,vqgan_model,skip,Load problem +thu-ml/zh-clip-vit-roberta-large-patch14,zhclip,skip,Load problem +tifa-benchmark/promptcap-coco-vqa,ofa,skip,Load problem +tli8hf/robertabase_snli,transformerfornli,skip,Load problem +transfo-xl-wt103,transfo-xl,xfail,Unsupported op aten::clamp_ aten::index_copy_ +transZ/BART_shared_clean,shared_bart,skip,Load problem +transZ/BART_shared_v2,shared_bart_v2,skip,Load problem +transZ/misecom,misecom,skip,Load problem +transZ/parex,parex,skip,Load problem +transZ/phrext,phrext,skip,Load problem +transZ/reword,reword,skip,Load problem +transZ/roberta_texid,roberta_texid,skip,Load problem +transZ/tforge_v1.9,Transformer_Forge,skip,Load problem +trl-internal-testing/tiny-random-BigBirdPegasusForConditionalGeneration,bigbird_pegasus,skip,Load problem +trl-internal-testing/tiny-random-BlenderbotSmallForConditionalGeneration,blenderbot-small,skip,Load problem +trl-internal-testing/tiny-random-MvpForConditionalGeneration,mvp,skip,Load problem +trl-internal-testing/tiny-random-PegasusXForConditionalGeneration,pegasus_x,skip,Load problem +trl-internal-testing/tiny-random-PLBartForConditionalGeneration,plbart,skip,Load problem +trl-internal-testing/tiny-random-ProphetNetForConditionalGeneration,prophetnet,skip,Load problem +trl-internal-testing/tiny-random-SwitchTransformersForConditionalGeneration,switch_transformers,skip,Load problem +turing-motors/heron-chat-blip-ja-stablelm-base-7b-v0,video_blip,skip,Load problem +turing-motors/heron-chat-git-ELYZA-fast-7b-v0,git_llama,skip,Load problem +uclanlp/visualbert-vqa-coco-pre,visual_bert,skip,Load problem +ummagumm-a/samolet_room_classifier,AirModelHF,skip,Load problem +ummagumm-a/samolet-room-classifier,gru,skip,Load problem +UNCANNY69/Misinfo-BERT-LSTM,BertLSTMForSequenceClassification,skip,Load problem +UNCANNY69/Miss-BERT-CNN,BertCNNForSequenceClassification,skip,Load problem +unc-nlp/lxmert-base-uncased,lxmert,skip,Load problem +uw-madison/mra-base-512-4,mra,skip,Load problem +uw-madison/yoso-4096,yoso,skip,Fatal Python error: Aborted +valhalla/cogview-gpt2-test,cog_view,skip,Load problem +valhalla/s2t_mustc_multilinguial_medium,speech_to_text_transformer,skip,Load problem +vblagoje/greaselm-csqa,greaselm,skip,Load problem +vinvino02/glpn-nyu,glpn +Visual-Attention-Network/van-base,van +visualjoyce/transformers4vl-uniter-base,uniter,skip,Load problem +visualjoyce/transformers4vl-vilbert-mt,vilbert,skip,Load problem +vumichien/nonsemantic-speech-trillsson3,trillsson_efficientnet,skip,Load problem +vumichien/trillsson3-ft-keyword-spotting-12,trillsson_efficient,skip,Load problem +wangruiai2023/nougat,nougat,skip,Load problem +WENGSYX/CoNN_Parity,conn,skip,Load problem +xlm-roberta-base,xlm-roberta +xlnet-base-cased,xlnet +ybelkada/focusondepth,focusondepth,skip,Load problem +ybelkada/random-tiny-BertGenerationModel,bert-generation,skip,Load problem +ydshieh/temp-testing-kosmos-2,kosmos-2,skip,Load problem +YituTech/conv-bert-base,convbert +yjernite/retribert-base-uncased,retribert,xfail,Unsupported op aten::cross_entropy_loss +ylacombe/hf-seamless-m4t-medium,seamless_m4t,skip,Load problem +youzanai/clip-product-title-chinese,clip_chinese_model,skip,Load problem +Yova/SmallCapOPT7M,smallcap,skip,Load problem +yusufani/trclip-vitl14-e10,trclip,skip,Load problem +yysung53/dpr,text_similarity,skip,Load problem +Zetatech/pvt-tiny-224,pvt,skip,Load problem +ZinengTang/tvlt-base,tvlt,skip,Load problem +zuppif/resnetd-18,resnetd,skip,Load problem diff --git a/tests/model_hub_tests/torch_tests/requirements.txt b/tests/model_hub_tests/torch_tests/requirements.txt index 9a859794b09d04..9668e5c92b12bb 100644 --- a/tests/model_hub_tests/torch_tests/requirements.txt +++ b/tests/model_hub_tests/torch_tests/requirements.txt @@ -5,3 +5,12 @@ pytest-html torch torchvision av +transformers +timm +sacremoses +sentencepiece +datasets +pyctcdecode +pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com +protobuf +soundfile diff --git a/tests/model_hub_tests/torch_tests/requirements_secondary.txt b/tests/model_hub_tests/torch_tests/requirements_secondary.txt index f59753797b27a0..f37ba0e81008ae 100644 --- a/tests/model_hub_tests/torch_tests/requirements_secondary.txt +++ b/tests/model_hub_tests/torch_tests/requirements_secondary.txt @@ -1,3 +1,4 @@ -c ../../constraints.txt # This file contains requirements dependednt from modules in requirements.txt -git+https://github.com/facebookresearch/detectron2.git \ No newline at end of file +git+https://github.com/facebookresearch/detectron2.git +natten diff --git a/tests/model_hub_tests/torch_tests/test_transformers.py b/tests/model_hub_tests/torch_tests/test_transformers.py new file mode 100644 index 00000000000000..f4cea932d4a0fd --- /dev/null +++ b/tests/model_hub_tests/torch_tests/test_transformers.py @@ -0,0 +1,287 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest +import os +import torch +import tempfile +from huggingface_hub import model_info +from models_hub_common.test_convert_model import TestConvertModel +from openvino import convert_model +from models_hub_common.utils import get_models_list + + +def flattenize_tuples(list_input): + unpacked_pt_res = [] + for r in list_input: + if isinstance(r, (tuple, list)): + unpacked_pt_res.extend(flattenize_tuples(r)) + else: + unpacked_pt_res.append(r) + return unpacked_pt_res + + +def flattenize_outputs(outputs): + if not isinstance(outputs, dict): + outputs = flattenize_tuples(outputs) + return [i.numpy(force=True) for i in outputs] + else: + return dict((k, v.numpy(force=True)) for k, v in outputs.items()) + + +# To make tests reproducible we seed the random generator +torch.manual_seed(0) + + +class TestTransformersModel(TestConvertModel): + def setup_class(self): + from PIL import Image + import requests + import os + + url = "http://images.cocodataset.org/val2017/000000039769.jpg" + self.image = Image.open(requests.get(url, stream=True).raw) + + self.cache_dir = tempfile.TemporaryDirectory() + print(f"Setting temp cache dir: {str(self.cache_dir)}") + os.environ["HUGGINGFACE_HUB_CACHE"] = str(self.cache_dir) + + def load_model(self, name, type): + mi = model_info(name) + auto_processor = None + model = None + example = None + try: + auto_model = mi.transformersInfo['auto_model'] + if "processor" in mi.transformersInfo: + auto_processor = mi.transformersInfo['processor'] + except: + auto_model = None + if "clip_vision_model" in mi.tags: + from transformers import CLIPVisionModel, CLIPFeatureExtractor + model = CLIPVisionModel.from_pretrained(name, torchscript=True) + preprocessor = CLIPFeatureExtractor.from_pretrained(name) + encoded_input = preprocessor(self.image, return_tensors='pt') + example = dict(encoded_input) + elif "t5" in mi.tags: + from transformers import T5Tokenizer + tokenizer = T5Tokenizer.from_pretrained(name) + encoder = tokenizer( + "Studies have been shown that owning a dog is good for you", return_tensors="pt") + decoder = tokenizer("Studies show that", return_tensors="pt") + example = (encoder.input_ids, encoder.attention_mask, + decoder.input_ids, decoder.attention_mask) + elif "hubert" in mi.tags: + wav_input_16khz = torch.randn(1, 10000) + example = (wav_input_16khz,) + elif "vit-gpt2" in name: + from transformers import VisionEncoderDecoderModel, ViTImageProcessor + model = VisionEncoderDecoderModel.from_pretrained( + name, torchscript=True) + feature_extractor = ViTImageProcessor.from_pretrained(name) + encoded_input = feature_extractor( + images=[self.image], return_tensors="pt") + + class VIT_GPT2_Model(torch.nn.Module): + def __init__(self, model): + super().__init__() + self.model = model + + def forward(self, x): + return self.model.generate(x, max_length=16, num_beams=4) + + model = VIT_GPT2_Model(model) + example = (encoded_input.pixel_values,) + elif "retribert" in mi.tags: + from transformers import RetriBertTokenizer + text = "How many cats are there?" + tokenizer = RetriBertTokenizer.from_pretrained(name) + encoding1 = tokenizer( + "How many cats are there?", return_tensors="pt") + encoding2 = tokenizer("Second text", return_tensors="pt") + example = (encoding1.input_ids, encoding1.attention_mask, + encoding2.input_ids, encoding2.attention_mask) + elif "mgp-str" in mi.tags or "clip_vision_model" in mi.tags: + from transformers import AutoProcessor + processor = AutoProcessor.from_pretrained(name) + encoded_input = processor(images=self.image, return_tensors="pt") + example = (encoded_input.pixel_values,) + elif "vivit" in mi.tags: + from transformers import VivitImageProcessor + frames = list(torch.randint( + 0, 255, [32, 3, 224, 224]).to(torch.float32)) + processor = VivitImageProcessor.from_pretrained(name) + encoded_input = processor(images=frames, return_tensors="pt") + example = (encoded_input.pixel_values,) + elif "tvlt" in mi.tags: + from transformers import AutoProcessor + processor = AutoProcessor.from_pretrained(name) + num_frames = 8 + images = list(torch.rand(num_frames, 3, 224, 224)) + audio = list(torch.randn(10000)) + input_dict = processor( + images, audio, sampling_rate=44100, return_tensors="pt") + example = dict(input_dict) + elif "xmod" in mi.tags: + from transformers import AutoTokenizer, AutoModel + processor = AutoTokenizer.from_pretrained(name) + text = "Replace me by any text you'd like." + encoded_input = processor(text=[text], return_tensors="pt") + model = AutoModel.from_pretrained(name, torchscript=True) + model.set_default_language("de_CH") + example = dict(encoded_input) + elif "gptsan-japanese" in mi.tags: + from transformers import AutoTokenizer + processor = AutoTokenizer.from_pretrained(name) + text = "織田信長は、" + encoded_input = processor(text=[text], return_tensors="pt") + example = dict(input_ids=encoded_input.input_ids, + token_type_ids=encoded_input.token_type_ids) + elif "videomae" in mi.tags or "timesformer" in mi.tags: + from transformers import AutoProcessor + processor = AutoProcessor.from_pretrained(name) + video = list(torch.randint( + 0, 255, [16, 3, 224, 224]).to(torch.float32)) + inputs = processor(video, return_tensors="pt") + example = dict(inputs) + else: + if auto_model == "AutoModelForCausalLM": + from transformers import AutoTokenizer, AutoModelForCausalLM + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForCausalLM.from_pretrained( + name, torchscript=True) + text = "Replace me by any text you'd like." + encoded_input = tokenizer(text, return_tensors='pt') + inputs_dict = dict(encoded_input) + if "facebook/incoder" in name and "token_type_ids" in inputs_dict: + del inputs_dict["token_type_ids"] + example = inputs_dict + elif auto_model == "AutoModelForMaskedLM": + from transformers import AutoTokenizer, AutoModelForMaskedLM + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForMaskedLM.from_pretrained( + name, torchscript=True) + text = "Replace me by any text you'd like." + encoded_input = tokenizer(text, return_tensors='pt') + example = dict(encoded_input) + elif auto_model == "AutoModelForImageClassification": + from transformers import AutoProcessor, AutoModelForImageClassification + processor = AutoProcessor.from_pretrained(name) + model = AutoModelForImageClassification.from_pretrained( + name, torchscript=True) + encoded_input = processor( + images=self.image, return_tensors="pt") + example = dict(encoded_input) + elif auto_model == "AutoModelForSeq2SeqLM": + from transformers import AutoTokenizer, AutoModelForSeq2SeqLM + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForSeq2SeqLM.from_pretrained( + name, torchscript=True) + inputs = tokenizer( + "Studies have been shown that owning a dog is good for you", return_tensors="pt") + decoder_inputs = tokenizer( + " Studien haben gezeigt dass es hilfreich ist einen Hund zu besitzen", + return_tensors="pt", + add_special_tokens=False, + ) + example = dict(input_ids=inputs.input_ids, + decoder_input_ids=decoder_inputs.input_ids) + elif auto_model == "AutoModelForSpeechSeq2Seq": + from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq + from datasets import load_dataset + processor = AutoProcessor.from_pretrained(name) + model = AutoModelForSpeechSeq2Seq.from_pretrained( + name, torchscript=True) + dataset = load_dataset( + "hf-internal-testing/librispeech_asr_demo", "clean", split="validation") + dataset = dataset.sort("id") + sampling_rate = dataset.features["audio"].sampling_rate + inputs = processor( + dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt") + example = dict(inputs) + elif auto_model == "AutoModelForCTC": + from transformers import AutoProcessor, AutoModelForCTC + from datasets import load_dataset + processor = AutoProcessor.from_pretrained(name) + model = AutoModelForCTC.from_pretrained( + name, torchscript=True) + ds = load_dataset( + "patrickvonplaten/librispeech_asr_dummy", "clean", split="validation") + input_values = processor( + ds[0]["audio"]["array"], return_tensors="pt") + example = dict(input_values) + elif auto_model == "AutoModelForTableQuestionAnswering": + import pandas as pd + from transformers import AutoTokenizer, AutoModelForTableQuestionAnswering + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForTableQuestionAnswering.from_pretrained( + name, torchscript=True) + data = {"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], + "Number of movies": ["87", "53", "69"]} + queries = ["What is the name of the first actor?", + "How many movies has George Clooney played in?", + "What is the total number of movies?",] + answer_coordinates = [[(0, 0)], [(2, 1)], [ + (0, 1), (1, 1), (2, 1)]] + answer_text = [["Brad Pitt"], ["69"], ["209"]] + table = pd.DataFrame.from_dict(data) + encoded_input = tokenizer(table=table, queries=queries, answer_coordinates=answer_coordinates, + answer_text=answer_text, padding="max_length", return_tensors="pt",) + example = dict(encoded_input) + else: + from transformers import AutoTokenizer, AutoProcessor + text = "Replace me by any text you'd like." + if auto_processor is not None and "Tokenizer" not in auto_processor: + processor = AutoProcessor.from_pretrained(name) + encoded_input = processor( + text=[text], images=self.image, return_tensors="pt", padding=True) + else: + tokenizer = AutoTokenizer.from_pretrained(name) + encoded_input = tokenizer(text, return_tensors='pt') + example = dict(encoded_input) + if model is None: + from transformers import AutoModel + model = AutoModel.from_pretrained(name, torchscript=True) + self.example = example + return model + + def get_inputs_info(self, model_obj): + return None + + def prepare_inputs(self, inputs_info): + if isinstance(self.example, dict): + return dict((k, v.numpy()) for k, v in self.example.items()) + else: + return [i.numpy() for i in self.example] + + def convert_model(self, model_obj): + ov_model = convert_model(model_obj, example_input=self.example) + return ov_model + + def infer_fw_model(self, model_obj, inputs): + if isinstance(inputs, dict): + inps = dict((k, torch.from_numpy(v)) for k, v in inputs.items()) + fw_outputs = model_obj(**inps) + else: + fw_outputs = model_obj(*[torch.from_numpy(i) for i in inputs]) + return flattenize_outputs(fw_outputs) + + def teardown_method(self): + # cleanup tmpdir + print(f"Cleaning temp cache dir: {str(self.cache_dir)}") + self.cache_dir.cleanup() + super().teardown_method() + + @pytest.mark.parametrize("name,type", [("bert-base-uncased", "bert"), + ("facebook/bart-large-mnli", "bart"), + ("gpt2", "gpt2"), + ("openai/clip-vit-large-patch14", "clip")]) + @pytest.mark.precommit + def test_convert_model_precommit(self, name, type, ie_device): + self.run(model_name=name, model_link=type, ie_device=ie_device) + + @pytest.mark.parametrize("name", + [pytest.param(n, marks=pytest.mark.xfail(reason=r) if m == "xfail" else pytest.mark.skip(reason=r)) if m else n for n, _, m, r in get_models_list(os.path.join(os.path.dirname(__file__), "hf_transformers_models"))]) + @pytest.mark.nightly + def test_convert_model_all_models(self, name, ie_device): + self.run(model_name=name, model_link=None, ie_device=ie_device) From d0ef28e5415c8bd41c3ef26b38ff6a23067e15eb Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 21 Sep 2023 17:37:33 +0200 Subject: [PATCH 02/43] Reverse infer deduce second Squeeze input (#19923) * Reverse infer deduce second Squeeze input * Fix build * Fix tf tests * Small optimization * Fix type * Fix tests --- .../reverse_shape_and_type_infer.cpp | 33 +++++++++++++---- .../reverse_shape_and_type_infer.cpp | 35 +++++++++++++++++++ .../tests/convert_tricky_models.cpp | 3 +- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp index 25708ad94202a1..5f93afb68c0280 100644 --- a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp @@ -5,6 +5,7 @@ #include "transformations/common_optimizations/reverse_shape_and_type_infer.hpp" #include "itt.hpp" +#include "openvino/core/rt_info.hpp" #include "openvino/core/validation_util.hpp" #include "openvino/op/concat.hpp" #include "openvino/op/convert_like.hpp" @@ -176,13 +177,31 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr(op)) { - auto in0_rank = op->get_input_partial_shape(0).rank(); - if (output_shape.rank().is_static() && in0_rank.is_dynamic() && op->get_input_size() > 1) { - auto in1_pshape = op->get_input_partial_shape(1); - if (in1_pshape.is_static()) { - auto num_dims = in1_pshape.size() == 0 ? 1 : in1_pshape[0].get_length(); - op->get_input_tensor(0).m_partial_shape = - PartialShape::dynamic(output_shape.rank().get_length() + num_dims); + auto in0_pshape = op->get_input_partial_shape(0); + auto in0_rank = in0_pshape.rank(); + if (output_shape.rank().is_static()) { + if (in0_rank.is_dynamic() && op->get_input_size() > 1) { + auto in1_pshape = op->get_input_partial_shape(1); + if (in1_pshape.is_static()) { + auto num_dims = in1_pshape.size() == 0 ? 1 : in1_pshape[0].get_length(); + op->get_input_tensor(0).m_partial_shape = + PartialShape::dynamic(output_shape.rank().get_length() + num_dims); + } + } else if (in0_rank.is_static() && op->get_input_size() == 1) { + // attempt to create second input + std::vector in1_data; + for (size_t i = 0; i < in0_pshape.size(); i++) { + if (in0_pshape[i] == 1) { + in1_data.push_back(i); + } + } + int64_t num_ones = in1_data.size(); + if (num_ones == in0_rank.get_length() - output_shape.rank().get_length()) { + auto axes = ov::op::v0::Constant::create(element::i64, Shape{in1_data.size()}, in1_data); + auto new_squeeze = std::make_shared(op->get_input_source_output(0), axes); + op->output(0).replace(new_squeeze->output(0)); + copy_runtime_info(op, new_squeeze); + } } } is_changed |= inherit_output_type(op, {0}); diff --git a/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp b/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp index f550b92ea07c97..82ceee31375b5a 100644 --- a/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp +++ b/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp @@ -412,6 +412,41 @@ TEST_F(TransformationTestsF, SqueezeReverseInfer) { } } +TEST_F(TransformationTestsF, SqueezeAxesReverseInfer) { + auto dyn = Dimension::dynamic(); + { + auto data = std::make_shared(element::dynamic, PartialShape{1, dyn, 1, dyn, dyn, dyn}); + auto squeeze = std::make_shared(data); + // Convolution is needed to produce static rank + auto weights = + opset10::Constant::create(element::f32, Shape{64, 3, 7, 7}, std::vector(64 * 3 * 7 * 7, 0.1f)); + auto conv = std::make_shared(squeeze, + weights, + Strides{2, 2}, + CoordinateDiff{3, 3}, + CoordinateDiff{3, 3}, + Strides{1, 1}); + auto result = std::make_shared(conv); + model = std::make_shared(ResultVector{result}, ParameterVector{data}); + manager.register_pass(); + } + { + auto data = std::make_shared(element::f32, PartialShape{1, dyn, 1, dyn, dyn, dyn}); + auto axes = opset10::Constant::create(element::i64, Shape{2}, {0, 2}); + auto squeeze = std::make_shared(data, axes); + auto weights = + opset10::Constant::create(element::f32, Shape{64, 3, 7, 7}, std::vector(64 * 3 * 7 * 7, 0.1f)); + auto conv = std::make_shared(squeeze, + weights, + Strides{2, 2}, + CoordinateDiff{3, 3}, + CoordinateDiff{3, 3}, + Strides{1, 1}); + auto result = std::make_shared(conv); + model_ref = std::make_shared(ResultVector{result}, ParameterVector{data}); + } +} + TEST_F(TransformationTestsF, UnsqueezeReverseInfer) { { auto data = std::make_shared(element::dynamic, PartialShape::dynamic()); diff --git a/src/frontends/tensorflow/tests/convert_tricky_models.cpp b/src/frontends/tensorflow/tests/convert_tricky_models.cpp index f7ef57511ea416..1ece7f7bec83cb 100644 --- a/src/frontends/tensorflow/tests/convert_tricky_models.cpp +++ b/src/frontends/tensorflow/tests/convert_tricky_models.cpp @@ -664,7 +664,8 @@ TEST_F(FrontEndConversionWithReferenceTestsF, NonMaxSuppressionWithNamedOutputs) selected_scores = make_shared(selected_scores, i32); // compute the third output - valid_outputs - Output valid_outputs = make_shared(nms->output(2)); + auto squeeze_axes = make_shared(i64, Shape{1}, 0); + Output valid_outputs = make_shared(nms->output(2), squeeze_axes); // make post-processing before the concatenation auto const_minus_one = make_shared(i32, Shape{1}, -1); From 0e0e1b0ee627524836398ac02de3fa3105bcd28f Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Thu, 21 Sep 2023 19:49:07 +0200 Subject: [PATCH 03/43] SmartReshape: ReshapeMatMul transformations are fixed (#19987) * SmartReshape: ReshapeMatMul transformations are fixed * clang-format fixes --- .../smart_reshape/matmul_sr.cpp | 37 ++++++++----------- .../tests/functional/matmul_sr_tests.cpp | 15 +++++--- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp b/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp index f3763eb47feb9c..870b69d9a55901 100644 --- a/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp +++ b/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp @@ -28,10 +28,8 @@ bool relax_hc_reshape_followed_by_matmul(const ov::pass::pattern::PatternValueMa const std::shared_ptr& other_input_label, const std::shared_ptr& reshape_pattern_label, bool reshape_is_A_input) { - const auto& reshape_rank = pattern_to_output.at(reshape_label).get_partial_shape().rank(); - const auto& matmul = - std::dynamic_pointer_cast(pattern_to_output.at(matmul_label).get_node_shared_ptr()); - if (!matmul || reshape_rank.is_dynamic() || reshape_rank.get_length() != 2) + const auto matmul = ov::as_type_ptr(pattern_to_output.at(matmul_label).get_node_shared_ptr()); + if (!matmul) return false; const auto& shape_source = pattern_to_output.at(other_input_label); if (ov::is_type(shape_source.get_node_shared_ptr()) || @@ -39,20 +37,15 @@ bool relax_hc_reshape_followed_by_matmul(const ov::pass::pattern::PatternValueMa // avoiding loop creation return false; - const auto& raw_idx = - reshape_is_A_input ? (matmul->get_transpose_b() ? -1 : -2) : (matmul->get_transpose_a() ? -2 : -1); - OPENVINO_SUPPRESS_DEPRECATED_START - const auto& idx = ov::normalize_axes(matmul->description(), {raw_idx}, reshape_rank); - OPENVINO_SUPPRESS_DEPRECATED_END - const auto& C = - std::make_shared(std::make_shared(shape_source), - ov::op::v0::Constant::create(ov::element::i64, {idx.size()}, idx), - ov::op::v0::Constant::create(ov::element::i64, {}, {0})); - const auto& N = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}); - const auto& pattern_vector = - reshape_is_A_input ? (matmul->get_transpose_a() ? ov::OutputVector({C, N}) : ov::OutputVector({N, C})) - : (matmul->get_transpose_b() ? ov::OutputVector({N, C}) : ov::OutputVector({C, N})); - const auto& new_reshape_pattern = std::make_shared(pattern_vector, 0); + const auto idx = reshape_is_A_input ? (matmul->get_transpose_b() ? -1 : -2) : (matmul->get_transpose_a() ? -2 : -1); + const auto C = std::make_shared(std::make_shared(shape_source), + ov::op::v0::Constant::create(ov::element::i64, {1}, {idx}), + ov::op::v0::Constant::create(ov::element::i64, {}, {0})); + const auto N = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}); + const auto pattern_vector = reshape_is_A_input + ? (matmul->get_transpose_a() ? ov::OutputVector({C, N}) : ov::OutputVector({N, C})) + : (matmul->get_transpose_b() ? ov::OutputVector({N, C}) : ov::OutputVector({C, N})); + const auto new_reshape_pattern = std::make_shared(pattern_vector, 0); auto reshape_pattern = pattern_to_output.at(reshape_pattern_label).get_node_shared_ptr(); new_reshape_pattern->set_friendly_name(reshape_pattern->get_friendly_name()); @@ -68,8 +61,8 @@ ov::pass::ReshapeAMatMul::ReshapeAMatMul() { auto other_input_label = pattern::any_input(); auto reshape_input_label = pattern::any_input(); auto reshape_pattern_label = pattern::any_input(); - auto reshape_label = - ov::pass::pattern::wrap_type({reshape_input_label, reshape_pattern_label}); + auto reshape_label = ov::pass::pattern::wrap_type({reshape_input_label, reshape_pattern_label}, + ov::pass::pattern::rank_equals(2)); auto matmul_label = ov::pass::pattern::wrap_type({reshape_label, other_input_label}); matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { @@ -90,8 +83,8 @@ ov::pass::ReshapeBMatMul::ReshapeBMatMul() { auto other_input_label = pattern::any_input(); auto reshape_input_label = pattern::any_input(); auto reshape_pattern_label = pattern::any_input(); - auto reshape_label = - ov::pass::pattern::wrap_type({reshape_input_label, reshape_pattern_label}); + auto reshape_label = ov::pass::pattern::wrap_type({reshape_input_label, reshape_pattern_label}, + ov::pass::pattern::rank_equals(2)); auto matmul_label = ov::pass::pattern::wrap_type({other_input_label, reshape_label}); matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool { diff --git a/src/inference/tests/functional/matmul_sr_tests.cpp b/src/inference/tests/functional/matmul_sr_tests.cpp index b4c0cd45e0833c..27a294e656e171 100644 --- a/src/inference/tests/functional/matmul_sr_tests.cpp +++ b/src/inference/tests/functional/matmul_sr_tests.cpp @@ -26,7 +26,7 @@ using namespace testing; namespace { -using reshape_map = std::map>; +using reshape_map = std::map; struct ReshapeMatMulTestCase { bool reshape_is_A_input; @@ -75,8 +75,10 @@ class SmartReshapeMatMulTests : public ov::test::TestsCommon, { auto input_A = std::make_shared(ov::element::f32, test_case.A_shape); input_A->set_friendly_name("input_A"); + input_A->output(0).set_names({"input_A"}); auto input_B = std::make_shared(ov::element::f32, test_case.B_shape); input_B->set_friendly_name("input_B"); + input_B->output(0).set_names({"input_B"}); auto reshape_pattern = std::make_shared(ov::element::i64, ov::Shape{test_case.reshape_pattern.size()}, @@ -99,15 +101,13 @@ class SmartReshapeMatMulTests : public ov::test::TestsCommon, ov::ResultVector results = {result}; model = std::make_shared(results, params); } - - InferenceEngine::details::CNNNetworkNGraphImpl network(model); - const auto& resp = network.reshape(test_case.new_shapes, nullptr); - ASSERT_EQ(resp, InferenceEngine::StatusCode::OK); + ASSERT_NO_THROW(model->reshape(test_case.new_shapes)); } }; TEST_P(SmartReshapeMatMulTests, ReshapeMatMul) {} +// clang-format off INSTANTIATE_TEST_SUITE_P( OVModel, SmartReshapeMatMulTests, @@ -116,11 +116,14 @@ INSTANTIATE_TEST_SUITE_P( ReshapeMatMulTestCase{true, {1, 20, 30}, {40, 30}, {20, -1}, false, true, {{"input_A", {2, 20, 30}}}}, ReshapeMatMulTestCase{true, {1, 30, 20}, {30, 20}, {-1, 20}, true, false, {{"input_A", {2, 30, 20}}}}, ReshapeMatMulTestCase{true, {1, 30, 20}, {40, 30}, {-1, 20}, true, true, {{"input_A", {2, 30, 20}}}}, + ReshapeMatMulTestCase{true, {-1, 30, 40}, {-1, 1, 1200}, {1200, 1200}, false, true, {{"input_A", {1200, 30, 40}}}}, ReshapeMatMulTestCase{false, {20, 30}, {1, 30, 40}, {-1, 40}, false, false, {{"input_B", {2, 30, 40}}}}, ReshapeMatMulTestCase{false, {20, 30}, {1, 40, 30}, {40, -1}, false, true, {{"input_B", {2, 40, 30}}}}, ReshapeMatMulTestCase{false, {30, 20}, {1, 30, 40}, {-1, 40}, true, false, {{"input_B", {2, 30, 40}}}}, - ReshapeMatMulTestCase{false, {30, 20}, {1, 40, 30}, {40, -1}, true, true, {{"input_B", {2, 40, 30}}}}), + ReshapeMatMulTestCase{false, {30, 20}, {1, 40, 30}, {40, -1}, true, true, {{"input_B", {2, 40, 30}}}}, + ReshapeMatMulTestCase{false, {-1, 1, 1200}, {-1, 30, 40}, {1200, 1200}, false, false, {{"input_B", {1200, 30, 40}}}}), SmartReshapeMatMulTests::getTestCaseName); +// clang-format on } // namespace TEST(SmartReshapeTransposeMatMulTests, TransposeAMatMulFuse) { From e068cfc5a352e432fb276e957e5ab2ff28b999ab Mon Sep 17 00:00:00 2001 From: Zlobin Vladimir Date: Thu, 21 Sep 2023 22:03:09 +0400 Subject: [PATCH 04/43] benchmark: drop python3.7 (#19972) Ticket 118797 --- tools/benchmark_tool/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/benchmark_tool/setup.py b/tools/benchmark_tool/setup.py index 19d0aa0edb7679..e4bdc4af9ac559 100644 --- a/tools/benchmark_tool/setup.py +++ b/tools/benchmark_tool/setup.py @@ -112,5 +112,5 @@ def read_requirements(path: str) -> List[str]: ], packages=find_packages(), install_requires=read_requirements('requirements.txt'), - python_requires='>=3.7', + python_requires='>=3.8', ) From b1bf16c7cfc09a91bfb702928395c0c957eda0d9 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Thu, 21 Sep 2023 22:56:14 +0200 Subject: [PATCH 05/43] Refactor ConversionLayerTest, ConcatLayerTest, ConstantLayerTest, ConvertColorI420LayerTest, ConvertColorNV12LayerTest (#19777) * Refactor ConversionLayerTest * Refactor ConcatLayerTest * Refactor ConstantLayerTest * Refactor ConvertColorI420LayerTest * Refactor ConvertColorNV12LayerTest --- .../single_layer_tests/concat.cpp | 17 +-- .../single_layer_tests/constant.cpp | 38 +++--- .../single_layer_tests/conversion.cpp | 55 ++++----- .../single_layer_tests/convert_color_i420.cpp | 67 ++++++++--- .../single_layer_tests/convert_color_nv12.cpp | 58 +++++++-- .../shared/include/single_op_tests/concat.hpp | 15 +++ .../include/single_op_tests/constant.hpp | 15 +++ .../include/single_op_tests/conversion.hpp | 15 +++ .../single_op_tests/convert_color_i420.hpp | 15 +++ .../single_op_tests/convert_color_nv12.hpp | 15 +++ .../shared_test_classes/single_op/concat.hpp | 32 +++++ .../single_op/constant.hpp | 30 +++++ .../single_op/conversion.hpp | 30 +++++ .../single_op/convert_color_i420.hpp | 30 +++++ .../single_op/convert_color_nv12.hpp | 31 +++++ .../src/base/utils/compare_results.cpp | 98 ++++++++++++++++ .../src/base/utils/generate_inputs.cpp | 110 +++++++++++++++++- .../src/single_op/concat.cpp | 55 +++++++++ .../src/single_op/constant.cpp | 47 ++++++++ .../src/single_op/conversion.cpp | 66 +++++++++++ .../src/single_op/convert_color_i420.cpp | 75 ++++++++++++ .../src/single_op/convert_color_nv12.cpp | 75 ++++++++++++ 22 files changed, 898 insertions(+), 91 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/concat.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/constant.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/conversion.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/convert_color_i420.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/concat.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/constant.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/conversion.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_i420.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_nv12.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/concat.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/constant.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/conversion.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/convert_color_i420.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/convert_color_nv12.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp index 68227e25fddc03..a3e7d144ee9d35 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/concat.cpp @@ -4,15 +4,15 @@ #include -#include "single_layer_tests/concat.hpp" +#include "single_op_tests/concat.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; namespace { +using ov::test::ConcatLayerTest; std::vector axes = {-3, -2, -1, 0, 1, 2, 3}; -std::vector>> inShapes = { +std::vector> shapes_static = { {{10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}}, {{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}}, @@ -21,19 +21,14 @@ std::vector>> inShapes = { }; -std::vector netPrecisions = {InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16}; +std::vector netPrecisions = {ov::element::f32, + ov::element::f16}; INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest, ::testing::Combine( ::testing::ValuesIn(axes), - ::testing::ValuesIn(inShapes), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes_static)), ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(ov::test::utils::DEVICE_CPU)), ConcatLayerTest::getTestCaseName); - } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/constant.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/constant.cpp index 3e536688891147..d680bb9746990a 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/constant.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/constant.cpp @@ -2,38 +2,34 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/constant.hpp" - -#include - +#include "single_op_tests/constant.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::ConstantLayerTest; -std::vector> shapes{ +std::vector shapes{ {2, 2, 3}, {3, 4, 1}, {1, 1, 12}, }; -std::vector precisions{ - InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP64, - InferenceEngine::Precision::U4, InferenceEngine::Precision::U8, - InferenceEngine::Precision::U16, InferenceEngine::Precision::U32, - InferenceEngine::Precision::I4, InferenceEngine::Precision::I8, - InferenceEngine::Precision::I16, InferenceEngine::Precision::I32, +std::vector model_types{ + ov::element::bf16, ov::element::f16, + ov::element::f32, ov::element::f64, + ov::element::u4, ov::element::u8, + ov::element::u16, ov::element::u32, + ov::element::i4, ov::element::i8, + ov::element::i16, ov::element::i32, }; std::vector data{"0", "1", "2", "3", "4", "5", "6", "7", "0", "1", "2", "3"}; -std::vector precisionsWithNegativeValues{ - InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP64, - InferenceEngine::Precision::I4, InferenceEngine::Precision::I8, - InferenceEngine::Precision::I16, InferenceEngine::Precision::I32, +std::vector model_types_with_negative_values{ + ov::element::bf16, ov::element::f16, + ov::element::f32, ov::element::f64, + ov::element::i4, ov::element::i8, + ov::element::i16, ov::element::i32, }; std::vector dataWithNegativeValues{"1", "-2", "3", "-4", "5", "-6", @@ -41,13 +37,13 @@ std::vector dataWithNegativeValues{"1", "-2", "3", "-4", "5", "-6", INSTANTIATE_TEST_SUITE_P(smoke_Constant, ConstantLayerTest, ::testing::Combine(::testing::ValuesIn(shapes), - ::testing::ValuesIn(precisions), ::testing::Values(data), + ::testing::ValuesIn(model_types), ::testing::Values(data), ::testing::Values(ov::test::utils::DEVICE_CPU)), ConstantLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_Constant_with_negative_values, ConstantLayerTest, ::testing::Combine(::testing::ValuesIn(shapes), - ::testing::ValuesIn(precisionsWithNegativeValues), + ::testing::ValuesIn(model_types_with_negative_values), ::testing::Values(dataWithNegativeValues), ::testing::Values(ov::test::utils::DEVICE_CPU)), ConstantLayerTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/conversion.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/conversion.cpp index 7f1dac6f27f03c..b03d55f3208126 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/conversion.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/conversion.cpp @@ -5,48 +5,39 @@ #include #include "common_test_utils/test_constants.hpp" -#include "single_layer_tests/conversion.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/conversion.hpp" namespace { -const std::vector conversionOpTypes = { - ngraph::helpers::ConversionTypes::CONVERT, - ngraph::helpers::ConversionTypes::CONVERT_LIKE, +using ov::test::ConversionLayerTest; + +const std::vector conversionOpTypes = { + ov::test::utils::ConversionTypes::CONVERT, + ov::test::utils::ConversionTypes::CONVERT_LIKE, }; -const std::vector> inShape = {{1, 2, 3, 4}}; +const std::vector> shapes = {{{1, 2, 3, 4}}}; -const std::vector netPrecisions = { - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::U32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U64, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::BF16, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP64, - InferenceEngine::Precision::BOOL, - InferenceEngine::Precision::MIXED, - InferenceEngine::Precision::Q78, - InferenceEngine::Precision::U4, - InferenceEngine::Precision::I4, - InferenceEngine::Precision::BIN, - InferenceEngine::Precision::CUSTOM, +const std::vector types = { + ov::element::u8, + ov::element::i8, + ov::element::u16, + ov::element::i16, + ov::element::u32, + ov::element::i32, + ov::element::u64, + ov::element::i64, + ov::element::bf16, + ov::element::f16, + ov::element::f32, + ov::element::f64, }; INSTANTIATE_TEST_SUITE_P(smoke_ConversionLayerTest, ConversionLayerTest, ::testing::Combine(::testing::ValuesIn(conversionOpTypes), - ::testing::Values(inShape), - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(netPrecisions), - ::testing::Values(InferenceEngine::Layout::ANY), - ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes)), + ::testing::ValuesIn(types), + ::testing::ValuesIn(types), ::testing::Values(ov::test::utils::DEVICE_CPU)), ConversionLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp index 725853a93af1e8..5be4e9ba6dc458 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_i420.cpp @@ -4,34 +4,71 @@ #include -#include "single_layer_tests/convert_color_i420.hpp" +#include "single_op_tests/convert_color_i420.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::ConvertColorI420LayerTest; -const std::vector inShapes_nhwc = { +const std::vector in_shapes = { {1, 10, 10, 1} }; +auto generate_input_static_shapes = [] (const std::vector& original_shapes, bool single_plane) { + std::vector> result_shapes; + for (const auto& original_shape : original_shapes) { + std::vector one_result_shapes; + if (single_plane) { + auto shape = original_shape; + shape[1] = shape[1] * 3 / 2; + one_result_shapes.push_back(shape); + } else { + auto shape = original_shape; + one_result_shapes.push_back(shape); + auto uvShape = ov::Shape{shape[0], shape[1] / 2, shape[2] / 2, 1}; + one_result_shapes.push_back(uvShape); + one_result_shapes.push_back(uvShape); + } + result_shapes.push_back(one_result_shapes); + } + return result_shapes; +}; + +auto in_shapes_single_plain_static = generate_input_static_shapes(in_shapes, true); +auto in_shapes_not_single_plain_static = generate_input_static_shapes(in_shapes, false); + const std::vector inTypes = { ov::element::u8, ov::element::f32 }; -const auto testCase_values = ::testing::Combine( - ::testing::ValuesIn(inShapes_nhwc), +const auto test_case_values_single_plain = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_single_plain_static)), ::testing::ValuesIn(inTypes), ::testing::Bool(), + ::testing::Values(true), + ::testing::Values(ov::test::utils::DEVICE_CPU) +); + +const auto test_case_values_not_single_plain = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_not_single_plain_static)), + ::testing::ValuesIn(inTypes), ::testing::Bool(), + ::testing::Values(false), ::testing::Values(ov::test::utils::DEVICE_CPU) ); +INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420SinglePlain, + ConvertColorI420LayerTest, + test_case_values_single_plain, + ConvertColorI420LayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420, ConvertColorI420LayerTest, testCase_values, ConvertColorI420LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420NotSinglePlain, + ConvertColorI420LayerTest, + test_case_values_not_single_plain, + ConvertColorI420LayerTest::getTestCaseName); -const auto testCase_accuracy_values = ::testing::Combine( - ::testing::Values(ov::Shape{1, 16*6, 16, 1}), +const auto test_case_accuracy_values = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 16*6, 16, 1}}, true))), ::testing::Values(ov::element::u8), ::testing::Values(false), ::testing::Values(true), @@ -39,12 +76,12 @@ const auto testCase_accuracy_values = ::testing::Combine( ); INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420_acc, - ConvertColorI420AccuracyTest, - testCase_accuracy_values, + ConvertColorI420LayerTest, + test_case_accuracy_values, ConvertColorI420LayerTest::getTestCaseName); -const auto testCase_accuracy_values_nightly = ::testing::Combine( - ::testing::Values(ov::Shape{1, 256*256, 256, 1}), +const auto test_case_accuracy_values_nightly = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 256*256, 256, 1}}, true))), ::testing::Values(ov::element::u8), ::testing::Values(false), ::testing::Values(true), @@ -52,8 +89,8 @@ const auto testCase_accuracy_values_nightly = ::testing::Combine( ); INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorI420_acc, - ConvertColorI420AccuracyTest, - testCase_accuracy_values_nightly, + ConvertColorI420LayerTest, + test_case_accuracy_values_nightly, ConvertColorI420LayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp index f821d37819713a..af84b09833c0cd 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/convert_color_nv12.cpp @@ -4,34 +4,70 @@ #include -#include "single_layer_tests/convert_color_nv12.hpp" +#include "single_op_tests/convert_color_nv12.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::ConvertColorNV12LayerTest; -const std::vector inShapes_nhwc = { +const std::vector in_shapes = { {1, 10, 10, 1} }; +auto generate_input_static_shapes = [] (const std::vector& original_shapes, bool single_plane) { + std::vector> result_shapes; + for (const auto& original_shape : original_shapes) { + std::vector one_result_shapes; + if (single_plane) { + auto shape = original_shape; + shape[1] = shape[1] * 3 / 2; + one_result_shapes.push_back(shape); + } else { + auto shape = original_shape; + one_result_shapes.push_back(shape); + auto uvShape = ov::Shape{shape[0], shape[1] / 2, shape[2] / 2, 2}; + one_result_shapes.push_back(uvShape); + } + result_shapes.push_back(one_result_shapes); + } + return result_shapes; +}; + +auto in_shapes_single_plain_static = generate_input_static_shapes(in_shapes, true); +auto in_shapes_not_single_plain_static = generate_input_static_shapes(in_shapes, false); + const std::vector inTypes = { ov::element::u8, ov::element::f32 }; -const auto testCase_values = ::testing::Combine( - ::testing::ValuesIn(inShapes_nhwc), +const auto test_case_values_single_plain = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_single_plain_static)), ::testing::ValuesIn(inTypes), ::testing::Bool(), + ::testing::Values(true), + ::testing::Values(ov::test::utils::DEVICE_CPU) +); + +const auto test_case_values_not_single_plain = ::testing::Combine( + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_not_single_plain_static)), + ::testing::ValuesIn(inTypes), ::testing::Bool(), + ::testing::Values(false), ::testing::Values(ov::test::utils::DEVICE_CPU) ); +INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_1Plain, + ConvertColorNV12LayerTest, + test_case_values_single_plain, + ConvertColorNV12LayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12, ConvertColorNV12LayerTest, testCase_values, ConvertColorNV12LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_3Plains, + ConvertColorNV12LayerTest, + test_case_values_not_single_plain, + ConvertColorNV12LayerTest::getTestCaseName); const auto testCase_accuracy_values = ::testing::Combine( - ::testing::Values(ov::Shape{1, 16*6, 16, 1}), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 16*6, 16, 1}}, true))), ::testing::Values(ov::element::u8), ::testing::Values(false), ::testing::Values(true), @@ -39,12 +75,12 @@ const auto testCase_accuracy_values = ::testing::Combine( ); INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_acc, - ConvertColorNV12AccuracyTest, + ConvertColorNV12LayerTest, testCase_accuracy_values, ConvertColorNV12LayerTest::getTestCaseName); const auto testCase_accuracy_values_nightly = ::testing::Combine( - ::testing::Values(ov::Shape{1, 256*256, 256, 1}), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 256*256, 256, 1}}, true))), ::testing::Values(ov::element::u8), ::testing::Values(false), ::testing::Values(true), @@ -52,7 +88,7 @@ const auto testCase_accuracy_values_nightly = ::testing::Combine( ); INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorNV12_acc, - ConvertColorNV12AccuracyTest, + ConvertColorNV12LayerTest, testCase_accuracy_values_nightly, ConvertColorNV12LayerTest::getTestCaseName); diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/concat.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/concat.hpp new file mode 100644 index 00000000000000..3a368e69526530 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/concat.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/concat.hpp" + +namespace ov { +namespace test { +TEST_P(ConcatLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/constant.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/constant.hpp new file mode 100644 index 00000000000000..767cc69b99795f --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/constant.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/constant.hpp" + +namespace ov { +namespace test { +TEST_P(ConstantLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/conversion.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/conversion.hpp new file mode 100644 index 00000000000000..0d498cb95e1706 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/conversion.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/conversion.hpp" + +namespace ov { +namespace test { +TEST_P(ConversionLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_i420.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_i420.hpp new file mode 100644 index 00000000000000..5d777981efaf6a --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_i420.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/convert_color_i420.hpp" + +namespace ov { +namespace test { +TEST_P(ConvertColorI420LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp new file mode 100644 index 00000000000000..1497c5d0fc2e97 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/convert_color_nv12.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/convert_color_nv12.hpp" + +namespace ov { +namespace test { +TEST_P(ConvertColorNV12LayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/concat.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/concat.hpp new file mode 100644 index 00000000000000..e52016207d0e59 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/concat.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using concatParamsTuple = typename std::tuple< + int, // Concat axis + std::vector, // Input shapes + ov::element::Type, // Model type + std::string>; // Device name + +// Multichannel +class ConcatLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/constant.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/constant.hpp new file mode 100644 index 00000000000000..8fb64cc9b0cfca --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/constant.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using constantParamsTuple = typename std::tuple< + ov::Shape, // Constant data shape + ov::element::Type, // Constant data precision + std::vector, // Constant elements + std::string>; // Device name + +class ConstantLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/conversion.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/conversion.hpp new file mode 100644 index 00000000000000..af182b65b3c755 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/conversion.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "gtest/gtest.h" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/test_enums.hpp" + +namespace ov { +namespace test { +using ConversionParamsTuple = typename std::tuple, // Input shapes + ov::element::Type, // Input type + ov::element::Type, // Convert type + std::string>; // Device name + +class ConversionLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_i420.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_i420.hpp new file mode 100644 index 00000000000000..231af9f1390927 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_i420.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using ConvertColorI420ParamsTuple = std::tuple< + std::vector, // Input Shape + ov::element::Type, // Element type + bool, // Conversion type + bool, // 1 or 3 planes + std::string>; // Device name + +class ConvertColorI420LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_nv12.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_nv12.hpp new file mode 100644 index 00000000000000..ad922c686c9b77 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/convert_color_nv12.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using ConvertColorNV12ParamsTuple = std::tuple< + std::vector, // Input Shape + ov::element::Type, // Element type + bool, // Conversion type + bool, // 1 or 2 planes + std::string>; // Device name + +class ConvertColorNV12LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/base/utils/compare_results.cpp b/src/tests/functional/shared_test_classes/src/base/utils/compare_results.cpp index 43ab82af73a1cc..5d9f13d9ba0017 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/compare_results.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/compare_results.cpp @@ -54,6 +54,104 @@ void compare(const std::shared_ptr &node, ov::test::utils::compare(expected, actual, 1e-2f, relThreshold); } +namespace color_conversion { +template +inline void validate_colors(const T* expected, const T* actual, size_t size, float dev_threshold, float abs_threshold = 0.01f) { + size_t mismatches = 0; + for (size_t i = 0; i < size; i++) { + if (std::abs(static_cast(expected[i] - actual[i])) > abs_threshold) { + mismatches++; + } + } + ASSERT_LT(mismatches / size, dev_threshold) << mismatches << + " out of " << size << " color mismatches found which exceeds allowed threshold " << dev_threshold; +} + +inline void validate_colors(const ov::Tensor& expected, const ov::Tensor& actual, float dev_threshold, float abs_threshold = 0.01f) { + OPENVINO_ASSERT(expected.get_size() == actual.get_size()); + OPENVINO_ASSERT(expected.get_element_type() == actual.get_element_type()); + +#define CASE(X) \ + case X: \ + validate_colors( \ + static_cast*>(expected.data()), \ + static_cast*>(actual.data()), \ + expected.get_size(), \ + dev_threshold, \ + abs_threshold); \ + break; + switch (expected.get_element_type()) { + CASE(ov::element::Type_t::i8) + CASE(ov::element::Type_t::i16) + CASE(ov::element::Type_t::i32) + CASE(ov::element::Type_t::i64) + CASE(ov::element::Type_t::u8) + CASE(ov::element::Type_t::u16) + CASE(ov::element::Type_t::u32) + CASE(ov::element::Type_t::u64) + CASE(ov::element::Type_t::bf16) + CASE(ov::element::Type_t::f16) + CASE(ov::element::Type_t::f32) + CASE(ov::element::Type_t::f64) + default: + OPENVINO_THROW("Unsupported element type: ", expected.get_element_type()); + } +#undef CASE +} +} // namespace color_conversion + +void compare(const std::shared_ptr &node, + size_t port, + const ov::runtime::Tensor &expected, + const ov::runtime::Tensor &actual, + double absThreshold, + double relThreshold) { + ov::test::utils::compare(expected, actual, absThreshold, relThreshold); + + // Allow less than 2% of deviations with 1 color step. 2% is experimental value + // For different calculation methods - 1.4% deviation is observed + color_conversion::validate_colors(expected, actual, 0.02); +} + +void compare(const std::shared_ptr &node, + size_t port, + const ov::runtime::Tensor &expected, + const ov::runtime::Tensor &actual, + double absThreshold, + double relThreshold) { + ov::test::utils::compare(expected, actual, absThreshold, relThreshold); + + // Allow less than 2% of deviations with 1 color step. 2% is experimental value + // For different calculation methods - 1.4% deviation is observed + color_conversion::validate_colors(expected, actual, 0.02); +} + +void compare(const std::shared_ptr &node, + size_t port, + const ov::runtime::Tensor &expected, + const ov::runtime::Tensor &actual, + double absThreshold, + double relThreshold) { + ov::test::utils::compare(expected, actual, absThreshold, relThreshold); + + // Allow less than 2% of deviations with 1 color step. 2% is experimental value + // For different calculation methods - 1.4% deviation is observed + color_conversion::validate_colors(expected, actual, 0.02); +} + +void compare(const std::shared_ptr &node, + size_t port, + const ov::runtime::Tensor &expected, + const ov::runtime::Tensor &actual, + double absThreshold, + double relThreshold) { + ov::test::utils::compare(expected, actual, absThreshold, relThreshold); + + // Allow less than 2% of deviations with 1 color step. 2% is experimental value + // For different calculation methods - 1.4% deviation is observed + color_conversion::validate_colors(expected, actual, 0.02); +} + template void compareResults(const std::shared_ptr &node, size_t port, diff --git a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp index be877939273ae7..c97617aec0d86c 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp @@ -1020,7 +1020,6 @@ ov::runtime::Tensor generate(const comparison::fill_tensor(tensor); return tensor; } - ov::runtime::Tensor generate(const std::shared_ptr& node, size_t port, @@ -1031,6 +1030,115 @@ ov::runtime::Tensor generate(const return tensor; } +namespace color_conversion { +enum class ColorFormat { + i420, + nv12 +}; + +inline std::vector color_test_image(size_t height, size_t width, int b_step, ColorFormat format) { + // Test all possible r/g/b values within dimensions + int b_dim = 255 / b_step + 1; + auto input_yuv = std::vector(height * b_dim * width * 3 / 2); + for (int b = 0; b <= 255; b += b_step) { + for (size_t y = 0; y < height / 2; y++) { + for (size_t x = 0; x < width / 2; x++) { + int r = static_cast(y) * 512 / static_cast(height); + int g = static_cast(x) * 512 / static_cast(width); + // Can't use random y/u/v for testing as this can lead to invalid R/G/B values + int y_val = ((66 * r + 129 * g + 25 * b + 128) / 256) + 16; + int u_val = ((-38 * r - 74 * g + 112 * b + 128) / 256) + 128; + int v_val = ((112 * r - 94 * g + 18 * b + 128) / 256) + 128; + + size_t b_offset = height * width * b / b_step * 3 / 2; + if (ColorFormat::i420 == format) { + size_t u_index = b_offset + height * width + y * width / 2 + x; + size_t v_index = u_index + height * width / 4; + input_yuv[u_index] = u_val; + input_yuv[v_index] = v_val; + } else { + size_t uv_index = b_offset + height * width + y * width + x * 2; + input_yuv[uv_index] = u_val; + input_yuv[uv_index + 1] = v_val; + } + size_t y_index = b_offset + y * 2 * width + x * 2; + input_yuv[y_index] = y_val; + input_yuv[y_index + 1] = y_val; + input_yuv[y_index + width] = y_val; + input_yuv[y_index + width + 1] = y_val; + } + } + } + return input_yuv; +} + +void fill_tensor(ov::Tensor& tensor, ColorFormat format) { + size_t full_height = tensor.get_shape()[1]; + size_t full_width = tensor.get_shape()[2]; + int b_dim = static_cast(full_height * 2 / (3 * full_width)); + ASSERT_GT(b_dim, 1) << "Image height is invalid"; + ASSERT_EQ(255 % (b_dim - 1), 0) << "Image height is invalid"; + int b_step = 255 / (b_dim - 1); + auto input_image = color_test_image(full_width, full_width, b_step, format); + auto data_ptr = static_cast(tensor.data()); + for (size_t j = 0; j < input_image.size(); ++j) { + data_ptr[j] = input_image[j]; + } +} +} // namespace color_conversion + +ov::runtime::Tensor generate(const std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + auto b_dim = static_cast(targetShape[1] * 2 / (3 * targetShape[2])); + if (node->inputs().size() > 1 || b_dim < 2) + return generate(std::static_pointer_cast(node), port, elemType, targetShape); + ov::Tensor tensor(elemType, targetShape); + color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420); + return tensor; +} + +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + auto b_dim = static_cast(targetShape[1] * 2 / (3 * targetShape[2])); + if (node->inputs().size() > 1 || b_dim < 2) + return generate(std::static_pointer_cast(node), port, elemType, targetShape); + ov::Tensor tensor(elemType, targetShape); + color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420); + return tensor; +} + + +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + auto b_dim = static_cast(targetShape[1] * 2 / (3 * targetShape[2])); + if (node->inputs().size() > 1 || b_dim < 2) + return generate(std::static_pointer_cast(node), port, elemType, targetShape); + ov::Tensor tensor(elemType, targetShape); + color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12); + return tensor; +} + +ov::runtime::Tensor generate(const + std::shared_ptr& node, + size_t port, + const ov::element::Type& elemType, + const ov::Shape& targetShape) { + auto b_dim = static_cast(targetShape[1] * 2 / (3 * targetShape[2])); + if (node->inputs().size() > 1 || b_dim < 2) + return generate(std::static_pointer_cast(node), port, elemType, targetShape); + ov::Tensor tensor(elemType, targetShape); + color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12); + return tensor; +} + template ov::runtime::Tensor generateInput(const std::shared_ptr& node, size_t port, diff --git a/src/tests/functional/shared_test_classes/src/single_op/concat.cpp b/src/tests/functional/shared_test_classes/src/single_op/concat.cpp new file mode 100644 index 00000000000000..fc45423a8f0ebb --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/concat.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/concat.hpp" + +namespace ov { +namespace test { + +std::string ConcatLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + int axis; + std::vector shapes; + ov::element::Type model_type; + std::string targetName; + std::tie(axis, shapes, model_type, targetName) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "axis=" << axis << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << targetName; + return result.str(); +} + +void ConcatLayerTest::SetUp() { + int axis; + std::vector shapes; + ov::element::Type model_type; + std::tie(axis, shapes, model_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + ov::ParameterVector params; + ov::NodeVector params_nodes; + for (const auto& shape : inputDynamicShapes) { + auto param = std::make_shared(model_type, shape); + params.push_back(param); + params_nodes.push_back(param); + } + + auto concat = std::make_shared(params_nodes, axis); + auto result = std::make_shared(concat); + function = std::make_shared(result, params, "concat"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/constant.cpp b/src/tests/functional/shared_test_classes/src/single_op/constant.cpp new file mode 100644 index 00000000000000..2b67e830e56121 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/constant.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/constant.hpp" + +namespace ov { +namespace test { +namespace { +template +std::vector getElements(const std::vector& v) { + const auto new_size = std::min(N, v.size()); + return {begin(v), std::next(begin(v), new_size)}; +} +} // namespace + +std::string ConstantLayerTest::getTestCaseName( + const testing::TestParamInfo& obj) { + ov::Shape shape; + ov::element::Type model_type; + std::vector data_elements; + std::string target_device; + + std::tie(shape, model_type, data_elements, target_device) = obj.param; + + std::ostringstream result; + result << "TS={" << ov::test::utils::vec2str(shape) << "}_"; + result << "dataPRC=" << model_type.get_type_name() << "_"; + result << "dataValue=" << ov::test::utils::vec2str(getElements<5>(data_elements)) << "_"; + result << "targetDevice=" << target_device << "_"; + return result.str(); +} + +void ConstantLayerTest::SetUp() { + ov::Shape shape; + ov::element::Type model_type; + std::vector data_elements; + + std::tie(shape, model_type, data_elements, targetDevice) = this->GetParam(); + + auto constant = ov::op::v0::Constant::create(model_type, shape, data_elements); + auto result = std::make_shared(constant); + + function = std::make_shared(result, ov::ParameterVector{}, "constant"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/conversion.cpp b/src/tests/functional/shared_test_classes/src/single_op/conversion.cpp new file mode 100644 index 00000000000000..dabc1e2531ffe9 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/conversion.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/conversion.hpp" + +namespace ov { +namespace test { +namespace { +std::map conversionNames = { + {ov::test::utils::ConversionTypes::CONVERT, "Convert"}, + {ov::test::utils::ConversionTypes::CONVERT_LIKE, "ConvertLike"}}; +} + +std::string ConversionLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::test::utils::ConversionTypes conversion_type; + ov::element::Type input_type, convert_type; + std::string device_name; + std::vector shapes; + std::tie(conversion_type, shapes, input_type, convert_type, device_name) = + obj.param; + std::ostringstream result; + result << "conversionOpType=" << conversionNames[conversion_type] << "_"; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "inputPRC=" << input_type.get_type_name() << "_"; + result << "targetPRC=" << convert_type.get_type_name() << "_"; + result << "trgDev=" << device_name; + return result.str(); +} + +void ConversionLayerTest::SetUp() { + ov::test::utils::ConversionTypes conversion_type; + ov::element::Type input_type, convert_type; + std::vector shapes; + std::tie(conversion_type, shapes, input_type, convert_type, targetDevice) = GetParam(); + init_input_shapes(shapes); + + ov::ParameterVector params; + for (const auto& shape : inputDynamicShapes) { + params.push_back(std::make_shared(input_type, shape)); + } + + std::shared_ptr conversion; + if (conversion_type == ov::test::utils::ConversionTypes::CONVERT) { + conversion = std::make_shared(params.front(), convert_type); + } else /*CONVERT_LIKE*/ { + auto like = std::make_shared(convert_type, ov::Shape{1}); + conversion = std::make_shared(params.front(), like); + } + + auto result = std::make_shared(conversion); + function = std::make_shared(result, params, "Conversion"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/convert_color_i420.cpp b/src/tests/functional/shared_test_classes/src/single_op/convert_color_i420.cpp new file mode 100644 index 00000000000000..b8d00620e21651 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/convert_color_i420.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/convert_color_i420.hpp" +#include "openvino/op/i420_to_rgb.hpp" +#include "openvino/op/i420_to_bgr.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" + +namespace ov { +namespace test { +std::string ConvertColorI420LayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + ov::element::Type type; + bool conversion, single_plane; + std::string device_name; + std::tie(shapes, type, conversion, single_plane, device_name) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "netPRC=" << type.c_type_string() << "_"; + result << "convRGB=" << conversion << "_"; + result << "singlePlane=" << single_plane << "_"; + result << "targetDevice=" << device_name; + return result.str(); +} + +void ConvertColorI420LayerTest::SetUp() { + std::vector shapes; + ov::element::Type net_type; + bool conversion_to_rgb; + bool single_plane; + abs_threshold = 1.1f; // I420 conversion can use various algorithms, thus some absolute deviation is allowed + rel_threshold = 1.1f; // Ignore relative comparison for I420 convert (allow 100% relative deviation) + std::tie(shapes, net_type, conversion_to_rgb, single_plane, targetDevice) = GetParam(); + init_input_shapes(shapes); + + if (single_plane) { + auto param = std::make_shared(net_type, inputDynamicShapes.front()); + std::shared_ptr convert_color; + if (conversion_to_rgb) { + convert_color = std::make_shared(param); + } else { + convert_color = std::make_shared(param); + } + function = std::make_shared(std::make_shared(convert_color), + ov::ParameterVector{param}, "ConvertColorI420"); + } else { + auto param_y = std::make_shared(net_type, inputDynamicShapes[0]); + auto param_u = std::make_shared(net_type, inputDynamicShapes[1]); + auto param_v = std::make_shared(net_type, inputDynamicShapes[2]); + std::shared_ptr convert_color; + if (conversion_to_rgb) { + convert_color = std::make_shared(param_y, param_u, param_v); + } else { + convert_color = std::make_shared(param_y, param_u, param_v); + } + function = std::make_shared(std::make_shared(convert_color), + ov::ParameterVector{param_y, param_u, param_v}, + "ConvertColorI420"); + } +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/convert_color_nv12.cpp b/src/tests/functional/shared_test_classes/src/single_op/convert_color_nv12.cpp new file mode 100644 index 00000000000000..f5eb7b6b9ce736 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/convert_color_nv12.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/convert_color_nv12.hpp" + +#include "openvino/op/nv12_to_rgb.hpp" +#include "openvino/op/nv12_to_bgr.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/result.hpp" + +namespace ov { +namespace test { +std::string ConvertColorNV12LayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + std::vector shapes; + ov::element::Type type; + bool conversion, single_plane; + std::string device_name; + std::tie(shapes, type, conversion, single_plane, device_name) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "modelType=" << type.c_type_string() << "_"; + result << "convRGB=" << conversion << "_"; + result << "single_plane=" << single_plane << "_"; + result << "targetDevice=" << device_name; + return result.str(); +} + +void ConvertColorNV12LayerTest::SetUp() { + std::vector shapes; + ov::element::Type net_type; + bool conversionToRGB, single_plane; + abs_threshold = 1.1f; // NV12 conversion can use various algorithms, thus some absolute deviation is allowed + rel_threshold = 1.1f; // Ignore relative comparison for NV12 convert (allow 100% relative deviation) + std::tie(shapes, net_type, conversionToRGB, single_plane, targetDevice) = GetParam(); + init_input_shapes(shapes); + + if (single_plane) { + auto param = std::make_shared(net_type, inputDynamicShapes.front()); + + std::shared_ptr convert_color; + if (conversionToRGB) { + convert_color = std::make_shared(param); + } else { + convert_color = std::make_shared(param); + } + function = std::make_shared(std::make_shared(convert_color), + ov::ParameterVector{param}, "ConvertColorNV12"); + } else { + auto param_y = std::make_shared(net_type, inputDynamicShapes[0]); + auto param_uv = std::make_shared(net_type, inputDynamicShapes[1]); + + std::shared_ptr convert_color; + if (conversionToRGB) { + convert_color = std::make_shared(param_y, param_uv); + } else { + convert_color = std::make_shared(param_y, param_uv); + } + function = std::make_shared(std::make_shared(convert_color), + ov::ParameterVector{param_y, param_uv}, "ConvertColorNV12"); + } +} +} // namespace test +} // namespace ov From 058b45e60865c4e20a5cc1e5684a33b4577ad60d Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Thu, 21 Sep 2023 23:58:09 +0200 Subject: [PATCH 06/43] [PT FE] Fix aten::repeat regression (#19991) * Revert "[PT FE] Simplify repeat operation (#19926)" This reverts commit f926e0e3920e27d81355f007f3b5dcfb51342ad1. * Fix aten::repeats regression * Simplify * Update src/frontends/pytorch/src/op_table.cpp * Add impacted model --- src/frontends/pytorch/src/op_table.cpp | 2 +- .../layer_tests/pytorch_tests/test_repeat.py | 25 ++++++++++++++++++- tests/layer_tests/requirements.txt | 1 + .../torch_tests/test_transformers.py | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index f475c2cd186275..9cb68a3ea5c17d 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -393,7 +393,7 @@ const std::map get_supported_ops_ts() { {"aten::relu_", op::inplace_op>}, {"aten::relu6", op::translate_relu6}, {"aten::remainder", op::translate_remainder}, - {"aten::repeat", op::inplace_op>}, + {"aten::repeat", op::translate_1to1_match_2_inputs}, {"aten::repeat_interleave", op::translate_repeat_interleave}, {"aten::reshape", op::translate_reshape}, {"aten::reshape_as", op::translate_reshape_as}, diff --git a/tests/layer_tests/pytorch_tests/test_repeat.py b/tests/layer_tests/pytorch_tests/test_repeat.py index 71c79c32d81867..45263366c76c54 100644 --- a/tests/layer_tests/pytorch_tests/test_repeat.py +++ b/tests/layer_tests/pytorch_tests/test_repeat.py @@ -32,6 +32,7 @@ def forward(self, x): def test_repeat(self, repeats, ie_device, precision, ir_version): self._test(*self.create_model(repeats), ie_device, precision, ir_version) + class TestRepeatList(PytorchLayerTest): def _prepare_input(self, repeats_shape): import numpy as np @@ -54,4 +55,26 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit def test_repeat(self, repeats, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={"repeats_shape": repeats}) + self._test(*self.create_model(), ie_device, precision, ir_version, + kwargs_to_prepare_input={"repeats_shape": repeats}) + + +class TestRepeatFromFlanT5(PytorchLayerTest): + def _prepare_input(self): + import numpy as np + return (np.random.randn(1, 15).astype(np.float32),) + + def create_model(self): + import torch + from transformers.modeling_utils import ModuleUtilsMixin + + class aten_repeat(torch.nn.Module): + def forward(self, x): + return ModuleUtilsMixin.create_extended_attention_mask_for_decoder(x.size(), x) + + return aten_repeat(), None, "aten::repeat" + + @pytest.mark.nightly + @pytest.mark.precommit + def test_repeat_t5(self, ie_device, precision, ir_version): + self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True) diff --git a/tests/layer_tests/requirements.txt b/tests/layer_tests/requirements.txt index 30a9221683391e..b1b76c54b92abe 100644 --- a/tests/layer_tests/requirements.txt +++ b/tests/layer_tests/requirements.txt @@ -4,6 +4,7 @@ numpy requests torch torchvision +transformers pytest tensorflow-addons; python_version <= '3.10' jax; sys_platform == "linux" diff --git a/tests/model_hub_tests/torch_tests/test_transformers.py b/tests/model_hub_tests/torch_tests/test_transformers.py index f4cea932d4a0fd..1df75b455026ec 100644 --- a/tests/model_hub_tests/torch_tests/test_transformers.py +++ b/tests/model_hub_tests/torch_tests/test_transformers.py @@ -274,6 +274,7 @@ def teardown_method(self): @pytest.mark.parametrize("name,type", [("bert-base-uncased", "bert"), ("facebook/bart-large-mnli", "bart"), + ("google/flan-t5-base","t5"), ("gpt2", "gpt2"), ("openai/clip-vit-large-patch14", "clip")]) @pytest.mark.precommit From 10c3b60aacef781b23b0bedebfa1e839c69d820d Mon Sep 17 00:00:00 2001 From: Georgy Krivoruchko Date: Thu, 21 Sep 2023 15:05:24 -0700 Subject: [PATCH 07/43] Updated model_creation_sample.py (#19989) Removed usage of ngraph in the sample --- .../python/model_creation_sample/model_creation_sample.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/python/model_creation_sample/model_creation_sample.py b/samples/python/model_creation_sample/model_creation_sample.py index d76d222c5f870e..85815df2a7c186 100755 --- a/samples/python/model_creation_sample/model_creation_sample.py +++ b/samples/python/model_creation_sample/model_creation_sample.py @@ -14,8 +14,8 @@ from data import digits -def create_ngraph_function(model_path: str) -> ov.Model: - """Create a model on the fly from the source code using ngraph.""" +def create_model(model_path: str) -> ov.Model: + """Create a model on the fly from the source code using openvino.""" def shape_and_length(shape: list) -> typing.Tuple[list, int]: length = reduce(lambda x, y: x * y, shape) @@ -136,8 +136,8 @@ def main(): log.info('Creating OpenVINO Runtime Core') # ---------------------------Step 2. Read a model in OpenVINO Intermediate Representation------------------------------ - log.info(f'Loading the model using ngraph function with weights from {model_path}') - model = create_ngraph_function(model_path) + log.info(f'Loading the model using openvino with weights from {model_path}') + model = create_model(model_path) # ---------------------------Step 3. Apply preprocessing---------------------------------------------------------- # Get names of input and output blobs ppp = ov.preprocess.PrePostProcessor(model) From efe54362fdb3ed77a6b8adb9d23aaa1e61fe98d9 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Fri, 22 Sep 2023 00:06:39 +0200 Subject: [PATCH 08/43] fix f16/f32 el type mismatch for shape subgraphs: Parameter type should not be fused for precision sensitive nodes (#19959) Co-authored-by: Roman Kazantsev --- .../src/transformations/convert_precision.cpp | 2 + .../tests/utils/convert_precision.cpp | 90 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index d9d506bbd0660e..65387086310830 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -201,6 +201,8 @@ bool convert_function_precision(const std::shared_ptr& f, } for (const auto& param : f->get_parameters()) { + if (skip_precision_sensitive && fp16_compression_is_disabled(param) && has_fp16_compression) + continue; is_changed |= fuse_type_to_parameter(param, precisions, convert_input_output_precision); } diff --git a/src/common/transformations/tests/utils/convert_precision.cpp b/src/common/transformations/tests/utils/convert_precision.cpp index cab235a94591af..07d6288112214a 100644 --- a/src/common/transformations/tests/utils/convert_precision.cpp +++ b/src/common/transformations/tests/utils/convert_precision.cpp @@ -2136,3 +2136,93 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiSubgraphs) { const auto& results = model->get_results(); ASSERT_EQ("if_result", results[0]->get_input_node_ptr(0)->get_friendly_name()); } + +TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_1) { + shared_ptr model, model_ref; + pass::Manager manager; + { + auto input_1 = make_shared(element::f32, Shape{1, 3, 224, 224}); + auto shape_input = make_shared(element::f32, Shape{2}); + + auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f}); + auto mul_1 = make_shared(shape_input, upscale_const); + auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0}); + auto final_float_shape = make_shared(mul_1, axis_const); + auto final_int_shape = make_shared(final_float_shape, element::i64); + auto reshape_1 = make_shared(input_1, final_int_shape, false); + + model = make_shared(NodeVector{reshape_1}, ParameterVector{input_1, shape_input}); + + type_to_fuse_map empty_type_to_fuse_map = {}; + bool keep_precision_sensitive_in_fp32 = true; + manager.register_pass(precisions_map{{element::f32, element::f16}}, + empty_type_to_fuse_map, + keep_precision_sensitive_in_fp32); + manager.run_passes(model); + } + + { + auto input_1 = make_shared(element::f16, Shape{1, 3, 224, 224}); + auto shape_input = make_shared(element::f32, Shape{2}); + + // even for FP16 compressed model shape subgraph should be kept in fp32 + auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f}); + auto mul_1 = make_shared(shape_input, upscale_const); + auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0}); + auto final_float_shape = make_shared(mul_1, axis_const); + auto final_int_shape = make_shared(final_float_shape, element::i64); + auto reshape_1 = make_shared(input_1, final_int_shape, false); + + model_ref = make_shared(NodeVector{reshape_1}, ParameterVector{input_1, shape_input}); + } + const FunctionsComparator func_comparator = FunctionsComparator::with_default(); + FunctionsComparator::Result result = func_comparator(model_ref, model); + ASSERT_TRUE(result.valid) << result.message; +} + +TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_2) { + shared_ptr model, model_ref; + pass::Manager manager; + { + auto input_1 = make_shared(element::f32, Shape{1, 3, 224, 224}); + auto shape_input = make_shared(element::f32, Shape{2}); + + auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f}); + auto mul_1 = make_shared(shape_input, upscale_const); + auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0}); + auto final_float_shape = make_shared(mul_1, axis_const); + auto final_int_shape = make_shared(final_float_shape, element::i64); + auto reshape_1 = make_shared(input_1, final_int_shape, false); + + model = make_shared(NodeVector{reshape_1}, ParameterVector{input_1, shape_input}); + + type_to_fuse_map empty_type_to_fuse_map = {}; + bool keep_precision_sensitive_in_fp32 = true; + const bool convert_input_output_precision = false; + manager.register_pass(precisions_map{{element::f32, element::f16}}, + empty_type_to_fuse_map, + keep_precision_sensitive_in_fp32, + convert_input_output_precision); + manager.run_passes(model); + } + + { + auto input_1 = make_shared(element::f32, Shape{1, 3, 224, 224}); + auto convert_to_f16 = make_shared(input_1, element::f16); + auto shape_input = make_shared(element::f32, Shape{2}); + + // even for FP16 compressed model shape subgraph should be kept in fp32 + auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f}); + auto mul_1 = make_shared(shape_input, upscale_const); + auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0}); + auto final_float_shape = make_shared(mul_1, axis_const); + auto final_int_shape = make_shared(final_float_shape, element::i64); + auto reshape_1 = make_shared(convert_to_f16, final_int_shape, false); + auto convert_to_f32 = make_shared(reshape_1, element::f32); + + model_ref = make_shared(NodeVector{convert_to_f32}, ParameterVector{input_1, shape_input}); + } + const FunctionsComparator func_comparator = FunctionsComparator::with_default(); + FunctionsComparator::Result result = func_comparator(model_ref, model); + ASSERT_TRUE(result.valid) << result.message; +} From f1b8abe55a903d4ea3baf58afe891d213b4671ef Mon Sep 17 00:00:00 2001 From: Taylor Yeonbok Lee Date: Thu, 21 Sep 2023 22:07:53 -0700 Subject: [PATCH 09/43] [GPU] Optimization for gemm & fc in iGPU. (#19780) * Optimization for gemm & fc in iGPU. FC: fake alignment for 16 is better in iGPU. Gemm: permute + gemm_tiled_opt is better than transposed_input + gemm_ref kernel for unaligned shapes to 16. Note that this is an temporal optimization and will be removed once the final solution (i.e., support unaligned transposed input shape in gemm_tiled_opt kernel) is availalbe. * Fix unittest * Fix for model_cache * Fix unittest --- .../intel_gpu/graph/kernel_impl_params.hpp | 8 +++- .../intel_gpu/src/graph/fully_connected.cpp | 5 ++- .../src/graph/include/program_node.h | 3 +- .../src/graph/kernel_impl_params.cpp | 5 +++ .../intel_gpu/src/plugin/ops/matmul.cpp | 14 ++++++- .../fake_alignment/fc_fake_alignment_test.cpp | 41 +++++++++++++------ .../test_cases/fully_connected_gpu_test.cpp | 25 ++++++----- .../unit/test_cases/hash_key_gpu_test.cpp | 10 +++-- 8 files changed, 79 insertions(+), 32 deletions(-) diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp index 67fe93132b108a..e02ff0afbf1a1a 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp @@ -34,6 +34,7 @@ struct kernel_impl_params { bool has_runtime_layouts = false; const program *prog; + cldnn::device_type dev_type; stream::ptr strm; std::shared_ptr desc; size_t unique_id; @@ -63,9 +64,11 @@ struct kernel_impl_params { std::vector output_size; std::vector img_size; - kernel_impl_params() : prog(nullptr), strm(nullptr), desc(nullptr), unique_id(0) {} + kernel_impl_params() : prog(nullptr), dev_type(cldnn::device_type::integrated_gpu), strm(nullptr), desc(nullptr), unique_id(0) { + } kernel_impl_params(program& _prog, + cldnn::device_type _dev_type, stream::ptr _strm, std::shared_ptr _desc, size_t _uid, @@ -74,6 +77,7 @@ struct kernel_impl_params { const std::vector& _fused_descs) : has_runtime_layouts(true) , prog(&_prog) + , dev_type(_dev_type) , strm(std::move(_strm)) , desc(std::move(_desc)) , unique_id(_uid) @@ -135,7 +139,7 @@ struct kernel_impl_params { return std::static_pointer_cast(desc)->type == PType::type_id(); } -virtual primitive_type_id type() const { return desc->type; } + virtual primitive_type_id type() const { return desc->type; } void save(BinaryOutputBuffer& ob) const; void load(BinaryInputBuffer& ib); diff --git a/src/plugins/intel_gpu/src/graph/fully_connected.cpp b/src/plugins/intel_gpu/src/graph/fully_connected.cpp index 38d10a5e35f071..ed396907d7e1b1 100644 --- a/src/plugins/intel_gpu/src/graph/fully_connected.cpp +++ b/src/plugins/intel_gpu/src/graph/fully_connected.cpp @@ -187,8 +187,9 @@ kernel_impl_params fully_connected_inst::get_fake_aligned_params(kernel_impl_par return std::move(orig_impl_param); } - input_shape[input_row_idx] = align_to(input_shape[input_row_idx], 8); - output_shape[output_row_idx] = align_to(output_shape[output_row_idx], 8); + size_t fake_align_base = (orig_impl_param.dev_type == cldnn::device_type::integrated_gpu) ? 16 : 8; + input_shape[input_row_idx] = align_to(input_shape[input_row_idx], fake_align_base); + output_shape[output_row_idx] = align_to(output_shape[output_row_idx], fake_align_base); updated_param.input_layouts[0] = layout(ov::PartialShape(input_shape), orig_input_layout.data_type, diff --git a/src/plugins/intel_gpu/src/graph/include/program_node.h b/src/plugins/intel_gpu/src/graph/include/program_node.h index fb254ba757888d..d632df1bc6f695 100644 --- a/src/plugins/intel_gpu/src/graph/include/program_node.h +++ b/src/plugins/intel_gpu/src/graph/include/program_node.h @@ -127,7 +127,8 @@ struct program_node { } virtual std::unique_ptr get_kernel_impl_params(const std::vector& in_layouts, const std::vector& out_layouts) const { - auto params = std::unique_ptr(new kernel_impl_params(get_program(), get_program().get_stream_ptr(), get_primitive(), + auto params = std::unique_ptr(new kernel_impl_params(get_program(), get_program().get_engine().get_device_info().dev_type, + get_program().get_stream_ptr(), get_primitive(), get_unique_id(), in_layouts, out_layouts, get_fused_primitives())); params->memory_deps = get_const_memory_deps(); params->_can_be_optimized = this->optimized; diff --git a/src/plugins/intel_gpu/src/graph/kernel_impl_params.cpp b/src/plugins/intel_gpu/src/graph/kernel_impl_params.cpp index fbec60d2dbd438..2258c970776d45 100644 --- a/src/plugins/intel_gpu/src/graph/kernel_impl_params.cpp +++ b/src/plugins/intel_gpu/src/graph/kernel_impl_params.cpp @@ -8,6 +8,7 @@ #include "intel_gpu/graph/serialization/layout_serializer.hpp" #include "intel_gpu/graph/serialization/string_serializer.hpp" #include "intel_gpu/graph/serialization/vector_serializer.hpp" +#include "intel_gpu/runtime/device_info.hpp" #include #include @@ -71,6 +72,7 @@ bool kernel_impl_params::operator==(const kernel_impl_params& rhs) const { void kernel_impl_params::save(BinaryOutputBuffer& ob) const { ob << desc; + ob << static_cast(dev_type); ob << has_runtime_layouts; ob << unique_id; ob << input_layouts; @@ -135,6 +137,9 @@ void kernel_impl_params::save(BinaryOutputBuffer& ob) const { void kernel_impl_params::load(BinaryInputBuffer& ib) { prog = nullptr; ib >> desc; + size_t dev_type_id = 0; + ib >> dev_type_id; + dev_type = static_cast(dev_type_id); ib >> has_runtime_layouts; ib >> unique_id; ib >> input_layouts; diff --git a/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp b/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp index eced7765e693ea..b3b69fee255287 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp @@ -46,8 +46,18 @@ static void CreateMatMulOp(ProgramBuilder& p, const std::shared_ptr {}; @@ -54,8 +57,13 @@ TEST_P(fully_connected_fake_align_test, fake_alignment) { EXPECT_THROW(fully_connected_inst::get_fake_aligned_params(*impl_param), std::exception); } else { auto updated_param = fully_connected_inst::get_fake_aligned_params(*impl_param); - ASSERT_EQ(updated_param.get_input_layout(), p.expected_input_layout); - ASSERT_EQ(updated_param.get_output_layout(), p.expected_output_layout); + if (!engine.get_device_info().supports_immad) { + ASSERT_EQ(updated_param.get_input_layout(), p.expected_input_layout_igpu); + ASSERT_EQ(updated_param.get_output_layout(), p.expected_output_layout_igpu); + } else { + ASSERT_EQ(updated_param.get_input_layout(), p.expected_input_layout_dgpu); + ASSERT_EQ(updated_param.get_output_layout(), p.expected_output_layout_dgpu); + } } } @@ -65,29 +73,38 @@ INSTANTIATE_TEST_SUITE_P(smoke, fully_connected_fake_align_test, layout{ov::PartialShape{0, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // input_layout layout{ov::PartialShape{1000, 1024}, data_types::i8, format::bfyx}, // weight layout data_types::f16, - layout{ov::PartialShape{0, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout - layout{ov::PartialShape{0, 1000}, data_types::f16, format::bfyx} // fake_aligned output layout + layout{ov::PartialShape{0, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_igpu + layout{ov::PartialShape{0, 1000}, data_types::f16, format::bfyx}, // fake_aligned output layout_igpu + layout{ov::PartialShape{0, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_dgpu + layout{ov::PartialShape{0, 1000}, data_types::f16, format::bfyx} // fake_aligned output layout_dgpu }, { layout{ov::PartialShape{11, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // input_layout layout{ov::PartialShape{1000, 1024}, data_types::i8, format::bfyx}, // weight layout data_types::f16, - layout{ov::PartialShape{16, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout - layout{ov::PartialShape{16, 1000}, data_types::f16, format::bfyx} // fake_aligned output layout + layout{ov::PartialShape{16, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_igpu + layout{ov::PartialShape{16, 1000}, data_types::f16, format::bfyx}, // fake_aligned output layout_igpu + layout{ov::PartialShape{16, 1024}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_dgpu + layout{ov::PartialShape{16, 1000}, data_types::f16, format::bfyx} // fake_aligned output layout_dgpu + }, { layout{ov::PartialShape{133, 511}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // input_layout layout{ov::PartialShape{800, 511}, data_types::i8, format::bfyx}, // weight layout data_types::f16, - layout{ov::PartialShape{136, 511}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout - layout{ov::PartialShape{136, 800}, data_types::f16, format::bfyx} // fake_aligned output layout + layout{ov::PartialShape{144, 511}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_igpu + layout{ov::PartialShape{144, 800}, data_types::f16, format::bfyx}, // fake_aligned output layout_igpu + layout{ov::PartialShape{136, 511}, data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // fake_aligned input layout_dgpu + layout{ov::PartialShape{136, 800}, data_types::f16, format::bfyx} // fake_aligned output layout_dgpu }, { layout{ov::PartialShape::dynamic(2), data_types::i8, format::bfyx, padding{{1,1,1,1}, 0}}, // input_layout layout{ov::PartialShape{1000, 1024}, data_types::i8, format::bfyx}, // weight layout data_types::f16, - layout{ov::PartialShape{-1, -1}, data_types::i8, format::bfyx}, // fake_aligned input layout // dummy - layout{ov::PartialShape{-1, -1}, data_types::f16, format::bfyx} // fake_aligned output layout // dummy + layout{ov::PartialShape{-1, -1}, data_types::i8, format::bfyx}, // fake_aligned input layout_igpu // dummy + layout{ov::PartialShape{-1, -1}, data_types::f16, format::bfyx}, // fake_aligned output layout_igpu // dummy + layout{ov::PartialShape{-1, -1}, data_types::i8, format::bfyx}, // fake_aligned input layout_dgpu // dummy + layout{ov::PartialShape{-1, -1}, data_types::f16, format::bfyx} // fake_aligned output layout_dgpu // dummy }, })); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp index 664e91d3a63017..0b99d36ce3624f 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp @@ -1874,6 +1874,7 @@ TEST(fully_connected_onednn, impl_replacement_with_cldnn) { const int32_t input_f = 3, input_b = 1, weight_b = 4; + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; auto input_dyn_layout = layout{ ov::PartialShape{ ov::Dimension(1, 10), input_f }, data_types::f32,format::bfyx }; auto input_data = engine.allocate_memory(layout{ ov::PartialShape{ input_b, input_f }, data_types::f32,format::bfyx }); auto weights_data = engine.allocate_memory({ ov::PartialShape{ weight_b, input_f }, data_types::f32,format::bfyx }); @@ -1909,7 +1910,7 @@ TEST(fully_connected_onednn, impl_replacement_with_cldnn) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), input_b); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2045,6 +2046,7 @@ TEST(fully_connected_gpu, dynamic) { const int32_t input_f = 3, input_b = 1, weight_b = 4; + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; auto input_dyn_layout = layout{ ov::PartialShape{ ov::Dimension(1, 10), input_f }, data_types::f32,format::bfyx }; auto input_data = engine.allocate_memory(layout{ ov::PartialShape{ input_b, input_f }, data_types::f32,format::bfyx }); auto weights_data = engine.allocate_memory({ ov::PartialShape{ weight_b, input_f }, data_types::f32,format::bfyx }); @@ -2071,7 +2073,7 @@ TEST(fully_connected_gpu, dynamic) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), input_b); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2199,7 +2201,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_same_shape) { auto input_data1 = engine.allocate_memory(input_actual_layout); auto input_data2 = engine.allocate_memory(input_actual_layout); auto weights_data = engine.allocate_memory({ ov::PartialShape{ weight_b, input_f }, data_types::f32,format::bfyx }); - + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; set_values(input_data1, { 0.5f, -2.0f, -0.5f }); set_values(input_data2, { -0.5f, 2.0f, 0.5f }); set_values(weights_data, { 1.5f, 1.0f, 0.5f, @@ -2228,7 +2230,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_same_shape) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), input_b); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2252,7 +2254,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_same_shape) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), input_b); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2272,6 +2274,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_different_shape) { const int32_t input_f = 3, weight_b = 4; + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; auto input_dyn_layout = layout{ ov::PartialShape{ ov::Dimension(1, 10), input_f }, data_types::f32,format::bfyx }; auto input_actual_layout1 = layout{ ov::PartialShape{ 2, input_f }, data_types::f32,format::bfyx}; auto input_actual_layout2 = layout{ ov::PartialShape{ 1, input_f }, data_types::f32,format::bfyx}; @@ -2311,7 +2314,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_different_shape) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(2, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(2, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), 2); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2340,7 +2343,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_different_shape) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(1, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(1, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), 1); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2360,6 +2363,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_multiple_shapes) { const int32_t input_f = 3, weight_b = 4; + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; auto input_dyn_layout = layout{ ov::PartialShape{ ov::Dimension(1, 10), input_f }, data_types::f32,format::bfyx }; auto input_actual_layout1 = layout{ ov::PartialShape{ 2, input_f }, data_types::f32,format::bfyx}; auto input_actual_layout2 = layout{ ov::PartialShape{ 1, input_f }, data_types::f32,format::bfyx}; @@ -2398,7 +2402,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_multiple_shapes) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(2, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(2, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), 2); // fake_alignment ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2427,7 +2431,7 @@ TEST(fully_connected_gpu, dynamic_multi_inference_multiple_shapes) { auto output_prim_mem = outputs.begin()->second.get_memory(); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(1, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(1, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), 1); // fake_alignment ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); @@ -2661,6 +2665,7 @@ TEST(fully_connected_gpu, has_cached_weights_reorder) { const int32_t input_f = 3, input_b = 1, weight_b = 4; + auto fake_alignment_size = engine.get_device_info().supports_immad ? 8 : 16; auto input_dyn_layout = layout{ ov::PartialShape{ ov::Dimension(1, 10), input_f }, data_types::f32,format::bfyx }; auto input_data = engine.allocate_memory(layout{ ov::PartialShape{ input_b, input_f }, data_types::f32,format::bfyx }); auto weights_data = engine.allocate_memory({ ov::PartialShape{ weight_b, input_f }, data_types::f32,format::bfyx }); @@ -2701,7 +2706,7 @@ TEST(fully_connected_gpu, has_cached_weights_reorder) { ASSERT_TRUE(reorder_impl == nullptr); auto out_l = network.get_output_layout(outputs.begin()->first); - ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, 8)); // fake_alignment + ASSERT_EQ(output_prim_mem->get_layout().batch(), align_to(input_b, fake_alignment_size)); // fake_alignment ASSERT_EQ(out_l.batch(), input_b); ASSERT_EQ(out_l.feature(), weight_b); ASSERT_EQ(out_l.spatial(0), 1); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp index eaf253c248cbbb..a40469eb8a8cc8 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/hash_key_gpu_test.cpp @@ -70,9 +70,13 @@ class check_hash_value: public ::testing::Test { const auto primitive_hash = primitve->hash(); const auto params_hash = primitve->type->get_fake_aligned_params(*prim_inst->get_impl_params()).hash(); - - ASSERT_EQ(primitive_hash, 6924775129729406941UL); - ASSERT_EQ(params_hash, 8552673460001178483UL); + if (!engine.get_device_info().supports_immad) { + ASSERT_EQ(primitive_hash, 6924775129729406941UL); + ASSERT_EQ(params_hash, 15366394052020805414UL); + } else { + ASSERT_EQ(primitive_hash, 6924775129729406941UL); + ASSERT_EQ(params_hash, 8552673460001178483UL); + } } void test_gather_basic(bool is_caching_test) { From fde054e4a6df0a264ac5a2b065082c8402de911c Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Fri, 22 Sep 2023 09:30:57 +0400 Subject: [PATCH 10/43] [PT FE]: support aten::minimum aten::maximum (#19996) --- src/frontends/pytorch/src/op/min_max.cpp | 32 ++++++++ src/frontends/pytorch/src/op_table.cpp | 4 + .../layer_tests/pytorch_tests/test_min_max.py | 74 +++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/src/frontends/pytorch/src/op/min_max.cpp b/src/frontends/pytorch/src/op/min_max.cpp index c6b63f11e25d9f..670b4eca4d4e93 100644 --- a/src/frontends/pytorch/src/op/min_max.cpp +++ b/src/frontends/pytorch/src/op/min_max.cpp @@ -80,6 +80,38 @@ OutputVector translate_min(const NodeContext& context) { return {values, indicies}; }; +OutputVector translate_maximum(const NodeContext& context) { + // aten::maximum(Tensor self, Tensor other) -> Tensor + + // aten::maximum.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!) + + num_inputs_check(context, 2, 3); + auto x = context.get_input(0); + auto y = context.get_input(1); + align_eltwise_input_types(context, x, y, true); + auto res = context.mark_node(std::make_shared(x, y)); + if (!context.input_is_none(2)) { + context.mutate_input(2, res); + } + return {res}; +} + +OutputVector translate_minimum(const NodeContext& context) { + // aten::minimum(Tensor self, Tensor other) -> Tensor + + // aten::minimum.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!) + + num_inputs_check(context, 2, 3); + auto x = context.get_input(0); + auto y = context.get_input(1); + align_eltwise_input_types(context, x, y, true); + auto res = context.mark_node(std::make_shared(x, y)); + if (!context.input_is_none(2)) { + context.mutate_input(2, res); + } + return {res}; +} + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 9cb68a3ea5c17d..088a2ce9639468 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -96,10 +96,12 @@ OP_CONVERTER(translate_loop); OP_CONVERTER(translate_masked_fill); OP_CONVERTER(translate_masked_scatter); OP_CONVERTER(translate_max); +OP_CONVERTER(translate_maximum); OP_CONVERTER(translate_max_poolnd); OP_CONVERTER(translate_mean); OP_CONVERTER(translate_meshgrid); OP_CONVERTER(translate_min); +OP_CONVERTER(translate_minimum); OP_CONVERTER(translate_narrow); OP_CONVERTER(translate_native_multi_head_attention); OP_CONVERTER(translate_neg); @@ -351,12 +353,14 @@ const std::map get_supported_ops_ts() { {"aten::masked_scatter_", op::inplace_op}, {"aten::matmul", op::translate_1to1_match_2_inputs}, {"aten::max", op::translate_max}, + {"aten::maximum", op::translate_maximum}, {"aten::max_pool1d", op::quantizable_op}, {"aten::max_pool2d", op::quantizable_op}, {"aten::max_pool3d", op::quantizable_op}, {"aten::mean", op::quantizable_op}, {"aten::meshgrid", op::translate_meshgrid}, {"aten::min", op::translate_min}, + {"aten::minimum", op::translate_minimum}, {"aten::mm", op::translate_1to1_match_2_inputs}, {"aten::mul", op::translate_1to1_match_2_inputs_align_types}, {"aten::mul_", op::inplace_op>}, diff --git a/tests/layer_tests/pytorch_tests/test_min_max.py b/tests/layer_tests/pytorch_tests/test_min_max.py index 1d03c837380ed3..c32fe41512f800 100644 --- a/tests/layer_tests/pytorch_tests/test_min_max.py +++ b/tests/layer_tests/pytorch_tests/test_min_max.py @@ -210,3 +210,77 @@ def forward(self, x: float, y: float): def test_min(self, case, kwargs_to_prepare_input, ie_device, precision, ir_version): self._test(*self.create_model(case), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input, use_mo_convert=False) + + +class TestMinimumMaximum(PytorchLayerTest): + def _prepare_input(self, input_dtype="float32", second_input_dtype="float32", out=False): + import numpy as np + x = np.random.randn(1, 3, 10, 10).astype(input_dtype) + y = np.random.randn(1, 3, 10, 10).astype(second_input_dtype) + if not out: + return x, y + return (x, y, np.zeros_like(x).astype(input_dtype)) + + def create_model(self, op_type, dtypes=("float32", "float32"), out=False): + import torch + op_types = { + "maximum": torch.maximum, + "minimum": torch.minimum + } + + dtypes_map = { + "float32": torch.float32, + "int32": torch.int32, + "int64": torch.int64, + "float64": torch.float64 + } + + op = op_types[op_type] + + class aten_minimum_maximum(torch.nn.Module): + def __init__(self, op, l_dtype, r_dtype, out): + super(aten_minimum_maximum, self).__init__() + self.op = op + self.l_dtype = l_dtype + self.r_dtype = r_dtype + if out: + self.forward = self.forward_out + + def forward_out(self, x, y, z): + return self.op(x.to(self.l_dtype), y.to(self.r_dtype), out=z), z + + def forward(self, x, y): + return self.op(x.to(self.l_dtype), y.to(self.r_dtype)) + + l_dtype = dtypes_map[dtypes[0]] + r_dtype = dtypes_map[dtypes[1]] + model_cls = aten_minimum_maximum(op, l_dtype, r_dtype, out) + + return model_cls, None, f"aten::{op_type}" + + @pytest.mark.parametrize("op_type", ["minimum", "maximum"]) + @pytest.mark.parametrize("second_input_dtype", ["float32", "int32", "int64", "float64"]) + @pytest.mark.parametrize("first_input_dtype", ["float32", "int32", "int64", "float64"]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_minimum_maximum( + self, op_type, first_input_dtype, second_input_dtype, ie_device, precision, ir_version + ): + self._test(*self.create_model(op_type, dtypes=(first_input_dtype, second_input_dtype), out=False), + ie_device, precision, ir_version, kwargs_to_prepare_input= + {"input_dtype": first_input_dtype, "second_input_dtype": second_input_dtype, "out": False} + ) + + + @pytest.mark.parametrize("op_type", ['minimum', 'maximum']) + @pytest.mark.parametrize("input_dtype", ["float32", "int32", "int64", "float64"]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_minimum_maximum_out( + self, op_type, input_dtype, ie_device, precision, ir_version + ): + self._test(*self.create_model(op_type, dtypes=(input_dtype, input_dtype), out=True), + ie_device, precision, ir_version, kwargs_to_prepare_input= + {"input_dtype": input_dtype, "second_input_dtype": input_dtype, + "out": True} + ) \ No newline at end of file From aec4c6c8437e439796fc3d55564d756061418491 Mon Sep 17 00:00:00 2001 From: Egor Duplenskii Date: Fri, 22 Sep 2023 07:32:12 +0200 Subject: [PATCH 11/43] [CPU][ARM][FP16] Use Transpose executor for layout Reorder (#19227) --- src/plugins/intel_cpu/src/nodes/reorder.cpp | 88 +++++++++++++++++++-- src/plugins/intel_cpu/src/nodes/reorder.h | 5 ++ 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/reorder.cpp b/src/plugins/intel_cpu/src/nodes/reorder.cpp index 14c1cda04682d5..1cd1257f3318f0 100644 --- a/src/plugins/intel_cpu/src/nodes/reorder.cpp +++ b/src/plugins/intel_cpu/src/nodes/reorder.cpp @@ -17,6 +17,7 @@ #include "convert.h" #include #include +#include "executors/transpose_list.hpp" using namespace dnnl; using namespace InferenceEngine; @@ -116,6 +117,60 @@ void Reorder::executeDynamicImpl(dnnl::stream strm) { execute(strm); } +#if defined(OV_CPU_ARM_ENABLE_FP16) +void Reorder::prepareReorderAsTranspose(MemoryDescPtr parentDesc, MemoryDescPtr childDesc) { + auto getOrder = [](const MemoryDesc& lhs, const MemoryDesc& rhs) -> std::pair, std::vector> { + const auto& in = lhs.getShape().getStaticDims(); + const auto rank = lhs.getShape().getRank(); + + if (lhs.hasLayoutType(LayoutType::ncsp) && rhs.hasLayoutType(LayoutType::nspc)) { + if (rank == 4) + return {{0, 2, 3, 1}, {in[0], in[2], in[3], in[1]}}; + else + return {{0, 2, 1}, {in[0], in[2], in[1]}}; + + } else if (lhs.hasLayoutType(LayoutType::nspc) && rhs.hasLayoutType(LayoutType::ncsp)) { + if (rank == 4) + return {{0, 3, 1, 2}, {in[0], in[3], in[1], in[2]}}; + else + return {{0, 2, 1}, {in[0], in[2], in[1]}}; + } else { + if (rank == 4) + return {{0, 1, 2, 3}, in}; + else + return {{0, 1, 2}, in}; + } + }; + + auto order = getOrder(*parentDesc, *childDesc); + const auto& transposeOrder = order.first; + const auto& transposedDims = order.second; + + auto transposedDesc = std::make_shared(parentDesc->getPrecision(), Shape{transposedDims}); + + TransposeParams transposeParams; + transposeParams.permuteParams.src_block_dims = parentDesc->as()->getBlockDims(); + transposeParams.permuteParams.src_block_order = parentDesc->as()->getOrder(); + transposeParams.permuteParams.dst_block_dims = transposedDesc->as()->getBlockDims(); + transposeParams.permuteParams.dst_block_order = transposedDesc->as()->getOrder(); + transposeParams.permuteParams.order = transposeOrder; + transposeParams.permuteParams.data_size = parentDesc->getPrecision().size(); + + auto transpose_context = std::make_shared(context, getImplPriority()); + auto factory = std::make_shared(transposeParams, + std::vector{parentDesc}, + std::vector{transposedDesc}, + transpose_context); + dnnl::primitive_attr attr; + transposeExecutor = factory->makeExecutor(transposeParams, + {parentDesc}, + {transposedDesc}, + attr); + getSelectedPrimitiveDescriptor()->setImplementationType(transposeExecutor->getImplType()); + return; +} +#endif // OV_CPU_ARM_ENABLE_FP16 + void Reorder::prepareParams() { if (isOptimized) return; @@ -142,15 +197,27 @@ void Reorder::prepareParams() { return true; }; - const auto& parentDesc = srcMemPtr->getDesc(); - const auto& childDesc = dstMemPtr->getDesc(); - if ((isNspc2NcspCase || isNcsp2NspcCase) && isSupportedDesc(childDesc) && isSupportedDesc(parentDesc)) { + const auto& parentDesc = srcMemPtr->getDescPtr(); + const auto& childDesc = dstMemPtr->getDescPtr(); + +#if defined(OV_CPU_ARM_ENABLE_FP16) + // @todo current oneDNN v3.2 lacks optimized jit implementation for fp16 reorders. + // Use transpose executor as a temporary WA. + if (everyone_is(Precision::FP16, parentDesc->getPrecision(), childDesc->getPrecision()) && + ((parentDesc->hasLayoutType(LayoutType::ncsp) && childDesc->hasLayoutType(LayoutType::nspc)) || + (parentDesc->hasLayoutType(LayoutType::nspc) && childDesc->hasLayoutType(LayoutType::ncsp))) && + one_of(parentDesc->getShape().getRank(), 3, 4)) { + return prepareReorderAsTranspose(parentDesc, childDesc); + } +#endif + + if ((isNspc2NcspCase || isNcsp2NspcCase) && isSupportedDesc(*childDesc) && isSupportedDesc(*parentDesc)) { const auto &inDims = srcMemPtr->getStaticDims(); // Check that child strides are consistent with parent dims if the child is inplace. // The strides must be dense except for the channel one (since the child num channels might differ) const auto childSubBlocksAreDense = [&]() { - const auto& dstStrides = childDesc.as()->getStrides(); - const auto& dstOrder = childDesc.as()->getOrder(); + const auto& dstStrides = childDesc->as()->getStrides(); + const auto& dstOrder = childDesc->as()->getOrder(); const size_t channelDim = 1; if (dstStrides.back() != 1) return false; @@ -162,7 +229,7 @@ void Reorder::prepareParams() { }; if (isNspc2NcspCase) { canUseNspc2Ncsp = inDims[1] <= 64 && inDims[1] >= 16 && - (parentDesc.as()->getPaddedElementsCount() / inDims[1]) >= 128 && + (parentDesc->as()->getPaddedElementsCount() / inDims[1]) >= 128 && childSubBlocksAreDense(); } else if (isNcsp2NspcCase) { canUseNcsp2Nspc = childSubBlocksAreDense(); @@ -326,6 +393,15 @@ void Reorder::optimizedNspc2Ncsp() { } void Reorder::execute(dnnl::stream strm) { +#if defined(OV_CPU_ARM_ENABLE_FP16) + if (transposeExecutor) { + auto dstMemPtr = getChildEdgeAt(0)->getMemoryPtr(); + auto srcMemPtr = getParentEdgeAt(0)->getMemoryPtr(); + int MB = srcMemPtr->getStaticDims()[0]; + return transposeExecutor->exec({srcMemPtr}, {dstMemPtr}, MB); + } +#endif + if (isOptimized) { DEBUG_LOG("#", getExecIndex(), " Reorder ", getName(), " is Optimized.", " input @", getParentEdgeAt(0)->getMemory().getData(), diff --git a/src/plugins/intel_cpu/src/nodes/reorder.h b/src/plugins/intel_cpu/src/nodes/reorder.h index ef8e508fa08123..5e6a125ca94346 100644 --- a/src/plugins/intel_cpu/src/nodes/reorder.h +++ b/src/plugins/intel_cpu/src/nodes/reorder.h @@ -9,6 +9,7 @@ #include #include #include +#include "nodes/executors/transpose.hpp" #include namespace ov { @@ -83,6 +84,10 @@ class Reorder : public Node { void optimizedNspc2Ncsp(); void optimizedNcsp2Nspc(); void createReorderPrimitive(const dnnl::memory::desc &srcDesc, void* srcPtr, const dnnl::memory::desc &dstDesc, void* dstPtr); +#if defined(OV_CPU_ARM_ENABLE_FP16) + void prepareReorderAsTranspose(MemoryDescPtr parentDesc, MemoryDescPtr childDesc); + TransposeExecutorPtr transposeExecutor; +#endif }; } // namespace node From 6de8579b1d141761d192d6b6e60b9e4eb667a6dd Mon Sep 17 00:00:00 2001 From: Egor Duplenskii Date: Fri, 22 Sep 2023 07:33:16 +0200 Subject: [PATCH 12/43] [CPU][ARM] Choose eltwise layout based on model type (#19234) Eltwise order of the supported primitive descriptors affects the performance of the model. Often only one of the port descriptors matches with the layout of the parent descriptors, i.e. when two parent ports have mixed layout "nchw nhwc". So either nchw or nhwc layout will be used for the eltwise node and reorder will be used for either of the ports. The shape of the ports also can be different (when one of the inputs is broadcasted). So reorders on different ports have different performance impact. The layout of the eltwise node child has an effect on the performance as well, since it may or may not require reorder on input. --- src/plugins/intel_cpu/src/config.cpp | 3 ++- src/plugins/intel_cpu/src/config.h | 3 ++- src/plugins/intel_cpu/src/nodes/eltwise.cpp | 25 ++++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp index c616df1ecf8712..10630c8891dddf 100644 --- a/src/plugins/intel_cpu/src/config.cpp +++ b/src/plugins/intel_cpu/src/config.cpp @@ -69,7 +69,7 @@ void Config::applyDebugCapsProperties() { } #endif -void Config::readProperties(const std::map &prop, ModelType modelType) { +void Config::readProperties(const std::map &prop, const ModelType modelType) { const auto streamExecutorConfigKeys = streamExecutorConfig.SupportedKeys(); const auto hintsConfigKeys = perfHintsConfig.SupportedKeys(); for (const auto& kvp : prop) { @@ -267,6 +267,7 @@ void Config::readProperties(const std::map &prop, Mode streamExecutorConfig._streams = 1; streamExecutorConfig._streams_changed = true; #endif + this->modelType = modelType; CPU_DEBUG_CAP_ENABLE(applyDebugCapsProperties()); updateProperties(); diff --git a/src/plugins/intel_cpu/src/config.h b/src/plugins/intel_cpu/src/config.h index 320701cf13c793..fab215e64c10b0 100644 --- a/src/plugins/intel_cpu/src/config.h +++ b/src/plugins/intel_cpu/src/config.h @@ -88,7 +88,7 @@ struct Config { // is reserved. bool DAZOn = false; - void readProperties(const std::map &config, ModelType modelType = ModelType::Unknown); + void readProperties(const std::map &config, const ModelType modelType = ModelType::Unknown); void updateProperties(); std::map _config; @@ -96,6 +96,7 @@ struct Config { bool isLegacyApi = false; int modelPreferThreads = -1; + ModelType modelType = ModelType::Unknown; #ifdef CPU_DEBUG_CAPS DebugCapsConfig debugCaps; diff --git a/src/plugins/intel_cpu/src/nodes/eltwise.cpp b/src/plugins/intel_cpu/src/nodes/eltwise.cpp index 11d52cd45e8b95..32bd0382244b36 100644 --- a/src/plugins/intel_cpu/src/nodes/eltwise.cpp +++ b/src/plugins/intel_cpu/src/nodes/eltwise.cpp @@ -11,6 +11,7 @@ #include +#include "config.h" #include "cpu_types.h" #include "utils/bfloat16.hpp" #include "ie_ngraph_utils.hpp" @@ -2171,15 +2172,23 @@ void Eltwise::initSupportedPrimitiveDescriptors() { #if defined (OV_CPU_WITH_ACL) eltwiseAttrs = {algorithm, alpha, beta, gamma}; - if (isChannelsFirstApplicable) { - auto channelFirstDesc = initDesc(ChannelsFirst, true); - if (channelFirstDesc.getExecutorFactory()) - supportedPrimitiveDescriptors.emplace_back(channelFirstDesc); - } - auto planarDesc = initDesc(Planar, true); - if (planarDesc.getExecutorFactory()) - supportedPrimitiveDescriptors.emplace_back(planarDesc); + auto addDesc = [&initDesc](std::vector& supportedPrimitiveDescriptors, const LayoutType layoutType) { + auto nodeDesc = initDesc(layoutType, true); + if (nodeDesc.getExecutorFactory()) + supportedPrimitiveDescriptors.emplace_back(nodeDesc); + }; + + // @todo should be handled in scope of selectPreferPrimitiveDescriptor + if (context->getConfig().modelType == Config::ModelType::CNN) { + if (isChannelsFirstApplicable) + addDesc(supportedPrimitiveDescriptors, ChannelsFirst); + addDesc(supportedPrimitiveDescriptors, Planar); + } else { + addDesc(supportedPrimitiveDescriptors, Planar); + if (isChannelsFirstApplicable) + addDesc(supportedPrimitiveDescriptors, ChannelsFirst); + } canUseAclExecutor = !supportedPrimitiveDescriptors.empty(); if (canUseAclExecutor) From 3f3d89678eba9825010e7141d9652d85f693a11b Mon Sep 17 00:00:00 2001 From: Egor Duplenskii Date: Fri, 22 Sep 2023 07:33:33 +0200 Subject: [PATCH 13/43] [CPU][ARM] Reorder FullyConnected weights in scope of compile_model (#19634) --- .../intel_cpu/src/nodes/fullyconnected.cpp | 278 ++++++++++-------- .../intel_cpu/src/nodes/fullyconnected.h | 6 +- 2 files changed, 163 insertions(+), 121 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp index deac818e4fbb98..fcb112c368131c 100644 --- a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp +++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp @@ -9,6 +9,7 @@ #include "fake_quantize.h" #include "input.h" #include "memory_desc/blocked_memory_desc.h" +#include "memory_desc/dnnl_memory_desc.h" #include "reorder.h" #include "transformations/cpu_opset/common/op/fully_connected.hpp" #include "ngraph/opsets/opset1.hpp" @@ -329,6 +330,156 @@ void FullyConnected::prepackMLASWeight() { } #endif +static dnnl::convolution_forward::primitive_desc +createDescriptorInternalForConv(DnnlMemoryDescCPtr inputDescPtr, + DnnlMemoryDescCPtr weightDescPtr, + DnnlMemoryDescCPtr biasDescPtr, + DnnlMemoryDescCPtr outputDescPtr, + const dnnl::primitive_attr& attr, + const dnnl::engine& engine) { + const dnnl::memory::desc &inputDesc = inputDescPtr->getDnnlDesc(); + const dnnl::memory::desc &outputDesc = outputDescPtr->getDnnlDesc(); + const dnnl::memory::desc &weightDesc = weightDescPtr->getDnnlDesc(); + // make a fake shape: N, IC, W + auto inDims = inputDesc.get_dims(); + dnnl::memory::dims normalizedInDims; + if (inDims.size() == 3) { + normalizedInDims = {inDims[0], inDims[2], inDims[1]}; + } else if (inDims.size() == 2) { + normalizedInDims = {dnnl::memory::dim{1}, inDims[1], inDims[0]}; + } + auto convInDesc = dnnl::memory::desc(normalizedInDims, inputDesc.get_data_type(), memory::format_tag::nwc); + + // make a fake shape: N, OC, W + const auto& outDims = outputDesc.get_dims(); + dnnl::memory::dims normalizedOutDims; + if (outDims.size() == 3) { + normalizedOutDims = { outDims[0], outDims[2], outDims[1]}; + } else if (outDims.size() == 2) { + normalizedOutDims = { dnnl::memory::dim{1}, outDims[1], outDims[0]}; + } + auto convOutDesc = dnnl::memory::desc(normalizedOutDims, outputDesc.get_data_type(), memory::format_tag::nwc); + + // make a fake shape: OC, IC, 1 + auto weightDims = weightDesc.get_dims(); + dnnl::memory::dims normalizedWeightDims; + normalizedWeightDims = {static_cast(weightDims[0]), + static_cast(weightDims[1]), + dnnl::memory::dim{1}}; + auto convWeightDescAny = dnnl::memory::desc(normalizedWeightDims, weightDesc.get_data_type(), dnnl::memory::format_tag::any); + + if (biasDescPtr) { + return dnnl::convolution_forward::primitive_desc( + engine, + prop_kind::forward_inference, + dnnl::algorithm::convolution_direct, + convInDesc, convWeightDescAny, biasDescPtr->getDnnlDesc(), convOutDesc, + dnnl::memory::dims{1}, // stride + dnnl::memory::dims{0}, // dilation + dnnl::memory::dims{0}, // paddingL + dnnl::memory::dims{0}, // paddingR + attr); + } else { + return dnnl::convolution_forward::primitive_desc( + engine, + prop_kind::forward_inference, dnnl::algorithm::convolution_direct, + convInDesc, convWeightDescAny, convOutDesc, + dnnl::memory::dims{1}, // stride + dnnl::memory::dims{0}, // dilation + dnnl::memory::dims{0}, // paddingL + dnnl::memory::dims{0}, // paddingR + attr); + } +} + +static dnnl::primitive_desc createPrimitiveDesc(const FCKey& key, const dnnl::engine& engine) { + // use conv1x1 primitive for computation + if (key.useConv1x1) { + auto prim_desc = createDescriptorInternalForConv(key.inp0, key.inp1, key.bias, key.out, key.attr, engine); + const bool found = DnnlExtensionUtils::find_implementation(prim_desc, brgconv_avx512_1x1); + + if (found) + return std::move(prim_desc); + } + + // fallback to normal inner product primitive + auto inDesc = key.inp0->getDnnlDesc(); + const auto& inDims = inDesc.get_dims(); // @TODO query + copy might be slow + if (inDims.size() == 3) { + auto normalizedInDims = {inDims[0] * inDims[1], inDims[2]}; + inDesc = inDesc.reshape(normalizedInDims); + } + auto outDesc = key.out->getDnnlDesc(); + const auto& outDims = outDesc.get_dims(); // @TODO query + copy might be slow + + if (outDims.size() == 3) { + auto normalizedOutDims = { outDims[0] * outDims[1], outDims[2] }; + outDesc = outDesc.reshape(normalizedOutDims); + } + auto wghDescAny = dnnl::memory::desc(DnnlExtensionUtils::convertToDnnlDims(key.inp1->getShape().getStaticDims()), + key.inp1->getDataType(), memory::format_tag::any); + dnnl::inner_product_forward::primitive_desc prim_desc; + if (key.bias) { + prim_desc = dnnl::inner_product_forward::primitive_desc( + engine, + dnnl::prop_kind::forward_inference, + inDesc, + wghDescAny, + key.bias->getDnnlDesc(), + outDesc, + key.attr); + } else { + prim_desc = dnnl::inner_product_forward::primitive_desc( + engine, + dnnl::prop_kind::forward_inference, + inDesc, + wghDescAny, + outDesc, + key.attr); + } + auto first_desc = dnnl::inner_product_forward::primitive_desc(prim_desc.get()); + const bool found = DnnlExtensionUtils::find_implementation(prim_desc, key.implType); + + if (found) + return std::move(prim_desc); + + return std::move(first_desc); +} + +#if defined(OV_CPU_WITH_ACL) +/** + * Do not wait till prepareParams to reorder the weights + * Do it in scope of compile_model using dummy shapes + */ +void FullyConnected::prepareWeightsUsingDummyShape() { + NodeDesc *selected_pd = getSelectedPrimitiveDescriptor(); + if (selected_pd == nullptr) + IE_THROW() << "Preferable primitive descriptor is not set for node " << getName() << "."; + + auto inDesc = MemoryDescUtils::convertToDnnlMemoryDesc(MemoryDescUtils::makeDummyDesc(*getBaseMemDescAtInputPort(DATA_ID))); + auto weightDesc = MemoryDescUtils::convertToDnnlMemoryDesc(weightDescIP); + auto biasDesc = withBiases ? MemoryDescUtils::convertToDnnlMemoryDesc(getBaseMemDescAtInputPort(BIAS_ID)) : nullptr; + auto outDesc = MemoryDescUtils::convertToDnnlMemoryDesc(MemoryDescUtils::makeDummyDesc(*getBaseMemDescAtOutputPort(0))); + + const FCKey key = {inDesc, + weightDesc, + biasDesc, + outDesc, + attr, + selected_pd->getImplementationType(), + false}; + + auto prim_desc = createPrimitiveDesc(key, getEngine()); + auto weights = DnnlExtensionUtils::makeDescriptor(prim_desc.weights_desc()); + // ignore the result since we just need to put the reordered weights into the cache + if (weightsNonTransposed) { + (void) prepareWeightMemory(weights, makeTransposedWeightDescriptor(weights)); + } else { + (void) prepareWeightMemory(weights); + } +} +#endif + void FullyConnected::createPrimitive() { #ifdef OV_CPU_WITH_MLAS if (useMlas) { @@ -341,6 +492,9 @@ void FullyConnected::createPrimitive() { attr.set_scratchpad_mode(dnnl::scratchpad_mode::user); Node::createPrimitive(); appendPostOpArgs(attr, primArgs, postOpsArgs); +#if defined(OV_CPU_WITH_ACL) + prepareWeightsUsingDummyShape(); +#endif } void FullyConnected::prepareParams() { @@ -393,60 +547,7 @@ void FullyConnected::prepareParams() { auto& engine = getEngine(); auto builder = [&engine](const FCKey& key) -> executorPtr { - // use conv1x1 primitive for computation - if (key.useConv1x1) { - auto prim_desc = createDescriptorInternalForConv(key.inp0, key.inp1, key.bias, key.out, key.attr, engine); - const bool found = DnnlExtensionUtils::find_implementation(prim_desc, brgconv_avx512_1x1); - - if (found) - return std::make_shared(prim_desc); - } - - // fallback to normal inner product primitive - auto inDesc = key.inp0->getDnnlDesc(); - const auto& inDims = inDesc.get_dims(); // @TODO query + copy might be slow - if (inDims.size() == 3) { - auto normalizedInDims = {inDims[0] * inDims[1], inDims[2]}; - inDesc = inDesc.reshape(normalizedInDims); - } - auto outDesc = key.out->getDnnlDesc(); - const auto& outDims = outDesc.get_dims(); // @TODO query + copy might be slow - - if (outDims.size() == 3) { - auto normalizedOutDims = { outDims[0] * outDims[1], outDims[2] }; - outDesc = outDesc.reshape(normalizedOutDims); - } - auto wghDescAny = dnnl::memory::desc(DnnlExtensionUtils::convertToDnnlDims(key.inp1->getShape().getStaticDims()), - key.inp1->getDataType(), memory::format_tag::any); - dnnl::inner_product_forward::primitive_desc prim_desc; - if (key.bias) { - prim_desc = dnnl::inner_product_forward::primitive_desc( - engine, - dnnl::prop_kind::forward_inference, - inDesc, - wghDescAny, - key.bias->getDnnlDesc(), - outDesc, - key.attr); - } else { - prim_desc = dnnl::inner_product_forward::primitive_desc( - engine, - dnnl::prop_kind::forward_inference, - inDesc, - wghDescAny, - outDesc, - key.attr); - } - auto first_desc = dnnl::inner_product_forward::primitive_desc(prim_desc.get()); - const bool found = DnnlExtensionUtils::find_implementation(prim_desc, key.implType); - - if (found) - return std::make_shared(prim_desc); - - // For dynamic shape, the expected implement type kernel can support with dummy shape but - // not the run time inference shape. In this case, the implementation type will be - // ignored and the first available primitive descriptor will be chosen - return std::make_shared(first_desc); + return std::make_shared(createPrimitiveDesc(key, engine)); }; auto cache = context->getParamsCache(); @@ -487,7 +588,8 @@ void FullyConnected::prepareParams() { } #endif if (weightsNonTransposed) { - primArgs[DNNL_ARG_WEIGHTS] = prepareWeightMemory(execPtr->getWeightDesc(), makeTransposedWeightDescriptor())->getPrimitive(); + primArgs[DNNL_ARG_WEIGHTS] = prepareWeightMemory(execPtr->getWeightDesc(), + makeTransposedWeightDescriptor(execPtr->getWeightDesc()))->getPrimitive(); } else { primArgs[DNNL_ARG_WEIGHTS] = prepareWeightMemory(execPtr->getWeightDesc())->getPrimitive(); } @@ -912,68 +1014,6 @@ void FullyConnected::initOptimalPrimitiveDescriptor() { selectedPD->setConfig(config); } -dnnl::convolution_forward::primitive_desc -FullyConnected::createDescriptorInternalForConv(DnnlMemoryDescCPtr inputDescPtr, - DnnlMemoryDescCPtr weightDescPtr, - DnnlMemoryDescCPtr biasDescPtr, - DnnlMemoryDescCPtr outputDescPtr, - const dnnl::primitive_attr& attr, - const dnnl::engine& engine) { - const dnnl::memory::desc &inputDesc = inputDescPtr->getDnnlDesc(); - const dnnl::memory::desc &outputDesc = outputDescPtr->getDnnlDesc(); - const dnnl::memory::desc &weightDesc = weightDescPtr->getDnnlDesc(); - // make a fake shape: N, IC, W - auto inDims = inputDesc.get_dims(); - dnnl::memory::dims normalizedInDims; - if (inDims.size() == 3) { - normalizedInDims = {inDims[0], inDims[2], inDims[1]}; - } else if (inDims.size() == 2) { - normalizedInDims = {dnnl::memory::dim{1}, inDims[1], inDims[0]}; - } - auto convInDesc = dnnl::memory::desc(normalizedInDims, inputDesc.get_data_type(), memory::format_tag::nwc); - - // make a fake shape: N, OC, W - const auto& outDims = outputDesc.get_dims(); - dnnl::memory::dims normalizedOutDims; - if (outDims.size() == 3) { - normalizedOutDims = { outDims[0], outDims[2], outDims[1]}; - } else if (outDims.size() == 2) { - normalizedOutDims = { dnnl::memory::dim{1}, outDims[1], outDims[0]}; - } - auto convOutDesc = dnnl::memory::desc(normalizedOutDims, outputDesc.get_data_type(), memory::format_tag::nwc); - - // make a fake shape: OC, IC, 1 - auto weightDims = weightDesc.get_dims(); - dnnl::memory::dims normalizedWeightDims; - normalizedWeightDims = {static_cast(weightDims[0]), - static_cast(weightDims[1]), - dnnl::memory::dim{1}}; - auto convWeightDescAny = dnnl::memory::desc(normalizedWeightDims, weightDesc.get_data_type(), dnnl::memory::format_tag::any); - - if (biasDescPtr) { - return dnnl::convolution_forward::primitive_desc( - engine, - prop_kind::forward_inference, - dnnl::algorithm::convolution_direct, - convInDesc, convWeightDescAny, biasDescPtr->getDnnlDesc(), convOutDesc, - dnnl::memory::dims{1}, // stride - dnnl::memory::dims{0}, // dilation - dnnl::memory::dims{0}, // paddingL - dnnl::memory::dims{0}, // paddingR - attr); - } else { - return dnnl::convolution_forward::primitive_desc( - engine, - prop_kind::forward_inference, dnnl::algorithm::convolution_direct, - convInDesc, convWeightDescAny, convOutDesc, - dnnl::memory::dims{1}, // stride - dnnl::memory::dims{0}, // dilation - dnnl::memory::dims{0}, // paddingL - dnnl::memory::dims{0}, // paddingR - attr); - } -} - bool FullyConnected::canBeExecutedInConv1x1() const { bool retVal = false; const auto inRank = getInputShapeAtPort(DATA_ID).getRank(); @@ -1106,7 +1146,7 @@ void FullyConnected::fuseDecompressionConstant(const NodePtr& constData, std::ve elementsCount); } -DnnlMemoryDescPtr FullyConnected::makeTransposedWeightDescriptor() { +DnnlMemoryDescPtr FullyConnected::makeTransposedWeightDescriptor(DnnlMemoryDescPtr desc) { if (!getParentEdgeAt(1)->getParent()->isConstant()) IE_THROW() << "Weight input is not const for node " << getName() << "."; auto edgeMem = getParentEdgeAt(1)->getMemoryPtr(); @@ -1116,7 +1156,7 @@ DnnlMemoryDescPtr FullyConnected::makeTransposedWeightDescriptor() { auto constDnnlMemOutDesc = edgeMem->getDescWithType(); auto weightSrcDesc = constDnnlMemOutDesc->getDnnlDesc(); weightSrcDesc = {weightSrcDesc.get_dims(), weightSrcDesc.get_data_type(), memory::format_tag::ba}; - weightSrcDesc = weightSrcDesc.reshape(execPtr->getWeightDesc()->getDnnlDesc().get_dims()); + weightSrcDesc = weightSrcDesc.reshape(desc->getDnnlDesc().get_dims()); return DnnlExtensionUtils::makeDescriptor(weightSrcDesc); } diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.h b/src/plugins/intel_cpu/src/nodes/fullyconnected.h index 9192d741cf6ebd..8c25927ca06f36 100644 --- a/src/plugins/intel_cpu/src/nodes/fullyconnected.h +++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.h @@ -117,14 +117,16 @@ class FullyConnected : public Node { void executeMLAS(); void prepackMLASWeight(); #endif - +#if defined(OV_CPU_WITH_ACL) + void prepareWeightsUsingDummyShape(); +#endif bool useWeightsDecompressionImpl = false; std::vector decompressionSubtract; std::vector decompressionMultiply; // FC with transposed weights bool weightsNonTransposed = false; - DnnlMemoryDescPtr makeTransposedWeightDescriptor(); + DnnlMemoryDescPtr makeTransposedWeightDescriptor(DnnlMemoryDescPtr desc); }; } // namespace node From 8d59fcd34ff1c0e323010109ec2a6d0de508ba28 Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Fri, 22 Sep 2023 10:11:36 +0400 Subject: [PATCH 14/43] [PT FE]: extend logical operations support (#19981) * [PT FE]: extend logical operations support * tests * more tests --- src/frontends/pytorch/src/op/logical.cpp | 42 ++++++++++-- src/frontends/pytorch/src/op_table.cpp | 6 ++ .../pytorch_tests/test_logical_ops.py | 64 +++++++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 tests/layer_tests/pytorch_tests/test_logical_ops.py diff --git a/src/frontends/pytorch/src/op/logical.cpp b/src/frontends/pytorch/src/op/logical.cpp index 0c5a93e2c91933..b094067dbbd05d 100644 --- a/src/frontends/pytorch/src/op/logical.cpp +++ b/src/frontends/pytorch/src/op/logical.cpp @@ -4,7 +4,9 @@ #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/logical_and.hpp" +#include "openvino/op/logical_not.hpp" #include "openvino/op/logical_or.hpp" +#include "openvino/op/logical_xor.hpp" #include "utils.hpp" namespace ov { @@ -15,25 +17,57 @@ namespace op { using namespace ov::op; OutputVector translate_or(const NodeContext& context) { - num_inputs_check(context, 2, 2); + num_inputs_check(context, 2, 3); auto x = context.get_input(0); auto y = context.get_input(1); x = context.mark_node(std::make_shared(x, element::boolean)); y = context.mark_node(std::make_shared(y, element::boolean)); // TODO: use bitwise op here when will be supported by openvino auto or_node = context.mark_node(std::make_shared(x, y)); + if (!context.input_is_none(2)) { + context.mutate_input(2, or_node); + } return {or_node}; }; OutputVector translate_and(const NodeContext& context) { - num_inputs_check(context, 2, 2); + num_inputs_check(context, 2, 3); auto x = context.get_input(0); auto y = context.get_input(1); x = context.mark_node(std::make_shared(x, element::boolean)); y = context.mark_node(std::make_shared(y, element::boolean)); // TODO: use bitwise op here when will be supported by openvino - auto or_node = context.mark_node(std::make_shared(x, y)); - return {or_node}; + auto and_node = context.mark_node(std::make_shared(x, y)); + if (!context.input_is_none(2)) { + context.mutate_input(2, and_node); + } + return {and_node}; +}; + +OutputVector translate_not(const NodeContext& context) { + num_inputs_check(context, 1, 2); + auto x = context.get_input(0); + x = context.mark_node(std::make_shared(x, element::boolean)); + // TODO: use bitwise op here when will be supported by openvino + auto not_node = context.mark_node(std::make_shared(x)); + if (!context.input_is_none(1)) { + context.mutate_input(1, not_node); + } + return {not_node}; +}; + +OutputVector translate_xor(const NodeContext& context) { + num_inputs_check(context, 2, 3); + auto x = context.get_input(0); + auto y = context.get_input(1); + x = context.mark_node(std::make_shared(x, element::boolean)); + y = context.mark_node(std::make_shared(y, element::boolean)); + // TODO: use bitwise op here when will be supported by openvino + auto xor_node = context.mark_node(std::make_shared(x, y)); + if (!context.input_is_none(2)) { + context.mutate_input(2, xor_node); + } + return {xor_node}; }; } // namespace op diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 088a2ce9639468..94bd71286df807 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -111,6 +111,7 @@ OP_CONVERTER(translate_new_zeros); OP_CONVERTER(translate_nms); OP_CONVERTER(translate_nonzero); OP_CONVERTER(translate_norm); +OP_CONVERTER(translate_not); OP_CONVERTER(translate_numel); OP_CONVERTER(translate_one_hot); OP_CONVERTER(translate_ones); @@ -188,6 +189,7 @@ OP_CONVERTER(translate_quantized_cat); OP_CONVERTER(translate_quantized_convnd); OP_CONVERTER(translate_quantized_convnd_relu); OP_CONVERTER(translate_quantized_linear); +OP_CONVERTER(translate_xor); // Torch FX Translations OP_CONVERTER(translate_arange_fx); OP_CONVERTER(translate_batch_norm_fx); @@ -343,6 +345,10 @@ const std::map get_supported_ops_ts() { {"aten::linspace", op::translate_linspace}, {"aten::log", op::translate_log}, {"aten::log_", op::inplace_op}, + {"aten::logical_and", op::translate_and}, + {"aten::logical_or", op::translate_or}, + {"aten::logical_not", op::translate_not}, + {"aten::logical_xor", op::translate_xor}, {"aten::log_softmax", op::translate_log_softmax}, {"aten::log2", op::translate_log2}, {"aten::log2_", op::inplace_op}, diff --git a/tests/layer_tests/pytorch_tests/test_logical_ops.py b/tests/layer_tests/pytorch_tests/test_logical_ops.py new file mode 100644 index 00000000000000..210fd1a4bdb690 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_logical_ops.py @@ -0,0 +1,64 @@ +import numpy as np +import pytest +from pytorch_layer_test_class import PytorchLayerTest + +class TestLogicalOp(PytorchLayerTest): + + def _prepare_input(self, out, unary, first_dtype, second_dtype): + x = np.random.randint(1, 5, (1, 10)).astype(first_dtype) + if unary: + return (x, ) if not out else (x, np.zeros_like(x).astype(bool)) + y = np.random.randint(1, 5, (1, 10)).astype(second_dtype) + if not out: + return x, y + return x, y, np.zeros_like(x).astype(bool) + + def create_model(self, op_name, out): + import torch + + ops = { + "and": torch.logical_and, + "or": torch.logical_or, + "xor": torch.logical_xor, + "not": torch.logical_not + } + op = ops[op_name] + class aten_logical(torch.nn.Module): + + def __init__(self, op, out) -> None: + super().__init__() + self.op = op + if op == torch.logical_not: + self.forward = self.forward_not + if out: + self.forward = self.forward_out if not op == torch.logical_not else self.forward_not_out + + def forward(self, tensor_a, tensor_b): + return self.op(tensor_a, tensor_b) + + + def forward_out(self, tensor_a, tensor_b, out): + return self.op(tensor_a, tensor_b, out=out), out + + def forward_not(self, tensor_a): + return self.op(tensor_a) + + def forward_not_out(self, tensor_a, out): + return self.op(tensor_a, out=out), out + + ref_net = None + + return aten_logical(op, out), ref_net, f"aten::logical_{op_name}" + + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("op_type", ["and", "or", "not", "xor"]) + @pytest.mark.parametrize("first_dtype", ["bool", "int32", 'int8', 'float32']) + @pytest.mark.parametrize("second_dtype", ["bool", "int32", 'int8', 'float32']) + @pytest.mark.parametrize("out", [True, False]) + def test_logical(self, op_type, out, first_dtype, second_dtype, ie_device, precision, ir_version): + self._test(*self.create_model(op_type, out), + ie_device, precision, ir_version, + kwargs_to_prepare_input={"out": out, "unary": op_type == "not", + "first_dtype": first_dtype, "second_dtype": second_dtype}) \ No newline at end of file From aa293c09ac4c160aff93cee9ff07ef14a9362e72 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Fri, 22 Sep 2023 08:53:41 +0200 Subject: [PATCH 15/43] [core]Api 2.0/migrate ceiling op to new API (#19909) * Migrate Ceiling op to new API * Remove f16 precision from evaluate * Correct ceiling reference doxy comments - correct functor arg to be const --- src/core/include/openvino/op/ceiling.hpp | 4 +- .../include/openvino/reference/ceiling.hpp | 33 ++++- .../include/openvino/reference/copy.hpp | 6 +- src/core/src/op/ceiling.cpp | 113 ++++++++---------- 4 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/core/include/openvino/op/ceiling.hpp b/src/core/include/openvino/op/ceiling.hpp index d22b8ad5b16246..b372e3d1887b99 100644 --- a/src/core/include/openvino/op/ceiling.hpp +++ b/src/core/include/openvino/op/ceiling.hpp @@ -25,9 +25,7 @@ class OPENVINO_API Ceiling : public util::UnaryElementwiseArithmetic { return true; } std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v0 diff --git a/src/core/reference/include/openvino/reference/ceiling.hpp b/src/core/reference/include/openvino/reference/ceiling.hpp index e6aafae44f332d..69553d470b13b9 100644 --- a/src/core/reference/include/openvino/reference/ceiling.hpp +++ b/src/core/reference/include/openvino/reference/ceiling.hpp @@ -7,13 +7,36 @@ #include #include +#include "openvino/reference/copy.hpp" +#include "openvino/reference/utils/type_util.hpp" + namespace ov { namespace reference { -template -void ceiling(const T* arg, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = static_cast(std::ceil(arg[i])); - } + +/** + * @brief Reference implementation of Ceiling operator (integral types). + * + * @param arg Input pointer to data. + * @param out Output pointer to results. + * @param count Number of elements in input buffer. + */ +template ::value>::type* = nullptr> +void ceiling(const T* arg, T* out, const size_t count) { + copy(arg, out, count); +} + +/** + * @brief Reference implementation of Ceiling operator (floating point types). + * + * @param arg Input pointer to data. + * @param out Output pointer to results. + * @param count Number of elements in input buffer. + */ +template ()>::type* = nullptr> +void ceiling(const T* arg, T* out, const size_t count) { + std::transform(arg, std::next(arg, count), out, [](const T v) { + return std::ceil(v); + }); } } // namespace reference } // namespace ov diff --git a/src/core/reference/include/openvino/reference/copy.hpp b/src/core/reference/include/openvino/reference/copy.hpp index 3e3d49105848ec..245489ad6167c2 100644 --- a/src/core/reference/include/openvino/reference/copy.hpp +++ b/src/core/reference/include/openvino/reference/copy.hpp @@ -4,15 +4,13 @@ #pragma once -#include +#include namespace ov { namespace reference { template void copy(const T* arg, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = arg[i]; - } + std::copy_n(arg, count, out); } } // namespace reference } // namespace ov diff --git a/src/core/src/op/ceiling.cpp b/src/core/src/op/ceiling.cpp index 29a36600f2dac0..8b8f9e96f2503f 100644 --- a/src/core/src/op/ceiling.cpp +++ b/src/core/src/op/ceiling.cpp @@ -2,91 +2,72 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/ceiling.hpp" +#include "openvino/op/ceiling.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/op/util/eval_copy.hpp" -#include "ngraph/runtime/host_tensor.hpp" -#include "ngraph/validation_util.hpp" +#include "openvino/core/validation_util.hpp" #include "openvino/reference/ceiling.hpp" -#include "openvino/reference/copy.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace ceiling { + +struct Evaluate : element::NoAction { + using element::NoAction::visit; -op::Ceiling::Ceiling(const Output& arg) : UnaryElementwiseArithmetic(arg) { + template + static result_type visit(const Tensor& arg0, Tensor& out, const size_t count) { + using T = typename element_type_traits::value_type; + reference::ceiling(arg0.data(), out.data(), count); + return true; + } +}; +} // namespace ceiling + +namespace v0 { +Ceiling::Ceiling(const Output& arg) : UnaryElementwiseArithmetic(arg) { constructor_validate_and_infer_types(); } -shared_ptr op::Ceiling::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Ceiling::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Ceiling_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0)); -} - -OPENVINO_SUPPRESS_DEPRECATED_START -namespace ceiling { -namespace { -// function used by TYPE_CASE -template -inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { - using T = typename element_type_traits::value_type; - ov::reference::ceiling(arg0->get_data_ptr(), out->get_data_ptr(), count); - return true; + return std::make_shared(new_args.at(0)); } -// function used by COPY_TENSOR -template -inline bool copy_tensor(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { - ov::reference::copy(arg0->get_data_ptr(), out->get_data_ptr(), count); - return true; -} - -bool evaluate_ceiling(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) { - bool rc = true; - out->set_unary(arg0); +bool Ceiling::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OV_OP_SCOPE(v0_Ceiling_evaluate); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 1); - switch (arg0->get_element_type()) { - NGRAPH_COPY_TENSOR(evaluate_ceiling, i8, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, i16, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, i32, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, i64, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, u8, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, u16, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, u32, arg0, out, count); - NGRAPH_COPY_TENSOR(evaluate_ceiling, u64, arg0, out, count); - NGRAPH_TYPE_CASE(evaluate_ceiling, f16, arg0, out, count); - NGRAPH_TYPE_CASE(evaluate_ceiling, f32, arg0, out, count); - default: - rc = false; - break; - } - return rc; -} -} // namespace -} // namespace ceiling + outputs[0].set_shape(inputs[0].get_shape()); -bool op::Ceiling::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { - OV_OP_SCOPE(v0_Ceiling_evaluate); - return ceiling::evaluate_ceiling(inputs[0], outputs[0], shape_size(inputs[0]->get_shape())); + using namespace ov::element; + return IfTypeOf::apply( + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } -bool op::Ceiling::has_evaluate() const { +bool Ceiling::has_evaluate() const { OV_OP_SCOPE(v0_Ceiling_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::i8: - case ngraph::element::i16: - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u8: - case ngraph::element::u16: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::f16: - case ngraph::element::f32: + case element::i8: + case element::i16: + case element::i32: + case element::i64: + case element::u8: + case element::u16: + case element::u32: + case element::u64: + case element::f32: return true; default: - break; + return false; } - return false; } +} // namespace v0 +} // namespace op +} // namespace ov From e7c1344d3c390ae3dd1e827de18a0b76be15e3a5 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Fri, 22 Sep 2023 09:57:02 +0200 Subject: [PATCH 16/43] [core] Api 2.0/migrate Add operator to new API (#19984) * Migrate Add operator to new API * Remove `visit_attributes` as it calls base impl * Use shape inference to calculate broadcast shape --- src/core/include/openvino/op/add.hpp | 5 - .../include/openvino/reference/add.hpp | 27 ++-- src/core/shape_inference/CMakeLists.txt | 3 +- src/core/shape_inference/include/utils.hpp | 11 ++ src/core/shape_inference/src/utils.cpp | 16 +++ src/core/src/op/add.cpp | 132 +++++++----------- src/core/src/op/mod.cpp | 4 +- src/core/src/op/xor.cpp | 13 +- src/core/tests/pass/constant_folding.cpp | 2 +- 9 files changed, 107 insertions(+), 106 deletions(-) create mode 100644 src/core/shape_inference/src/utils.cpp diff --git a/src/core/include/openvino/op/add.hpp b/src/core/include/openvino/op/add.hpp index 054ec3302d846c..0a83c97f131295 100644 --- a/src/core/include/openvino/op/add.hpp +++ b/src/core/include/openvino/op/add.hpp @@ -38,11 +38,6 @@ class OPENVINO_API Add : public util::BinaryElementwiseArithmetic { std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; diff --git a/src/core/reference/include/openvino/reference/add.hpp b/src/core/reference/include/openvino/reference/add.hpp index 85357de726d192..4b097ec2bb2e41 100644 --- a/src/core/reference/include/openvino/reference/add.hpp +++ b/src/core/reference/include/openvino/reference/add.hpp @@ -4,30 +4,37 @@ #pragma once +#include #include -#include "ngraph/shape_util.hpp" #include "openvino/reference/autobroadcast_binop.hpp" namespace ov { namespace reference { -template -void add(const T* arg0, const T* arg1, T* out, size_t count) { - for (size_t i = 0; i < count; i++) { - out[i] = arg0[i] + arg1[i]; - } + +template +void add(const T* arg0, const T* arg1, T* out, const size_t count) { + std::transform(arg0, std::next(arg0, count), arg1, out, std::plus()); } -template +/** + * @brief Reference implementation of binary elementwise Add operator. + * + * @param arg0 Pointer to input 0 data. + * @param arg1 Pointer to input 1 data. + * @param out Pointer to output data. + * @param arg_shape0 Input 0 shape. + * @param arg_shape1 Input 1 shape. + * @param broadcast_spec Broadcast specification mode. + */ +template void add(const T* arg0, const T* arg1, T* out, const Shape& arg0_shape, const Shape& arg1_shape, const op::AutoBroadcastSpec& broadcast_spec) { - autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> T { - return x + y; - }); + autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, std::plus()); } } // namespace reference } // namespace ov diff --git a/src/core/shape_inference/CMakeLists.txt b/src/core/shape_inference/CMakeLists.txt index 611d118dd31952..b04f0cf8573b85 100644 --- a/src/core/shape_inference/CMakeLists.txt +++ b/src/core/shape_inference/CMakeLists.txt @@ -23,7 +23,8 @@ set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME shape_inference) target_include_directories(${TARGET_NAME} PUBLIC $ - $) + $ + $>) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) diff --git a/src/core/shape_inference/include/utils.hpp b/src/core/shape_inference/include/utils.hpp index 9815f5d1bf0876..7a1193f3a25a10 100644 --- a/src/core/shape_inference/include/utils.hpp +++ b/src/core/shape_inference/include/utils.hpp @@ -411,6 +411,17 @@ ov::optional get_input_bounds(const ov::Node* op, size_t port, const IT } return out; } + +/** + * @brief Inference broadcast shape for element wise operator according to broadcast specification stored in operator. + * + * @param op Pointer to operator. + * @param first First input shape. + * @param second Second input shape. + * + * @return Result shape from inputs with applied broadcast specification. + */ +ov::Shape infer_broadcast_shape(const ov::Node* const op, const ov::Shape& first, const ov::Shape& second); } // namespace op /** diff --git a/src/core/shape_inference/src/utils.cpp b/src/core/shape_inference/src/utils.cpp new file mode 100644 index 00000000000000..c89221d286ac69 --- /dev/null +++ b/src/core/shape_inference/src/utils.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "utils.hpp" + +#include "eltwise_shape_inference.hpp" + +namespace ov { +namespace op { + +ov::Shape infer_broadcast_shape(const ov::Node* const op, const ov::Shape& first, const ov::Shape& second) { + return eltwise_shape_infer(op, std::vector{first, second}).front().to_shape(); +} +} // namespace op +} // namespace ov diff --git a/src/core/src/op/add.cpp b/src/core/src/op/add.cpp index 8be44457dc3b91..316f71b3ebca7c 100644 --- a/src/core/src/op/add.cpp +++ b/src/core/src/op/add.cpp @@ -2,111 +2,83 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/add.hpp" +#include "openvino/op/add.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/runtime/host_tensor.hpp" #include "openvino/reference/add.hpp" +#include "utils.hpp" -using namespace std; -using namespace ngraph; - -OPENVINO_SUPPRESS_DEPRECATED_START +namespace ov { +namespace op { namespace add { -namespace { -template -bool evaluate(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - ov::reference::add(arg0->get_data_ptr(), - arg1->get_data_ptr(), - out->get_data_ptr(), - arg0->get_shape(), - arg1->get_shape(), - broadcast_spec); - return true; -} +struct Evaluate : element::NoAction { + using ov::element::NoAction::visit; -bool evaluate_add(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const op::AutoBroadcastSpec& broadcast_spec) { - bool rc = true; - out->set_broadcast(broadcast_spec, arg0, arg1); - switch (arg0->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_add, i8, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, i16, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, i32, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, i64, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, u8, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, u16, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, u32, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, u64, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, bf16, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, f16, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_add, f32, arg0, arg1, out, broadcast_spec); - default: - rc = false; - break; + template + static result_type visit(const Tensor& in0, + const Tensor& in1, + Tensor& out, + const AutoBroadcastSpec& broadcast_spec) { + using T = typename element_type_traits::value_type; + reference::add(in0.data(), + in1.data(), + out.data(), + in0.get_shape(), + in1.get_shape(), + broadcast_spec); + return true; } - return rc; -} -} // namespace +}; } // namespace add // ------------------------------- v1 ------------------------------------------ - -op::v1::Add::Add(const Output& arg0, const Output& arg1, const AutoBroadcastSpec& auto_broadcast) +namespace v1 { +Add::Add(const Output& arg0, const Output& arg1, const AutoBroadcastSpec& auto_broadcast) : BinaryElementwiseArithmetic(arg0, arg1, auto_broadcast) { constructor_validate_and_infer_types(); } -bool op::v1::Add::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_Add_visit_attributes); - BinaryElementwiseArithmetic::visit_attributes(visitor); - return true; -} - -shared_ptr op::v1::Add::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Add::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_Add_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); + return std::make_shared(new_args.at(0), new_args.at(1), this->get_autob()); } -bool op::v1::Add::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool Add::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const { OV_OP_SCOPE(v1_Add_evaluate); - return add::evaluate_add(inputs[0], inputs[1], outputs[0], get_autob()); -} + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); -bool op::v1::Add::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const { - OV_OP_SCOPE(v1_Add_evaluate); - if (std::none_of(inputs.cbegin(), inputs.cend(), [](const ov::Tensor& t) { - return is_vector(t.get_shape()) && t.get_shape().front() == 0; - })) { - return BinaryElementwiseArithmetic::evaluate(outputs, inputs); - } else { - return true; - } + outputs[0].set_shape(infer_broadcast_shape(this, inputs[0].get_shape(), inputs[1].get_shape())); + using namespace ov::element; + return IfTypeOf::apply( + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + get_autob()); } -bool op::v1::Add::has_evaluate() const { +bool Add::has_evaluate() const { OV_OP_SCOPE(v1_Add_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::i8: - case ngraph::element::i16: - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u8: - case ngraph::element::u16: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::bf16: - case ngraph::element::f16: - case ngraph::element::f32: + case element::i8: + case element::i16: + case element::i32: + case element::i64: + case element::u8: + case element::u16: + case element::u32: + case element::u64: + case element::bf16: + case element::f16: + case element::f32: return true; default: - break; + return false; } - return false; } +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/mod.cpp b/src/core/src/op/mod.cpp index 00c245514917e1..6bb45da04004cb 100644 --- a/src/core/src/op/mod.cpp +++ b/src/core/src/op/mod.cpp @@ -7,7 +7,7 @@ #include "element_visitor.hpp" #include "itt.hpp" #include "openvino/reference/mod.hpp" -#include "shape_util.hpp" +#include "utils.hpp" namespace ov { namespace op { @@ -49,7 +49,7 @@ bool Mod::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) co OPENVINO_ASSERT(outputs.size() == 1); OPENVINO_ASSERT(inputs.size() == 2); - outputs[0].set_shape(ov::util::get_broadcast_shape(inputs[0].get_shape(), inputs[1].get_shape(), get_autob())); + outputs[0].set_shape(infer_broadcast_shape(this, inputs[0].get_shape(), inputs[1].get_shape())); using namespace ov::element; return IfTypeOf::apply(inputs[0].get_element_type(), inputs[0], diff --git a/src/core/src/op/xor.cpp b/src/core/src/op/xor.cpp index 8a3b9c9e2c4303..a571e47618e9d1 100644 --- a/src/core/src/op/xor.cpp +++ b/src/core/src/op/xor.cpp @@ -8,7 +8,7 @@ #include "itt.hpp" #include "openvino/op/logical_xor.hpp" #include "openvino/reference/xor.hpp" -#include "shape_util.hpp" +#include "utils.hpp" namespace ov { namespace op { @@ -37,18 +37,17 @@ bool input_supported_type(const element::Type& et) { return et == element::boolean; } -bool evaluate(TensorVector& outputs, const TensorVector& inputs, const AutoBroadcastSpec& broadcast_spec) { +bool evaluate(const Node* const op, TensorVector& outputs, const TensorVector& inputs) { OPENVINO_ASSERT(outputs.size() == 1); OPENVINO_ASSERT(inputs.size() == 2); - outputs[0].set_shape(ov::util::get_broadcast_shape(inputs[0].get_shape(), inputs[1].get_shape(), broadcast_spec)); - + outputs[0].set_shape(infer_broadcast_shape(op, inputs[0].get_shape(), inputs[1].get_shape())); using namespace ov::element; return IfTypeOf::apply(inputs[0].get_element_type(), inputs[0], inputs[1], outputs[0], - broadcast_spec); + op->get_autob()); } } // namespace } // namespace logxor @@ -68,7 +67,7 @@ std::shared_ptr Xor::clone_with_new_inputs(const OutputVector& new_args) c bool Xor::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v0_Xor_evaluate); - return logxor::evaluate(outputs, inputs, get_autob()); + return logxor::evaluate(this, outputs, inputs); } bool Xor::has_evaluate() const { @@ -92,7 +91,7 @@ std::shared_ptr LogicalXor::clone_with_new_inputs(const OutputVector& new_ bool LogicalXor::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalXor_evaluate); - return logxor::evaluate(outputs, inputs, get_autob()); + return logxor::evaluate(this, outputs, inputs); } bool LogicalXor::has_evaluate() const { diff --git a/src/core/tests/pass/constant_folding.cpp b/src/core/tests/pass/constant_folding.cpp index 672f272d794514..005d5c4b8bfea0 100644 --- a/src/core/tests/pass/constant_folding.cpp +++ b/src/core/tests/pass/constant_folding.cpp @@ -3847,7 +3847,7 @@ class MockAddOp : public ov::op::v1::Add { const ov::op::AutoBroadcastSpec& auto_broadcast = ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY)) : ov::op::v1::Add(arg0, arg1, auto_broadcast) { ON_CALL(*this, evaluate).WillByDefault([this](ov::TensorVector& outputs, const ov::TensorVector& inputs) { - return ov::Node::evaluate(outputs, inputs); + return ov::op::v1::Add::evaluate(outputs, inputs); }); } MOCK_METHOD(bool, From 2151e5f9790f8158033b5ff2948db98b8d7f9b92 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Fri, 22 Sep 2023 10:34:07 +0200 Subject: [PATCH 17/43] [PT FE] Add tests for timm models (#19997) * Add tests for timm models * Apply suggestions from code review * Some improvements * Update tests/model_hub_tests/torch_tests/test_transformers.py --- .../models_hub_common/constants.py | 6 ++ .../models_hub_common/utils.py | 15 +++++ .../torch_tests/hf_transformers_models | 12 ++-- .../model_hub_tests/torch_tests/test_timm.py | 67 +++++++++++++++++++ .../torch_tests/test_transformers.py | 22 +++--- 5 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 tests/model_hub_tests/torch_tests/test_timm.py diff --git a/tests/model_hub_tests/models_hub_common/constants.py b/tests/model_hub_tests/models_hub_common/constants.py index a4c5934d5ea49b..6fc8a7ec6215a2 100644 --- a/tests/model_hub_tests/models_hub_common/constants.py +++ b/tests/model_hub_tests/models_hub_common/constants.py @@ -11,5 +11,11 @@ tf_hub_cache_dir = os.path.join(tempfile.gettempdir(), "tfhub_modules") os.environ['TFHUB_CACHE_DIR'] = tf_hub_cache_dir +if os.environ.get('HUGGINGFACE_HUB_CACHE') is not None: + hf_hub_cache_dir = os.environ['HUGGINGFACE_HUB_CACHE'] +else: + hf_hub_cache_dir = tempfile.gettempdir() + os.environ['HUGGINGFACE_HUB_CACHE'] = hf_hub_cache_dir + # supported_devices : CPU, GPU, GNA test_device = os.environ.get('TEST_DEVICE', 'CPU;GPU').split(';') diff --git a/tests/model_hub_tests/models_hub_common/utils.py b/tests/model_hub_tests/models_hub_common/utils.py index 076cd8e2f1e4c0..948ebfa14fb391 100644 --- a/tests/model_hub_tests/models_hub_common/utils.py +++ b/tests/model_hub_tests/models_hub_common/utils.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import os +import shutil import itertools import numpy as np @@ -47,3 +49,16 @@ def get_params(ie_device=None): for element in itertools.product(ie_device_params): test_args.append(element) return test_args + + +def cleanup_dir(dir: str): + # remove all downloaded files from cache + for file_name in os.listdir(dir): + file_path = os.path.join(dir, file_name) + try: + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception as e: + pass diff --git a/tests/model_hub_tests/torch_tests/hf_transformers_models b/tests/model_hub_tests/torch_tests/hf_transformers_models index 051de563ac171b..2f69f6adbcf405 100644 --- a/tests/model_hub_tests/torch_tests/hf_transformers_models +++ b/tests/model_hub_tests/torch_tests/hf_transformers_models @@ -3,7 +3,7 @@ abcp4/mymodel-test,mymodel,skip,Load problem abeja/gpt-neox-japanese-2.7b,gpt_neox_japanese acl-submission-anonym/EAM-spectral,examuse,skip,Load problem adalbertojunior/modular-test,modular,skip,Load problem -aerner/lm-v2,open-llama,skip,Load problem +aerner/lm-v2,open-llama,skip,Load problem: maximum recursion depth exceeded while calling a Python object afonsosamarques/ardt-vanilla-combo_train_hopper_v2-2508_1336-33,decision_transformer,skip,Load problem aihijo/gec-zh-gector-bert-large,gector,skip,Load problem albert-base-v2,albert @@ -72,7 +72,7 @@ facebook/esm2_t6_8M_UR50D,esm,xfail,Tracing error: The values for attribute 'sha facebook/flava-full,flava,skip,Load problem facebook/flava-image-codebook,flava_image_codebook,skip,Load problem facebook/m2m100_418M,m2m_100 -facebook/mask2former-swin-base-coco-panoptic,mask2former,skip,Load problem +facebook/mask2former-swin-base-coco-panoptic,mask2former,xfail,Accuracy validation failed facebook/maskformer-swin-base-coco,maskformer facebook/mms-tts-eng,vits,skip,Load problem facebook/musicgen-small,musicgen,skip,Load problem @@ -92,7 +92,7 @@ fusing/latent-diffusion-text2im-large,ldmbert,skip,Load problem Geor111y/flair-ner-addresses-extractor,flair,skip,Load problem gia-project/gia,gia,skip,Load problem gokuls/bert_12_layer_model_v1,hybridbert,skip,Load problem -google/bigbird-roberta-base,big_bird,skip,Load problem +google/bigbird-roberta-base,big_bird google/bit-50,bit google/canine-s,canine,xfail,aten::slice: Parameter axis 3 out of the tensor rank range google/efficientnet-b2,efficientnet,xfail,Compile error: AvgPool: Kernel after dilation has size (dim: 1408) larger than the data shape after padding (dim: 9) at axis 0. @@ -127,10 +127,10 @@ hf-internal-testing/tiny-random-DonutSwinModel,donut-swin,xfail,Unsupported op a hf-internal-testing/tiny-random-EfficientFormerForImageClassification,efficientformer hf-internal-testing/tiny-random-flaubert,flaubert hf-internal-testing/tiny-random-FocalNetModel,focalnet,xfail,Unsupported op aten::adaptive_avg_pool1d -hf-internal-testing/tiny-random-GPTBigCodeForCausalLM,gpt_bigcode,skip,Load problem +hf-internal-testing/tiny-random-GPTBigCodeForCausalLM,gpt_bigcode,xfail,Conversion is failed for: aten::mul hf-internal-testing/tiny-random-GPTJModel,gptj hf-internal-testing/tiny-random-groupvit,groupvit -hf-internal-testing/tiny-random-IBertModel,ibert,skip,Load problem +hf-internal-testing/tiny-random-IBertModel,ibert hf-internal-testing/tiny-random-ImageGPTModel,imagegpt hf-internal-testing/tiny-random-LevitModel,levit,skip,Load problem hf-internal-testing/tiny-random-LiltModel,lilt,skip,Load problem @@ -309,7 +309,7 @@ regisss/bridgetower-newyorker-a100-8x,bridgetower rinna/japanese-cloob-vit-b-16,cloob,skip,Load problem Rocketknight1/tiny-random-falcon-7b,falcon,skip,Load problem RUCAIBox/mass-base-uncased,mass,skip,Load problem -RWKV/rwkv-4-169m-pile,rwkv,skip,Load problem +RWKV/rwkv-4-169m-pile,rwkv,xfail,Unsupported op aten::maximum sahasrarjn/interbert,BERT,skip,Load problem saibo/genkalm-medium-gpt2,genkalm,skip,Load problem SajjadAyoubi/clip-fa-vision,clip_vision_model diff --git a/tests/model_hub_tests/torch_tests/test_timm.py b/tests/model_hub_tests/torch_tests/test_timm.py new file mode 100644 index 00000000000000..4294000740759c --- /dev/null +++ b/tests/model_hub_tests/torch_tests/test_timm.py @@ -0,0 +1,67 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import timm +import torch +import pytest +from models_hub_common.test_convert_model import TestConvertModel +from models_hub_common.constants import hf_hub_cache_dir +from models_hub_common.utils import cleanup_dir +from openvino import convert_model + + +def get_all_models() -> list: + m_list = timm.list_pretrained() + return m_list + + +# To make tests reproducible we seed the random generator +torch.manual_seed(0) + + +class TestTimmConvertModel(TestConvertModel): + def load_model(self, model_name, model_link): + m = timm.create_model(model_name, pretrained=True) + cfg = timm.get_pretrained_cfg(model_name) + shape = [1] + list(cfg.input_size) + self.example = (torch.randn(shape),) + self.inputs = (torch.randn(shape),) + return m + + def get_inputs_info(self, model_obj): + return None + + def prepare_inputs(self, inputs_info): + return [i.numpy() for i in self.inputs] + + def convert_model(self, model_obj): + ov_model = convert_model(model_obj, example_input=self.example) + return ov_model + + def infer_fw_model(self, model_obj, inputs): + fw_outputs = model_obj(*[torch.from_numpy(i) for i in inputs]) + if isinstance(fw_outputs, dict): + for k in fw_outputs.keys(): + fw_outputs[k] = fw_outputs[k].numpy(force=True) + elif isinstance(fw_outputs, (list, tuple)): + fw_outputs = [o.numpy(force=True) for o in fw_outputs] + else: + fw_outputs = [fw_outputs.numpy(force=True)] + return fw_outputs + + def teardown_method(self): + # remove all downloaded files from cache + cleanup_dir(hf_hub_cache_dir) + super().teardown_method() + + @pytest.mark.parametrize("name", ["mobilevitv2_050.cvnets_in1k", + "poolformerv2_s12.sail_in1k", + "vit_base_patch8_224.augreg_in21k"]) + @pytest.mark.precommit + def test_convert_model_precommit(self, name, ie_device): + self.run(name, None, ie_device) + + @pytest.mark.parametrize("name", get_all_models()) + @pytest.mark.nightly + def test_convert_model_all_models(self, name, ie_device): + self.run(name, None, ie_device) diff --git a/tests/model_hub_tests/torch_tests/test_transformers.py b/tests/model_hub_tests/torch_tests/test_transformers.py index 1df75b455026ec..b6f7e9239a9c0f 100644 --- a/tests/model_hub_tests/torch_tests/test_transformers.py +++ b/tests/model_hub_tests/torch_tests/test_transformers.py @@ -1,14 +1,14 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import pytest import os +import pytest import torch -import tempfile from huggingface_hub import model_info from models_hub_common.test_convert_model import TestConvertModel from openvino import convert_model -from models_hub_common.utils import get_models_list +from models_hub_common.utils import get_models_list, cleanup_dir +from models_hub_common.constants import hf_hub_cache_dir def flattenize_tuples(list_input): @@ -37,15 +37,10 @@ class TestTransformersModel(TestConvertModel): def setup_class(self): from PIL import Image import requests - import os url = "http://images.cocodataset.org/val2017/000000039769.jpg" self.image = Image.open(requests.get(url, stream=True).raw) - self.cache_dir = tempfile.TemporaryDirectory() - print(f"Setting temp cache dir: {str(self.cache_dir)}") - os.environ["HUGGINGFACE_HUB_CACHE"] = str(self.cache_dir) - def load_model(self, name, type): mi = model_info(name) auto_processor = None @@ -243,6 +238,12 @@ def forward(self, x): from transformers import AutoModel model = AutoModel.from_pretrained(name, torchscript=True) self.example = example + model.eval() + # do first inference + if isinstance(example, dict): + model(**example) + else: + model(*example) return model def get_inputs_info(self, model_obj): @@ -267,9 +268,8 @@ def infer_fw_model(self, model_obj, inputs): return flattenize_outputs(fw_outputs) def teardown_method(self): - # cleanup tmpdir - print(f"Cleaning temp cache dir: {str(self.cache_dir)}") - self.cache_dir.cleanup() + # remove all downloaded files from cache + cleanup_dir(hf_hub_cache_dir) super().teardown_method() @pytest.mark.parametrize("name,type", [("bert-base-uncased", "bert"), From 26d18c924b36bfaec169dffc85d5b35c58b666e7 Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Fri, 22 Sep 2023 13:54:44 +0400 Subject: [PATCH 18/43] [PT FE]: support aten::broadcast_tensors (#19994) * broadcast tensors * [PT FE]: support aten::broadcast_tensors * apply review comments * remove add --- .../transforms/prim_list_unpack_replacer.cpp | 23 ++++++++++ .../pytorch_tests/test_broadcast_tensors.py | 45 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/layer_tests/pytorch_tests/test_broadcast_tensors.py diff --git a/src/frontends/pytorch/src/transforms/prim_list_unpack_replacer.cpp b/src/frontends/pytorch/src/transforms/prim_list_unpack_replacer.cpp index 312ed1457c985d..e5fa463af31d00 100644 --- a/src/frontends/pytorch/src/transforms/prim_list_unpack_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/prim_list_unpack_replacer.cpp @@ -173,6 +173,29 @@ PrimListUnpackReplacer::PrimListUnpackReplacer() { } } + if (auto broadcast_tensors = cast_fw_node(input_node, "aten::broadcast_tensors")) { + auto tensors = cast_fw_node(broadcast_tensors->input_value(0).get_node_shared_ptr(), "prim::ListConstruct"); + if (!tensors) { + add_exception_to_fw_node(input_node, + "aten::broadcast_tensors: only prim::ListConstruct supported as input."); + return false; + } + Output final_shape_t = opset10::Constant::create(element::i32, Shape{}, {0}); + for (auto input : tensors->inputs()) { + auto tensor_shape = rg.make(input.get_source_output(), element::i32); + final_shape_t = + rg.make(final_shape_t, tensor_shape, ov::op::BroadcastType::BIDIRECTIONAL); + } + auto final_shape = rg.make(final_shape_t, element::i32); + OutputVector outputs; + for (auto input : tensors->inputs()) { + outputs.push_back(rg.make(input.get_source_output(), final_shape)); + } + copy_runtime_info_and_name(list_unpack, rg.get(), {input_node}); + replace_node(list_unpack, outputs); + return true; + } + if (auto unbind = cast_fw_node(input_node, "aten::unbind")) { const auto input = unbind->get_input_source_output(0); const auto axis = unbind->get_input_source_output(1); diff --git a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py new file mode 100644 index 00000000000000..b405f0114b5a4b --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py @@ -0,0 +1,45 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestBroadcastTensors(PytorchLayerTest): + def _prepare_input(self, x_shape, y_shape, z_shape, x_dtype, y_dtype, z_dtype): + import numpy as np + return ( + np.random.randn(*x_shape).astype(x_dtype), + np.random.randn(*y_shape).astype(y_dtype), + np.random.randn(*z_shape).astype(z_dtype)) + + def create_model(self): + import torch + + class aten_broadcast_tensors(torch.nn.Module): + def __init__(self): + super(aten_broadcast_tensors, self).__init__() + + def forward(self, x, y, z): + x1, y1, z1 = torch.broadcast_tensors(x, y, z) + return x1, y1, z1 + + ref_net = None + + return aten_broadcast_tensors(), ref_net, ("prim::ListConstruct", "aten::broadcast_tensors", "prim::ListUnpack") + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("x_shape", [[1, ], [2, 1], [2, 2, 1]]) + @pytest.mark.parametrize("y_shape", [[2, ], [1, 2], [1, 2, 1]]) + @pytest.mark.parametrize("z_shape", [[1, 2], [2, 2], [1, 2, 1, 1]]) + @pytest.mark.parametrize("x_dtype", ["float32", "int32"]) + @pytest.mark.parametrize("y_dtype", ["float32", "int32"]) + @pytest.mark.parametrize("z_dtype", ["float32", "int32"]) + def test_broadcast_tensors(self, x_shape, y_shape, z_shape, x_dtype, y_dtype, z_dtype, ie_device, precision, ir_version): + self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={ + "x_shape": x_shape, "x_dtype": x_dtype, + "y_shape": y_shape, "y_dtype": y_dtype, + "z_shape": z_shape, "z_dtype": z_dtype, + }) From c1271d1217ae515f9ac731f97bd5429e255667d2 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Fri, 22 Sep 2023 12:12:28 +0200 Subject: [PATCH 19/43] Refactor EmbeddingBagOffsetsSumLayerTest, EmbeddingBagPackedSumLayerTest, EmbeddingSegmentsSumLayerTest (#19952) * Refactor EmbeddingBagOffsetsSumLayerTest * Refactor EmbeddingBagPackedSumLayerTest * Refactor EmbeddingSegmentsSumLayerTest --- .../embedding_bag_offsets_sum.cpp | 31 ++++---- .../embedding_bag_packed_sum.cpp | 31 ++++---- .../embedding_segments_sum.cpp | 34 +++++---- .../embedding_bag_offsets_sum.hpp | 15 ++++ .../embedding_bag_packed_sum.hpp | 15 ++++ .../embedding_segments_sum.hpp | 15 ++++ .../single_op/embedding_bag_offsets_sum.hpp | 39 ++++++++++ .../single_op/embedding_bag_packed_sum.hpp | 36 +++++++++ .../single_op/embedding_segments_sum.hpp | 40 ++++++++++ .../single_op/embedding_bag_offsets_sum.cpp | 65 ++++++++++++++++ .../single_op/embedding_bag_packed_sum.cpp | 59 ++++++++++++++ .../src/single_op/embedding_segments_sum.cpp | 76 +++++++++++++++++++ 12 files changed, 412 insertions(+), 44 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_offsets_sum.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_packed_sum.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/embedding_segments_sum.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_offsets_sum.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_packed_sum.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_segments_sum.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/embedding_bag_packed_sum.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_offsets_sum.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_offsets_sum.cpp index 901e58f7ef1c9a..1b3d8d708a84f8 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_offsets_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_offsets_sum.cpp @@ -4,25 +4,28 @@ #include -#include "single_layer_tests/embedding_bag_offsets_sum.hpp" +#include "single_op_tests/embedding_bag_offsets_sum.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::EmbeddingBagOffsetsSumLayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U8 +const std::vector model_type = { + ov::element::f32, + ov::element::i32, + ov::element::u8 }; -const std::vector indPrecisions = { - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32 +const std::vector ind_type = { + ov::element::i64, + ov::element::i32 }; -const std::vector> emb_table_shape = {{5, 6}, {10, 35}, {5, 4, 16}}; +const std::vector> input_shapes_static = { + {{5, 6}}, + {{10, 35}}, + {{5, 4, 16}}}; + const std::vector> indices = {{0, 1, 2, 2, 3}, {4, 4, 3, 1, 0}, {1, 2, 1, 2, 1, 2, 1, 2, 1, 2}}; const std::vector> offsets = {{0, 2}, {0, 0, 2, 2}, {2, 4}}; @@ -31,7 +34,6 @@ const std::vector with_weights = {false, true}; const std::vector with_default_index = {false, true}; const auto embBagOffsetSumArgSet = ::testing::Combine( - ::testing::ValuesIn(emb_table_shape), ::testing::ValuesIn(indices), ::testing::ValuesIn(offsets), ::testing::ValuesIn(default_index), @@ -42,8 +44,9 @@ const auto embBagOffsetSumArgSet = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke, EmbeddingBagOffsetsSumLayerTest, ::testing::Combine( embBagOffsetSumArgSet, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(indPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(model_type), + ::testing::ValuesIn(ind_type), ::testing::Values(ov::test::utils::DEVICE_CPU)), EmbeddingBagOffsetsSumLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_packed_sum.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_packed_sum.cpp index 681b37e9a7ad24..5d546c05d7c4df 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_packed_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_bag_packed_sum.cpp @@ -4,31 +4,33 @@ #include -#include "single_layer_tests/embedding_bag_packed_sum.hpp" +#include "single_op_tests/embedding_bag_packed_sum.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::EmbeddingBagPackedSumLayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U8 +const std::vector model_type = { + ov::element::f32, + ov::element::i32, + ov::element::u8 }; -const std::vector indPrecisions = { - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32 +const std::vector ind_type = { + ov::element::i64, + ov::element::i32 }; -const std::vector> emb_table_shape = {{5, 6}, {10, 35}, {5, 4, 16}}; +const std::vector> input_shapes_static = + {{{5, 6}}, + {{10, 35}}, + {{5, 4, 16}}}; + const std::vector>> indices = {{{0, 1}, {2, 2}, {3, 4}}, {{4, 4, 3}, {1, 0, 2}}, {{1, 2, 1, 2}, {1, 2, 1, 2}}}; const std::vector with_weights = {false, true}; const auto embBagPackedSumArgSet = ::testing::Combine( - ::testing::ValuesIn(emb_table_shape), ::testing::ValuesIn(indices), ::testing::ValuesIn(with_weights) ); @@ -36,8 +38,9 @@ const auto embBagPackedSumArgSet = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke, EmbeddingBagPackedSumLayerTest, ::testing::Combine( embBagPackedSumArgSet, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(indPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(model_type), + ::testing::ValuesIn(ind_type), ::testing::Values(ov::test::utils::DEVICE_CPU)), EmbeddingBagPackedSumLayerTest::getTestCaseName); } // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_segments_sum.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_segments_sum.cpp index 8f3aa7ee3d2534..f97c316514058b 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_segments_sum.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/embedding_segments_sum.cpp @@ -4,27 +4,29 @@ #include -#include "single_layer_tests/embedding_segments_sum.hpp" +#include "single_op_tests/embedding_segments_sum.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::EmbeddingSegmentsSumLayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::U8 +const std::vector model_type = { + ov::element::f32, + ov::element::i32, + ov::element::u8 }; -const std::vector indPrecisions = { - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I32 +const std::vector ind_type = { + ov::element::i64, + ov::element::i32 }; -const std::vector> emb_table_shape = {{5, 6}, {10, 35}, {5, 4, 16}}; -const std::vector> indices = - {{0, 1, 2, 2, 3}, {4, 4, 3, 1, 2}}; +const std::vector> input_shapes_static = + {{{5, 6}}, + {{10, 35}}, + {{5, 4, 16}}}; + +const std::vector> indices = {{0, 1, 2, 2, 3}, {4, 4, 3, 1, 2}}; const std::vector> segment_ids = {{0, 1, 2, 3, 4}, {0, 0, 2, 2, 4}}; const std::vector num_segments = {5, 7}; const std::vector default_index = {0, 4}; @@ -32,7 +34,6 @@ const std::vector with_weights = {false, true}; const std::vector with_default_index = {false, true}; const auto embSegmentsSumArgSet = ::testing::Combine( - ::testing::ValuesIn(emb_table_shape), ::testing::ValuesIn(indices), ::testing::ValuesIn(segment_ids), ::testing::ValuesIn(num_segments), @@ -44,8 +45,9 @@ const auto embSegmentsSumArgSet = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke, EmbeddingSegmentsSumLayerTest, ::testing::Combine( embSegmentsSumArgSet, - ::testing::ValuesIn(netPrecisions), - ::testing::ValuesIn(indPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(model_type), + ::testing::ValuesIn(ind_type), ::testing::Values(ov::test::utils::DEVICE_CPU)), EmbeddingSegmentsSumLayerTest::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_offsets_sum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_offsets_sum.hpp new file mode 100644 index 00000000000000..c8e49b446748b3 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_offsets_sum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/embedding_bag_offsets_sum.hpp" + +namespace ov { +namespace test { +TEST_P(EmbeddingBagOffsetsSumLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_packed_sum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_packed_sum.hpp new file mode 100644 index 00000000000000..8d47cdbd9f8b81 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_bag_packed_sum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/embedding_bag_packed_sum.hpp" + +namespace ov { +namespace test { +TEST_P(EmbeddingBagPackedSumLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/embedding_segments_sum.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_segments_sum.hpp new file mode 100644 index 00000000000000..89c448a7da4655 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/embedding_segments_sum.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/embedding_segments_sum.hpp" + +namespace ov { +namespace test { +TEST_P(EmbeddingSegmentsSumLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_offsets_sum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_offsets_sum.hpp new file mode 100644 index 00000000000000..42ad1760064b6e --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_offsets_sum.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // indices + std::vector, // offsets + size_t, // default_index + bool, // with_weights + bool // with_def_index +> embeddingBagOffsetsSumParams; + +typedef std::tuple< + embeddingBagOffsetsSumParams, + std::vector, // shapes + ov::element::Type, // model type + ov::element::Type, // indices type + std::string> embeddingBagOffsetsSumLayerTestParamsSet; + +class EmbeddingBagOffsetsSumLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_packed_sum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_packed_sum.hpp new file mode 100644 index 00000000000000..46adfcbca10474 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_bag_packed_sum.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector>, // indices + bool // with_weights +> embeddingBagPackedSumParams; + +typedef std::tuple< + embeddingBagPackedSumParams, + std::vector, // input shapes + ov::element::Type, // embedding table + ov::element::Type, // indices + std::string> embeddingBagPackedSumLayerTestParamsSet; + +class EmbeddingBagPackedSumLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_segments_sum.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_segments_sum.hpp new file mode 100644 index 00000000000000..6f48a07cf689df --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/embedding_segments_sum.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // indices + std::vector, // segment_ids + size_t, // num_segments + size_t, // default_index + bool, // with_weights + bool // with_def_index +> embeddingSegmentsSumParams; + +typedef std::tuple< + embeddingSegmentsSumParams, + std::vector, // input shapes + ov::element::Type, // embedding table + ov::element::Type, // indices + std::string> embeddingSegmentsSumLayerTestParamsSet; + +class EmbeddingSegmentsSumLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp new file mode 100644 index 00000000000000..ef1542e2a2bd23 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_offsets_sum.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/embedding_bag_offsets_sum.hpp" +#include "ngraph_functions/builders.hpp" + +namespace ov { +namespace test { +std::string EmbeddingBagOffsetsSumLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + embeddingBagOffsetsSumParams emb_params; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::string target_device; + std::tie(emb_params, shapes, model_type, ind_type, target_device) = obj.param; + std::vector indices, offsets; + size_t default_index; + bool with_weights, with_def_index; + std::tie(indices, offsets, default_index, with_weights, with_def_index) = emb_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "I" << ov::test::utils::vec2str(indices) << "_"; + result << "O" << ov::test::utils::vec2str(offsets) << "_"; + result << "DI" << default_index << "_"; + result << "WW" << with_weights << "_"; + result << "WDI" << with_def_index << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "indPRC=" << ind_type.get_type_name() << "_"; + result << "targetDevice=" << target_device; + return result.str(); +} + +void EmbeddingBagOffsetsSumLayerTest::SetUp() { + embeddingBagOffsetsSumParams emb_params; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::tie(emb_params, shapes, model_type, ind_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + std::vector indices, offsets; + bool with_weights, with_def_index; + size_t default_index; + std::tie(indices, offsets, default_index, with_weights, with_def_index) = emb_params; + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto embBag = ngraph::builder::makeEmbeddingBagOffsetsSum(model_type, ind_type, param, indices, offsets, default_index, with_weights, with_def_index); + + auto result = std::make_shared(embBag); + function = std::make_shared(result, ov::ParameterVector{param}, "embeddingBagOffsetsSum"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_packed_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_packed_sum.cpp new file mode 100644 index 00000000000000..788271a4f4aefc --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/embedding_bag_packed_sum.cpp @@ -0,0 +1,59 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/embedding_bag_packed_sum.hpp" +#include "ngraph_functions/builders.hpp" + +namespace ov { +namespace test { +std::string EmbeddingBagPackedSumLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + embeddingBagPackedSumParams emb_params; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::string target_device; + std::tie(emb_params, shapes, model_type, ind_type, target_device) = obj.param; + std::vector> indices; + bool with_weights; + std::tie(indices, with_weights) = emb_params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "I" << ov::test::utils::vec2str(indices) << "_"; + result << "WW" << with_weights << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "indPRC=" << ind_type.get_type_name() << "_"; + result << "targetDevice=" << target_device; + return result.str(); +} + +void EmbeddingBagPackedSumLayerTest::SetUp() { + embeddingBagPackedSumParams emb_params; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::tie(emb_params, shapes, model_type, ind_type, targetDevice) = this->GetParam(); + std::vector> indices; + bool with_weights; + std::tie(indices, with_weights) = emb_params; + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto embBag = ngraph::builder::makeEmbeddingBagPackedSum(model_type, ind_type, param, indices, with_weights); + + auto result = std::make_shared(embBag); + function = std::make_shared(result, ov::ParameterVector{param}, "embeddingBagPackedSum"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp b/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp new file mode 100644 index 00000000000000..71a80bd7082514 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/embedding_segments_sum.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/embedding_segments_sum.hpp" +#include "ngraph_functions/builders.hpp" + + +namespace ov { +namespace test { + +std::string EmbeddingSegmentsSumLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + embeddingSegmentsSumParams params; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::string target_device; + std::tie(params, shapes, model_type, ind_type, target_device) = obj.param; + std::vector indices, segment_ids; + size_t num_segments, default_index; + bool with_weights, with_def_index; + std::tie(indices, segment_ids, num_segments, default_index, with_weights, with_def_index) = params; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "I" << ov::test::utils::vec2str(indices) << "_"; + result << "SI" << ov::test::utils::vec2str(segment_ids) << "_"; + result << "NS" << num_segments << "_"; + result << "DI" << default_index << "_"; + result << "WW" << with_weights << "_"; + result << "WDI" << with_def_index << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "indPRC=" << ind_type.get_type_name() << "_"; + result << "targetDevice=" << target_device; + return result.str(); +} + +void EmbeddingSegmentsSumLayerTest::SetUp() { + embeddingSegmentsSumParams embParams; + ov::element::Type model_type, ind_type; + std::vector shapes; + std::tie(embParams, shapes, model_type, ind_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + std::vector indices, segment_ids; + bool with_weights, with_def_index; + size_t num_segments, default_index; + std::tie(indices, segment_ids, num_segments, default_index, with_weights, with_def_index) = embParams; + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto embBag = ngraph::builder::makeEmbeddingSegmentsSum(model_type, + ind_type, + param, + indices, + segment_ids, + num_segments, + default_index, + with_weights, + with_def_index); + + auto result = std::make_shared(embBag); + function = std::make_shared(result, ov::ParameterVector{param}, "embeddingSegmentsSum"); +} +} // namespace test +} // namespace ov From 9271b79540758aa2712c39b4782047a1e4ae6d03 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Fri, 22 Sep 2023 13:05:21 +0200 Subject: [PATCH 20/43] [OVC] do not parse inputs for py_api (#19742) * [OVC] do not parse inputs * fix unit-tests * remove redundant lines, add test case * add one more unit-test * skip None values * replace str with List in test_mo_import_from_memory * corrected type hints, added a safety assert --- .../src/openvino/frontend/tensorflow/utils.py | 18 +++++- .../ovc_python_api_tests/test_pytorch.py | 34 ++++++++++- .../ovc_python_api_tests/test_tf.py | 17 ++++++ tools/ovc/openvino/tools/ovc/cli_parser.py | 38 ++++++------ tools/ovc/openvino/tools/ovc/convert_impl.py | 15 +++-- .../moc_tf_fe/conversion_basic_models_test.py | 4 +- .../unit_tests/ovc/utils/cli_parser_test.py | 58 +++++++++++++------ 7 files changed, 139 insertions(+), 45 deletions(-) diff --git a/src/bindings/python/src/openvino/frontend/tensorflow/utils.py b/src/bindings/python/src/openvino/frontend/tensorflow/utils.py index f4ac5b0a121565..b75f371d0c16f2 100644 --- a/src/bindings/python/src/openvino/frontend/tensorflow/utils.py +++ b/src/bindings/python/src/openvino/frontend/tensorflow/utils.py @@ -6,9 +6,11 @@ import logging as log -import numpy as np import sys from distutils.version import LooseVersion +from typing import List, Dict, Union + +import numpy as np from openvino.runtime import PartialShape, Dimension @@ -264,10 +266,22 @@ def tf_function(args): input_needs_packing = True + def are_shapes_defined(shape: Union[List, Dict]): + if shape is None: + return False + assert hasattr(shape, '__len__') + if len(shape) == 0: + return False + + if isinstance(shape, list): + return np.all([shape is not None for shape in input_shapes]) + elif isinstance(shape, dict): + return np.all([shape is not None for name, shape in input_shapes.items()]) + if example_input is not None: concrete_func = get_concrete_func(tf_function, example_input, input_needs_packing, "Could not trace the TF model with the following error: {}") - elif input_shapes is not None: + elif are_shapes_defined(input_shapes): inp = create_example_input_by_user_shapes(input_shapes, input_types) concrete_func = get_concrete_func(tf_function, inp, input_needs_packing, "Could not trace the TF model with the following error: {}") diff --git a/tests/layer_tests/ovc_python_api_tests/test_pytorch.py b/tests/layer_tests/ovc_python_api_tests/test_pytorch.py index 268f69d13f025c..52d6669045928e 100644 --- a/tests/layer_tests/ovc_python_api_tests/test_pytorch.py +++ b/tests/layer_tests/ovc_python_api_tests/test_pytorch.py @@ -187,8 +187,7 @@ def create_pytorch_nn_module_case3(tmp_dir): sample_input1 = torch.zeros(1, 3, 10, 10) sample_input2 = torch.zeros(1, 3, 10, 10) sample_input = tuple([sample_input1, sample_input2]) - - return pt_model, ref_model, {'input': "[?,3,?,?],[?,3,?,?]", + return pt_model, ref_model, {'input': [[-1, 3, -1, -1], [-1, 3, -1, -1]], 'example_input': sample_input} @@ -1093,6 +1092,37 @@ def test_example_inputs(self): with self.assertRaisesRegex(TypeError, ".*got an unexpected keyword argument 'example_inputs'.*"): convert_model(pytorch_model, example_inputs=(torch.tensor(1),)) + def test_incorrect_inputs_1(self): + from openvino.tools.ovc import convert_model + pytorch_model, _, _ = create_pytorch_nn_module_case1('') + + with self.assertRaisesRegex(Exception, ".*No node with name.*"): + convert_model(pytorch_model, input='input1[1, 10]') + + def test_incorrect_inputs_2(self): + from openvino.tools.ovc import convert_model + pytorch_model, _, _ = create_pytorch_nn_module_case1('') + + # check that it accepts specified names as is, without parsing into 2 different inputs + with self.assertRaisesRegex(Exception, 'No node with name input1,input2'): + convert_model(pytorch_model, input='input1,input2') + + def test_incorrect_inputs_3(self): + from openvino.tools.ovc import convert_model + pytorch_model, _, _ = create_pytorch_nn_module_case1('') + + # check that it accepts specified names as is, without parsing into 2 different inputs + with self.assertRaisesRegex(Exception, 'No node with name input1\[1, 10\],input2\[2, 100\]'): + convert_model(pytorch_model, input='input1[1, 10],input2[2, 100]') + + def test_incorrect_inputs_4(self): + from openvino.tools.ovc import convert_model + pytorch_model, _, _ = create_pytorch_nn_module_case1('') + + # check that it accepts specified names as is, without parsing into 2 different inputs + with self.assertRaisesRegex(Exception, 'No node with name input1\[1, 10\]'): + convert_model(pytorch_model, input=['input1[1, 10]', 'input2[2, 100]']) + def test_failed_extension(self): from openvino.tools.ovc import convert_model from openvino.frontend.pytorch import ConversionExtension diff --git a/tests/layer_tests/ovc_python_api_tests/test_tf.py b/tests/layer_tests/ovc_python_api_tests/test_tf.py index a311666eb83bf3..e8c098ff9cae56 100644 --- a/tests/layer_tests/ovc_python_api_tests/test_tf.py +++ b/tests/layer_tests/ovc_python_api_tests/test_tf.py @@ -938,3 +938,20 @@ def simple_tf_model(): fe = fem.load_by_model(model) assert fe is not None assert fe.get_name() == "tf" + + +class TestTFConvertRaises(unittest.TestCase): + def test_incorrect_inputs_1(self): + from openvino.tools.ovc import convert_model + tf_model, _, _ = create_keras_model('') + + with self.assertRaisesRegex(Exception, ".*No node with name.*"): + convert_model(tf_model, input='Input1[1, 2, 3]') + + def test_incorrect_inputs_2(self): + from openvino.tools.ovc import convert_model + tf_model, _, _ = create_keras_model('') + + # check that it accepts specified names as is without parsing into 2 different inputs + with self.assertRaisesRegex(Exception, 'No node with name Input1\[1, 2, 3\],Input2\[1, 2, 3\]'): + convert_model(tf_model, input='Input1[1, 2, 3],Input2[1, 2, 3]') diff --git a/tools/ovc/openvino/tools/ovc/cli_parser.py b/tools/ovc/openvino/tools/ovc/cli_parser.py index 8568c12a47a53f..9931fa539cb054 100644 --- a/tools/ovc/openvino/tools/ovc/cli_parser.py +++ b/tools/ovc/openvino/tools/ovc/cli_parser.py @@ -44,11 +44,8 @@ def single_input_to_input_cut_info(input: [str, tuple, list, PartialShape, Type, :return: InputCutInfo """ if isinstance(input, str): - # Parse params from string - node_name, shape = parse_input_value(input) # pylint: disable=no-member - return _InputCutInfo(node_name, - PartialShape(shape) if shape is not None else None) + return _InputCutInfo(input, None) if isinstance(input, (tuple, list)) or is_shape_type(input): # If input represents list with shape, wrap it to list. Single PartialShape also goes to this condition. # Check of all dimensions will be in is_shape_type(val) method below @@ -68,10 +65,10 @@ def single_input_to_input_cut_info(input: [str, tuple, list, PartialShape, Type, if inp_type is not None: raise Exception("More than one input type provided: {}".format(input)) inp_type = val - elif is_shape_type(val): + elif is_shape_type(val) or val is None: if shape is not None: raise Exception("More than one input shape provided: {}".format(input)) - shape = PartialShape(val) + shape = PartialShape(val) if val is not None else None else: raise Exception("Incorrect input parameters provided. Expected tuple with input name, " "input type or input shape. Got unknown object: {}".format(val)) @@ -116,7 +113,20 @@ def is_single_input(input: [tuple, list]): return True -def input_to_input_cut_info(input: [str, tuple, list]): +def parse_inputs(inputs: str): + inputs_list = [] + # Split to list of string + for input_value in split_inputs(inputs): + + # Parse string with parameters for single input + node_name, shape = parse_input_value(input_value) + # pylint: disable=no-member + inputs_list.append((node_name, shape)) + return inputs_list + + +def input_to_input_cut_info(input: [dict, tuple, list]): + """ Parses 'input' to list of InputCutInfo. :param input: input cut parameters passed by user @@ -124,18 +134,10 @@ def input_to_input_cut_info(input: [str, tuple, list]): """ if input is None: return [] - if isinstance(input, str): - inputs = [] - # Split to list of string - for input_value in split_inputs(input): - - # Parse string with parameters for single input - node_name, shape = parse_input_value(input_value) - # pylint: disable=no-member - inputs.append(_InputCutInfo(node_name, - PartialShape(shape) if shape is not None else None)) - return inputs + if isinstance(input, (tuple, list)): + if len(input) == 0: + return [] # Case when input is single shape set in tuple if len(input) > 0 and isinstance(input[0], (int, Dimension)): input = [input] diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index fabf3601a49aee..cf09a2abfe26d0 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -22,7 +22,7 @@ from openvino.tools.ovc.moc_frontend.moc_emit_ir import moc_emit_ir from openvino.tools.ovc.convert_data_type import destination_type_to_np_data_type from openvino.tools.ovc.cli_parser import get_available_front_ends, get_common_cli_options, depersonalize, \ - get_mo_convert_params, input_to_input_cut_info + get_mo_convert_params, input_to_input_cut_info, parse_inputs from openvino.tools.ovc.help import get_convert_model_help_specifics from openvino.tools.ovc.error import Error, FrameworkError @@ -93,7 +93,14 @@ def arguments_post_parsing(argv: argparse.Namespace): if is_verbose(argv): print_argv(argv) - params_parsing(argv) + import re + if argv.is_python_api_used and isinstance(argv.input, str): + argv.input = [argv.input] + + if not argv.is_python_api_used and isinstance(argv.input, str): + argv.input = parse_inputs(argv.input) + + normalize_inputs(argv) log.debug("Placeholder shapes : {}".format(argv.placeholder_shapes)) if not hasattr(argv, 'output') or argv.output is None: @@ -297,9 +304,9 @@ def input_model_is_object(input_model): return True -def params_parsing(argv: argparse.Namespace): +def normalize_inputs(argv: argparse.Namespace): """ - Parses params passed to convert_model and wraps resulting values into dictionaries or lists. + repacks params passed to convert_model and wraps resulting values into dictionaries or lists. After working of this method following values are set in argv: argv.input, argv.inputs_list - list of input names. Both values are used in some parts of MO. diff --git a/tools/ovc/unit_tests/moc_tf_fe/conversion_basic_models_test.py b/tools/ovc/unit_tests/moc_tf_fe/conversion_basic_models_test.py index ba2a1a8a652c4f..d1306523b83de7 100644 --- a/tools/ovc/unit_tests/moc_tf_fe/conversion_basic_models_test.py +++ b/tools/ovc/unit_tests/moc_tf_fe/conversion_basic_models_test.py @@ -144,14 +144,14 @@ def test_conversion_pbtxt_model_with_inference(self, inputs, expected, dtype): # new frontend ( "model_add_with_undefined_constant.pbtxt", - "x[2,3]", + ("x", [2, 3]), {"x": np.array([[12, 13, 10], [11, 14, 16]], dtype=np.float32)}, np.array([[12, 13, 10], [11, 14, 16]], dtype=np.float32), np.float32 ), ( "model_mul_with_undefined_constant.pbtxt", - "x[2]", + ("x", [2]), {"x": np.array([11, -12], dtype=np.int32)}, np.array([0, 0], dtype=np.int32), np.int32 diff --git a/tools/ovc/unit_tests/ovc/utils/cli_parser_test.py b/tools/ovc/unit_tests/ovc/utils/cli_parser_test.py index c7ecf0e90b53cf..8d7edc8b21451d 100644 --- a/tools/ovc/unit_tests/ovc/utils/cli_parser_test.py +++ b/tools/ovc/unit_tests/ovc/utils/cli_parser_test.py @@ -13,7 +13,7 @@ import numpy as np from openvino.tools.ovc.cli_parser import input_to_input_cut_info, check_positive, writable_dir, \ - readable_file_or_object, get_all_cli_parser, get_mo_convert_params + readable_file_or_object, get_all_cli_parser, get_mo_convert_params, parse_inputs from openvino.tools.ovc.convert_impl import pack_params_to_args_namespace, arguments_post_parsing, args_to_argv from openvino.tools.ovc.error import Error from unit_tests.ovc.unit_test_with_mocked_telemetry import UnitTestWithMockedTelemetry @@ -26,6 +26,7 @@ class TestShapesParsing(UnitTestWithMockedTelemetry): def test_get_shapes_several_inputs_several_shapes2(self): # shapes specified using --input command line parameter and no values argv_input = "inp1[1,22,333,123],inp2[-1,45,7,1]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([1,22,333,123])), _InputCutInfo(name='inp2', shape=PartialShape([-1,45,7,1]))] @@ -33,30 +34,31 @@ def test_get_shapes_several_inputs_several_shapes2(self): def test_raises_get_shapes_1(self): argv_input = "[h,y]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_raises_get_shapes_2(self): argv_input = "(2, 3)" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_raises_get_shapes_3(self): argv_input = "input_1(2, 3)" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_raises_get_shapes_4(self): argv_input = "(2, 3),(10, 10)" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_raises_get_shapes_5(self): argv_input = "<2,3,4>" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_raises_get_shapes_6(self): argv_input = "sd<2,3>" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_get_shapes_complex_input(self): argv_input = "[10, -1, 100],mask[],[?,?]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(shape=PartialShape([10, -1, 100])), _InputCutInfo(name='mask', shape=PartialShape([])), @@ -66,6 +68,7 @@ def test_get_shapes_complex_input(self): def test_get_shapes_and_freezing_with_scalar_and_without_shapes_in_input(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1,inp2" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1'), _InputCutInfo(name='inp2')] @@ -75,6 +78,7 @@ def test_get_shapes_and_freezing_with_scalar_and_without_shapes_in_input(self): def test_get_shapes_and_freezing_with_scalar(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1,inp2[]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1'), _InputCutInfo(name='inp2', shape=PartialShape([]))] @@ -83,6 +87,7 @@ def test_get_shapes_and_freezing_with_scalar(self): def test_get_shapes_several_inputs_several_shapes3(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1[3 1],inp2[3,2,3],inp3[5]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape([3,2,3])), @@ -92,6 +97,7 @@ def test_get_shapes_several_inputs_several_shapes3(self): def test_get_shapes_several_inputs_several_shapes3_comma_sep(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1[3 1],inp2[3 2 3],inp3[5]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape([3,2,3])), @@ -101,6 +107,7 @@ def test_get_shapes_several_inputs_several_shapes3_comma_sep(self): def test_get_shapes_several_inputs_several_shapes6(self): # 0D value for freezing specified using --input command line parameter without shape argv_input = "inp1[3,1],inp2[3,2,3],inp3" + argv_input = parse_inputs(argv_input) inputs_list, result, _ = input_to_input_cut_info(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), @@ -111,6 +118,7 @@ def test_get_shapes_several_inputs_several_shapes6(self): def test_get_shapes_several_inputs_several_shapes7(self): # 0D shape and value for freezing specified using --input command line parameter argv_input = "inp1[3,1],inp2[3,2,3],inp3[]" + argv_input = parse_inputs(argv_input) inputs_list, result, _ = input_to_input_cut_info(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), @@ -121,6 +129,7 @@ def test_get_shapes_several_inputs_several_shapes7(self): def test_get_shapes_and_data_types_shape_only(self): argv_input = "placeholder1[3 1],placeholder2,placeholder3" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='placeholder1', shape=PartialShape([3,1])), _InputCutInfo(name='placeholder2'), @@ -129,6 +138,7 @@ def test_get_shapes_and_data_types_shape_only(self): def test_get_shapes_and_data_types_shape_with_ports_only(self): argv_input = "placeholder1:4[3 1],placeholder2,2:placeholder3" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='placeholder1:4', shape=PartialShape([3,1])), _InputCutInfo(name='placeholder2'), @@ -137,15 +147,16 @@ def test_get_shapes_and_data_types_shape_with_ports_only(self): def test_wrong_data_types(self): argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3 2 3]{abracadabra},inp3[5]{f32}->[1.0 1.0 2.0 3.0 5.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_shape_and_value_shape_mismatch(self): # size of value tensor does not correspond to specified shape for the third node argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3 2 3],inp3[5 3]->[2.0 3.0 5.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_get_shapes_no_input_no_shape(self): argv_input = "" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [] self.assertEqual(inputs, inputs_ref) @@ -153,18 +164,21 @@ def test_get_shapes_no_input_no_shape(self): def test_get_shapes_no_input_one_shape2(self): argv_input = "[12,4,1]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(shape=PartialShape([12,4,1]))] self.assertEqual(inputs, inputs_ref) def test_get_shapes_for_scalar_inputs(self): argv_input = "[]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(shape=PartialShape([]))] self.assertEqual(inputs, inputs_ref) def test_get_shapes_two_input_shapes_with_scalar(self): argv_input = "[12,4,1],[]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(shape=PartialShape([12,4,1])), _InputCutInfo(shape=PartialShape([]))] @@ -172,6 +186,7 @@ def test_get_shapes_two_input_shapes_with_scalar(self): def test_get_shapes_two_input_shapes(self): argv_input = "[12,4,1],[10]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(shape=PartialShape([12,4,1])), _InputCutInfo(shape=PartialShape([10])),] @@ -179,6 +194,7 @@ def test_get_shapes_two_input_shapes(self): def test_get_shapes_one_input_no_shape(self): argv_input = "inp1" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1')] self.assertEqual(inputs, inputs_ref) @@ -186,6 +202,7 @@ def test_get_shapes_one_input_no_shape(self): def test_get_shapes_several_inputs_several_partial_shapes2(self): # shapes specified using --input command line parameter and no values argv_input = "inp1[1,?,50..100,123],inp2[-1,45..,..7,1]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape("[1,?,50..100,123]")), _InputCutInfo(name='inp2', shape=PartialShape("[-1,45..,..7,1]"))] @@ -194,6 +211,7 @@ def test_get_shapes_several_inputs_several_partial_shapes2(self): def test_get_shapes_several_inputs_several_partial_shapes3(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1[3,1],inp2[3..,..2,5..10,?,-1],inp3[5]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -203,6 +221,7 @@ def test_get_shapes_several_inputs_several_partial_shapes3(self): def test_get_shapes_several_inputs_several_partial_shapes6(self): # 0D value for freezing specified using --input command line parameter without shape argv_input = "inp1[3 1],inp2[3.. ..2 5..10 ? -1],inp3" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -212,6 +231,7 @@ def test_get_shapes_several_inputs_several_partial_shapes6(self): def test_get_shapes_several_inputs_several_partial_shapes7(self): # 0D shape and value for freezing specified using --input command line parameter argv_input = "inp1[3 1],inp2[3.. ..2 5..10 ? -1],inp3[]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -220,15 +240,16 @@ def test_get_shapes_several_inputs_several_partial_shapes7(self): def test_partial_shapes_freeze_dynamic_negative_case1(self): argv_input = "inp1:1[3 1..10]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_partial_shapes_freeze_dynamic_negative_case2(self): argv_input = "inp1:1[1 2 -1]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_get_shapes_several_inputs_several_partial_shapes2_comma_separator(self): # shapes specified using --input command line parameter and no values argv_input = "inp1[1,?,50..100,123],inp2[-1,45..,..7,1]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape("[1,?,50..100,123]")), _InputCutInfo(name='inp2', shape=PartialShape("[-1,45..,..7,1]"))] @@ -237,6 +258,7 @@ def test_get_shapes_several_inputs_several_partial_shapes2_comma_separator(self) def test_get_shapes_several_inputs_several_partial_shapes3_comma_separator(self): # shapes and value for freezing specified using --input command line parameter argv_input = "inp1[3,1],inp2[3..,..2,5..10,?,-1],inp3[5]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -246,6 +268,7 @@ def test_get_shapes_several_inputs_several_partial_shapes3_comma_separator(self) def test_get_shapes_several_inputs_several_partial_shapes6_comma_separator(self): # 0D value for freezing specified using --input command line parameter without shape argv_input = "inp1[3, 1],inp2[3.., ..2, 5..10, ?,-1],inp3" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -255,6 +278,7 @@ def test_get_shapes_several_inputs_several_partial_shapes6_comma_separator(self) def test_get_shapes_several_inputs_several_partial_shapes7_comma_separator(self): # 0D shape and value for freezing specified using --input command line parameter argv_input = "inp1[3,1],inp2[3.., ..2,5..10, ?,-1],inp3[]" + argv_input = parse_inputs(argv_input) inputs = input_to_input_cut_info(argv_input) inputs_ref = [_InputCutInfo(name='inp1', shape=PartialShape([3,1])), _InputCutInfo(name='inp2', shape=PartialShape("[3..,..2,5..10,?,-1]")), @@ -263,24 +287,25 @@ def test_get_shapes_several_inputs_several_partial_shapes7_comma_separator(self) def test_partial_shapes_freeze_dynamic_negative_case1_comma_separator(self): argv_input = "inp1:1[3,1..10]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_partial_shapes_freeze_dynamic_negative_case2_comma_separator(self): argv_input = "inp1:1[1,2,-1]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_partial_shapes_freeze_dynamic_negative_case3_comma_separator(self): argv_input = "inp1:1[3,1..10]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_partial_shapes_freeze_dynamic_negative_case4_comma_separator(self): argv_input = "inp1:1[1, 2, -1]->[1.0 2.0 3.0]" - self.assertRaises(Error, input_to_input_cut_info, argv_input) + self.assertRaises(Error, parse_inputs, argv_input) def test_not_supported_arrow(self): with self.assertRaisesRegex(Exception, "Incorrect format of input."): - input_to_input_cut_info("inp1->[1.0]") + argv_input = parse_inputs("inp1->[1.0]") + input_to_input_cut_info(argv_input) class PositiveChecker(unittest.TestCase): @@ -526,4 +551,3 @@ def test_mo_convert_params_parsing(self): assert param_name not in cli_parser._option_string_actions else: assert param_name in cli_parser._option_string_actions - From c76475288b9e3bd67b300dfdf297385017276820 Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Fri, 22 Sep 2023 15:05:33 +0400 Subject: [PATCH 21/43] [PT FE]: support aten::scatter_reduce and extend aten::scatter (#19980) * [PT FE]: support aten::scatter_reduce and extend aten::scatter out arg support * create mapping inside function --- src/frontends/pytorch/src/op/scatter.cpp | 112 +++++++++++---- src/frontends/pytorch/src/op_table.cpp | 3 + .../layer_tests/pytorch_tests/test_scatter.py | 135 ++++++++++++++++-- 3 files changed, 211 insertions(+), 39 deletions(-) diff --git a/src/frontends/pytorch/src/op/scatter.cpp b/src/frontends/pytorch/src/op/scatter.cpp index 87611d93fd7ba6..4c60f12eed546b 100644 --- a/src/frontends/pytorch/src/op/scatter.cpp +++ b/src/frontends/pytorch/src/op/scatter.cpp @@ -17,19 +17,68 @@ namespace op { using namespace ov::op; +namespace { +Output prepare_source(const NodeContext& context, Output src, Output index, Output input) { + auto src_partial_shape = src.get_partial_shape(); + auto index_shape_rank = get_shape_rank(context, index); + auto index_shape = std::get<0>(index_shape_rank); + auto index_rank = std::get<1>(index_shape_rank); + + // Source input can be either Tensor which should be passed in original shape or Scalar that should be broadcasted + // into shape of indices. + // TODO: Figure out way to dynamically broadcast scalar src only, without affecting Tensor src. Current + // implementation will fail if Scalar source would have dynamic rank. + if (src_partial_shape.rank().is_static() && src_partial_shape.rank().get_length() == 0) { + src = context.mark_node(std::make_shared(src, index_shape)); + } + + auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto zeros = context.mark_node(std::make_shared(const_0, index_rank)); + auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + auto ones = context.mark_node(std::make_shared(const_1, index_rank)); + // In torch indices can be of different shape than source tensor. Create slice to trim source tensor to shape of + // indices. + auto src_pruned = context.mark_node(std::make_shared(src, zeros, index_shape, ones)); + + auto src_input_dtype = context.mark_node(std::make_shared(src_pruned, input)); + return src_input_dtype; +}; + +const v12::ScatterElementsUpdate::Reduction get_reduction_mode(std::string pt_reduce_mode) { + static const std::unordered_map TORCH_REDUCTION_TO_OV{ + {"add", v12::ScatterElementsUpdate::Reduction::SUM}, + {"multiply", v12::ScatterElementsUpdate::Reduction::PROD}, + {"sum", v12::ScatterElementsUpdate::Reduction::SUM}, + {"prod", v12::ScatterElementsUpdate::Reduction::PROD}, + {"mean", v12::ScatterElementsUpdate::Reduction::MEAN}, + {"amax", v12::ScatterElementsUpdate::Reduction::MAX}, + {"amin", v12::ScatterElementsUpdate::Reduction::MIN}}; + + FRONT_END_OP_CONVERSION_CHECK(TORCH_REDUCTION_TO_OV.count(pt_reduce_mode), + "Unknown reduction mode: ", + pt_reduce_mode); + auto reduction = TORCH_REDUCTION_TO_OV.at(pt_reduce_mode); + return reduction; +} +}; // namespace + OutputVector translate_scatter(const NodeContext& context) { // Out-of-place schema // aten::scatter.value(Tensor self, int dim, Tensor index, Scalar value) -> Tensor: // aten::scatter.src(Tensor self, int dim, Tensor index, Tensor src) -> Tensor: + // aten::scatter.src_out(Tensor self, int dim, Tensor index, Tensor src, *, Tensor(a!) out) -> Tensor(a!) // aten::scatter.reduce(Tensor self, int dim, Tensor index, Tensor src, *, str reduce) -> Tensor: // aten::scatter.value_reduce(Tensor self, int dim, Tensor index, Scalar value, *, str reduce) -> Tensor: + // aten::scatter.value_out(Tensor self, int dim, Tensor index, Scalar value, *, Tensor(a!) out) -> Tensor(a!) + // aten::scatter.value_reduce_out(Tensor self, int dim, Tensor index, Scalar value, *, str reduce, Tensor(a!) out) + // -> Tensor(a!) // Inplace schema // aten::scatter_.value(Tensor(a!) self, int dim, Tensor index, Scalar value) -> Tensor(a!): // aten::scatter_.src(Tensor(a!) self, int dim, Tensor index, Tensor src) -> Tensor(a!): // aten::scatter_.reduce(Tensor(a!) self, int dim, Tensor index, Tensor src, *, str reduce) -> Tensor(a!): // aten::scatter_.value_reduce(Tensor(a!) self, int dim, Tensor index, Scalar value, *, str reduce) -> Tensor(a!): - num_inputs_check(context, 4, 5); + num_inputs_check(context, 4, 6); auto input = context.get_input(0); auto dim = context.get_input(1); auto index = context.mark_node(std::make_shared(context.get_input(2), element::i32)); @@ -37,38 +86,45 @@ OutputVector translate_scatter(const NodeContext& context) { auto reduction = v12::ScatterElementsUpdate::Reduction::NONE; auto input_num = context.get_input_size(); - if (input_num > 4 && !context.input_is_none(input_num - 1)) { - auto reduce_mode = context.const_input(input_num - 1); - if (reduce_mode == "add") { - reduction = v12::ScatterElementsUpdate::Reduction::SUM; - } else if (reduce_mode == "multiply") { - reduction = v12::ScatterElementsUpdate::Reduction::PROD; - } + // 5 argument can be reduction represened as string or out represented as Tensor + if (input_num > 4 && !context.input_is_none(4) && context.get_input_type(4).is()) { + auto reduce_mode = context.const_input(4); + reduction = get_reduction_mode(reduce_mode); } - auto src_partial_shape = src.get_partial_shape(); - auto index_shape_rank = get_shape_rank(context, index); - auto index_shape = std::get<0>(index_shape_rank); - auto index_rank = std::get<1>(index_shape_rank); - // Source input can be either Tensor which should be passed in original shape or Scalar that should be broadcasted - // into shape of indices. - // TODO: Figure out way to dynamically broadcast scalar src only, without affecting Tensor src. Current - // implementation will fail if Scalar source would have dynamic rank. - if (src_partial_shape.rank().is_static() && src_partial_shape.rank().get_length() == 0) { - src = context.mark_node(std::make_shared(src, index_shape)); + auto src_input_dtype = prepare_source(context, src, index, input); + auto res = + context.mark_node(std::make_shared(input, index, src_input_dtype, dim, reduction)); + if (input_num == 6 || (input_num == 5 && !context.get_input_type(4).is())) { + context.mutate_input(input_num - 1, res); } + return {res}; +}; - auto const_0 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); - auto zeros = context.mark_node(std::make_shared(const_0, index_rank)); - auto const_1 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); - auto ones = context.mark_node(std::make_shared(const_1, index_rank)); - // In torch indices can be of different shape than source tensor. Create slice to trim source tensor to shape of - // indices. - auto src_pruned = context.mark_node(std::make_shared(src, zeros, index_shape, ones)); +OutputVector translate_scatter_reduce(const NodeContext& context) { + // Out-of-place schema + // aten::scatter_reduce.two(Tensor self, int dim, Tensor index, Tensor src, str reduce, *, bool include_self=True) + // -> Tensor: aten::scatter_reduce.two_out(Tensor self, int dim, Tensor index, Tensor src, str reduce, *, bool + // include_self=True, Tensor(a!) out) -> Tensor(a!) - auto src_input_dtype = context.mark_node(std::make_shared(src_pruned, input)); - return { - context.mark_node(std::make_shared(input, index, src_input_dtype, dim, reduction))}; + // Inplace schema + // aten::scatter_reduce_.two(Tensor(a!) self, int dim, Tensor index, Tensor src, str reduce, *, bool + // include_self=True) -> Tensor(a!) + num_inputs_check(context, 6, 7); + auto input = context.get_input(0); + auto dim = context.get_input(1); + auto index = context.mark_node(std::make_shared(context.get_input(2), element::i32)); + auto src = context.get_input(3); + auto reduce_mode = context.const_input(4); + auto reduction = get_reduction_mode(reduce_mode); + auto include_self = context.const_input(5); + auto src_input_dtype = prepare_source(context, src, index, input); + auto scatter_result = context.mark_node( + std::make_shared(input, index, src_input_dtype, dim, reduction, include_self)); + if (!context.input_is_none(6)) { + context.mutate_input(6, scatter_result); + } + return {scatter_result}; }; } // namespace op diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 94bd71286df807..0bc6d77b3fc707 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -147,6 +147,7 @@ OP_CONVERTER(translate_rsqrt); OP_CONVERTER(translate_rsub); OP_CONVERTER(translate_scaled_dot_product_attention); OP_CONVERTER(translate_scatter); +OP_CONVERTER(translate_scatter_reduce); OP_CONVERTER(translate_select); OP_CONVERTER(translate_set_item); OP_CONVERTER(translate_selu); @@ -415,6 +416,8 @@ const std::map get_supported_ops_ts() { {"aten::scaled_dot_product_attention", op::translate_scaled_dot_product_attention}, {"aten::scatter", op::translate_scatter}, {"aten::scatter_", op::inplace_op}, + {"aten::scatter_reduce", op::translate_scatter_reduce}, + {"aten::scatter_reduce_", op::inplace_op}, {"aten::select", op::quantizable_op}, {"aten::selu", op::translate_selu}, {"aten::selu_", op::inplace_op}, diff --git a/tests/layer_tests/pytorch_tests/test_scatter.py b/tests/layer_tests/pytorch_tests/test_scatter.py index 4f4972b6e89a1a..f02aa74b88b9ab 100644 --- a/tests/layer_tests/pytorch_tests/test_scatter.py +++ b/tests/layer_tests/pytorch_tests/test_scatter.py @@ -8,13 +8,15 @@ class TestScatter(PytorchLayerTest): - def _prepare_input(self, dtype): - inp = np.random.randn(6, 6).astype(getattr(np, dtype)) - return (inp,) + def _prepare_input(self, dtype, out=False): + inp = np.random.randn(6, 6).astype(dtype) + if not out: + return (inp,) + return (inp, np.zeros_like(inp, dtype=dtype)) - def create_model(self, dim, index, src, inplace, reduce): + def create_model(self, dim, index, src, inplace, reduce, has_out): class aten_scatter(torch.nn.Module): - def __init__(self, dim, index, src, inplace, reduce): + def __init__(self, dim, index, src, inplace, reduce, has_out=False): super(aten_scatter, self).__init__() self.dim = dim self.use_empty_index = False @@ -29,7 +31,8 @@ def __init__(self, dim, index, src, inplace, reduce): if inplace: str_forward += "_inplace" else: - str_forward += "_out_of_place" + str_forward += ("_out_of_place" if not has_out else "_with_out") + if reduce: self.reduce = reduce @@ -43,6 +46,13 @@ def _forward_out_of_place(self, x: torch.Tensor): index = self.index return torch.scatter(x, self.dim, index, self.src) + def _forward_with_out(self, x: torch.Tensor, out: torch.Tensor): + if self.use_empty_index: + index = torch.empty([0, 0]) + else: + index = self.index + return torch.scatter(x, self.dim, index, self.src, out=out) + def _forward_inplace(self, x: torch.Tensor): if self.use_empty_index: index = torch.empty([0, 0]) @@ -57,6 +67,13 @@ def _forward_out_of_place_reduce(self, x: torch.Tensor): index = self.index return torch.scatter(x, self.dim, index, self.src, reduce=self.reduce) + def _forward_with_out_reduce(self, x: torch.Tensor, out:torch.Tensor): + if self.use_empty_index: + index = torch.empty([0, 0]) + else: + index = self.index + return torch.scatter(x, self.dim, index, self.src, reduce=self.reduce, out=out) + def _forward_inplace_reduce(self, x: torch.Tensor): if self.use_empty_index: index = torch.empty([0, 0]) @@ -70,7 +87,7 @@ def _forward_inplace_reduce(self, x: torch.Tensor): else: op_name = "aten::scatter" - return aten_scatter(dim, index, src, inplace, reduce), ref_net, op_name + return aten_scatter(dim, index, src, inplace, reduce, has_out), ref_net, op_name @pytest.mark.nightly @pytest.mark.precommit @@ -85,9 +102,105 @@ def _forward_inplace_reduce(self, x: torch.Tensor): ) @pytest.mark.parametrize("src", [torch.arange(1, 26).reshape(5, 5), 1]) @pytest.mark.parametrize("dtype", ["int32", "int64", "float32", "float64"]) - @pytest.mark.parametrize("inplace", [True, False]) + @pytest.mark.parametrize(["inplace", "has_out"], [(True, False), (False, True), (False, False)]) @pytest.mark.parametrize("reduce", [None, "add", "multiply"]) - def test_scatter(self, dim, index, src, dtype, inplace, reduce, ie_device, precision, ir_version): + def test_scatter(self, dim, index, src, dtype, inplace, has_out, reduce, ie_device, precision, ir_version): + if isinstance(src, torch.Tensor): + src = src.to(getattr(torch, dtype)) + freeze = True + if index is None: + # Freeze creates empty constant tensor which isn't supported by OV. + freeze = False + if (not freeze) and reduce: + pytest.skip( + "Cannot test reduce parameters with empty indexes due to issues with empty constant tensor or issues with prim::GetAttr str inputs." + ) + self._test( + *self.create_model(dim, index, src, inplace, reduce, has_out), + ie_device, + precision, + ir_version, + kwargs_to_prepare_input={"dtype": dtype, "out": has_out}, + freeze_model=freeze + ) + + +class TestScatterReduce(PytorchLayerTest): + def _prepare_input(self, dtype, out=False): + inp = np.random.randn(6, 6).astype(dtype) + if not out: + return (inp,) + return (inp, np.zeros_like(inp, dtype=dtype)) + + def create_model(self, dim, index, src, inplace, reduce, include_self, has_out): + class aten_scatter_reduce(torch.nn.Module): + def __init__(self, dim, index, src, inplace, reduce, include_self, has_out=False): + super(aten_scatter_reduce, self).__init__() + self.dim = dim + self.use_empty_index = False + if index is None: + self.use_empty_index = True + # Placeholder + self.index = torch.empty([1]) + else: + self.index = index + self.src = src + str_forward = "_forward" + if inplace: + str_forward += "_inplace" + else: + str_forward += ("_out_of_place" if not has_out else "_with_out") + + self.reduce = reduce + self.include_self = include_self + self.forward = getattr(self, str_forward) + + def _forward_out_of_place(self, x: torch.Tensor): + if self.use_empty_index: + index = torch.empty([0, 0]) + else: + index = self.index + return torch.scatter_reduce(x, self.dim, index, self.src, self.reduce, include_self=self.include_self) + + def _forward_with_out(self, x: torch.Tensor, out: torch.Tensor): + if self.use_empty_index: + index = torch.empty([0, 0]) + else: + index = self.index + return torch.scatter_reduce(x, self.dim, index, self.src, self.reduce, include_self=self.include_self, out=out) + + def _forward_inplace(self, x: torch.Tensor): + if self.use_empty_index: + index = torch.empty([0, 0]) + else: + index = self.index + return x.scatter_reduce_(self.dim, index, self.src, self.reduce, include_self=self.include_self) + + ref_net = None + if inplace: + op_name = "aten::scatter_reduce_" + else: + op_name = "aten::scatter_reduce" + + return aten_scatter_reduce(dim, index, src, inplace, reduce, include_self, has_out), ref_net, op_name + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("dim", [1, -1, 0]) + @pytest.mark.parametrize( + "index", + [ + None, # Empty tensor scenario. + torch.tensor([[0, 1, 2, 3]]), + torch.tensor([[0, 5], [4, 1], [2, 3]]), + ], + ) + @pytest.mark.parametrize("src", [torch.arange(1, 26).reshape(5, 5)]) + @pytest.mark.parametrize("dtype", ["int32", "int64", "float32", "float64"]) + @pytest.mark.parametrize(["inplace", "has_out"], [(True, False), (False, True), (False, False)]) + @pytest.mark.parametrize("reduce", ["sum", "prod", "mean", "amax", "amin"]) + @pytest.mark.parametrize("include_self", [True, False]) + def test_scatter_reduce(self, dim, index, src, dtype, inplace, has_out, reduce, include_self, ie_device, precision, ir_version): if isinstance(src, torch.Tensor): src = src.to(getattr(torch, dtype)) freeze = True @@ -99,10 +212,10 @@ def test_scatter(self, dim, index, src, dtype, inplace, reduce, ie_device, preci "Cannot test reduce parameters with empty indexes due to issues with empty constant tensor or issues with prim::GetAttr str inputs." ) self._test( - *self.create_model(dim, index, src, inplace, reduce), + *self.create_model(dim, index, src, inplace, reduce, include_self, has_out), ie_device, precision, ir_version, - kwargs_to_prepare_input={"dtype": dtype}, + kwargs_to_prepare_input={"dtype": dtype, "out": has_out}, freeze_model=freeze ) From fb4132414145ad294fc261d43b158859c9d477dc Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Fri, 22 Sep 2023 13:06:27 +0200 Subject: [PATCH 22/43] Update weight_compression.md (#20000) --- docs/optimization_guide/nncf/weight_compression.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/optimization_guide/nncf/weight_compression.md b/docs/optimization_guide/nncf/weight_compression.md index efec4839d47a1f..fb29a6d49b767f 100644 --- a/docs/optimization_guide/nncf/weight_compression.md +++ b/docs/optimization_guide/nncf/weight_compression.md @@ -10,7 +10,7 @@ Weight compression aims to reduce the memory footprint of a model. It can also l - enabling the inference of exceptionally large models that cannot be accommodated in the memory of the device; - improving the inference performance of the models by reducing the latency of the memory access when computing the operations with weights, for example, Linear layers. -Currently, NNCF provides 8-bit weight quantization as a compression method primarily designed to optimize LLMs. The main difference between weights compression and full model quantization (post-training quantization) is that activations remain floating-point in the case of weights compression which leads to a better accuracy. Weight compression for LLMs provides a solid inference performance improvement which is on par with the performance of the full model quantization. In addition, weight compression is data-free and does not require a calibration dataset, making it easy to use. +Currently, `Neural Network Compression Framework (NNCF) `__ provides 8-bit weight quantization as a compression method primarily designed to optimize LLMs. The main difference between weights compression and full model quantization (post-training quantization) is that activations remain floating-point in the case of weights compression which leads to a better accuracy. Weight compression for LLMs provides a solid inference performance improvement which is on par with the performance of the full model quantization. In addition, weight compression is data-free and does not require a calibration dataset, making it easy to use. Compress Model Weights ###################### @@ -33,5 +33,6 @@ Additional Resources - :doc:`Post-training Quantization ` - :doc:`Training-time Optimization ` +- `NNCF GitHub `__ @endsphinxdirective From 7a2ac27f09303a665d758772e405c31cb66ba3eb Mon Sep 17 00:00:00 2001 From: Mateusz Mikolajczyk Date: Fri, 22 Sep 2023 13:14:46 +0200 Subject: [PATCH 23/43] [Spec][Opset13] BitwiseAnd-13, BitwiseNot-13, BitwiseOr-13, BitwiseXor-13 specifications (#19798) * [Spec] BitwiseNot-13 specification * Improvements * add other specifications * Doc improvements * Fix typos * add opset13 * Fix typo * add opset13 * Fix * Improve example? * Fix step formatting * Apply suggestions from code review Co-authored-by: Katarzyna Mitrus * Add suggested changes * Fix missing the --------- Co-authored-by: Katarzyna Mitrus --- .../Operations_specifications.md | 4 + docs/ops/bitwise/BitwiseAnd_13.md | 138 ++++++++++++++++++ docs/ops/bitwise/BitwiseNot_13.md | 83 +++++++++++ docs/ops/bitwise/BitwiseOr_13.md | 138 ++++++++++++++++++ docs/ops/bitwise/BitwiseXor_13.md | 138 ++++++++++++++++++ docs/ops/opset13.md | 4 + 6 files changed, 505 insertions(+) create mode 100644 docs/ops/bitwise/BitwiseAnd_13.md create mode 100644 docs/ops/bitwise/BitwiseNot_13.md create mode 100644 docs/ops/bitwise/BitwiseOr_13.md create mode 100644 docs/ops/bitwise/BitwiseXor_13.md diff --git a/docs/OV_Runtime_UG/Operations_specifications.md b/docs/OV_Runtime_UG/Operations_specifications.md index c9d063b388108e..000b3e89525098 100644 --- a/docs/OV_Runtime_UG/Operations_specifications.md +++ b/docs/OV_Runtime_UG/Operations_specifications.md @@ -24,6 +24,10 @@ BatchNormInference-5 BatchToSpace-2 BinaryConvolution-1 + BitwiseAnd-13 + BitwiseNot-13 + BitwiseOr-13 + BitwiseXor-13 Broadcast-1 Broadcast-3 Bucketize-3 diff --git a/docs/ops/bitwise/BitwiseAnd_13.md b/docs/ops/bitwise/BitwiseAnd_13.md new file mode 100644 index 00000000000000..7ca942281f84d6 --- /dev/null +++ b/docs/ops/bitwise/BitwiseAnd_13.md @@ -0,0 +1,138 @@ +# BitwiseAnd {#openvino_docs_ops_bitwise_BitwiseAnd_13} + +@sphinxdirective + +.. meta:: + :description: Learn about BitwiseAnd-13 - an element-wise, bitwise AND operation, which can be performed on two required input tensors. + +**Versioned name**: *BitwiseAnd-13* + +**Category**: *Bitwise binary* + +**Short description**: *BitwiseAnd* performs a bitwise logical AND operation with two given tensors element-wise, applying multi-directional broadcast rules. + +**Detailed description**: Before performing the operation, input tensors *a* and *b* are broadcasted if their shapes are different and the ``auto_broadcast`` attribute is not ``none``. Broadcasting is performed according to the ``auto_broadcast`` value. + +After broadcasting input tensors *a* and *b*, *BitwiseAnd* performs a bitwise logical AND operation for each corresponding element in the given tensors, based on the following algorithm. + +For ``boolean`` type tensors, BitwiseAnd is equivalent to :doc:`LogicalAnd `. + +If tensor is of ``any supported integer`` type, for each element of the tensor: + +1. Convert values from input tensors to their binary representation according to the input tensor datatype. +2. Perform a logical AND on each bit in the binary representation of values from *a* and *b*, where value ``0`` represents ``false`` and value ``1`` represents ``true``. +3. Convert the results of AND in binary representation to the input datatype. + +Example 1 - *BitwiseAnd* output for boolean tensor: + +.. code-block:: py + :force: + + # For given boolean inputs: + a = [True, False, False] + b = [True, True, False] + # Perform logical AND operation same as in LogicalAnd operator: + output = [True, False, False] + +Example 2 - *BitwiseAnd* output for uint8 tensor: + +.. code-block:: py + :force: + + # For given uint8 inputs: + a = [21, 120] + b = [3, 37] + # Create a binary representation of uint8: + # binary a: [00010101, 01111000] + # binary b: [00000011, 00100101] + # Perform bitwise AND of corresponding elements in a and b: + # [00000001, 00100000] + # Convert binary values to uint8: + output = [1, 32] + +**Attributes**: + +* *auto_broadcast* + + * **Description**: specifies the rules used for auto-broadcasting of input tensors. + * **Range of values**: + + * *none* - no auto-broadcasting is allowed, all input shapes must match, + * *numpy* - numpy broadcasting rules, description is available in :doc:`Broadcast Rules For Elementwise Operations `, + * *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in :doc:`Broadcast Rules For Elementwise Operations `. + + * **Type**: string + * **Default value**: "numpy" + * **Required**: *no* + +**Inputs** + +* **1**: A tensor of type *T* and arbitrary shape. **Required.** +* **2**: A tensor of type *T* and arbitrary shape. **Required.** + +**Outputs** + +* **1**: The result of element-wise *BitwiseAnd* operation. A tensor of type *T* and the same shape equal to the broadcasted shape of two inputs. + +**Types** + +* *T*: ``any supported integer or boolean type``. + +**Examples** + +*Example 1: no broadcast* + +.. code-block:: xml + :force: + + + + + 256 + 56 + + + 256 + 56 + + + + + 256 + 56 + + + + + +*Example 2: numpy broadcast* + +.. code-block:: xml + :force: + + + + + 8 + 1 + 6 + 1 + + + 7 + 1 + 5 + + + + + 8 + 7 + 6 + 5 + + + + + +@endsphinxdirective diff --git a/docs/ops/bitwise/BitwiseNot_13.md b/docs/ops/bitwise/BitwiseNot_13.md new file mode 100644 index 00000000000000..1f54f1da4d72cc --- /dev/null +++ b/docs/ops/bitwise/BitwiseNot_13.md @@ -0,0 +1,83 @@ +# BitwiseNot {#openvino_docs_ops_bitwise_BitwiseNot_13} + +@sphinxdirective + +.. meta:: + :description: Learn about BitwiseNot-13 - an element-wise, bitwise negation operation, which can be performed on a single input tensor. + +**Versioned name**: *BitwiseNot-13* + +**Category**: *Bitwise unary* + +**Short description**: *BitwiseNot* performs a bitwise logical negation operation with given tensor element-wise. + +**Detailed description**: *BitwiseNot* performs a bitwise logical negation operation for each element in the given tensor, based on the following algorithm. + +For ``boolean`` type tensors, BitwiseNot is equivalent to :doc:`LogicalNot `. + +If tensor is of ``any supported integer`` type, for each element of the tensor: + +1. Convert the value from the input tensor to binary representation according to the input tensor datatype. +2. Perform a logical negation on each bit in the binary representation, where value ``0`` represents ``false`` and value ``1`` represents ``true``. +3. Convert back the binary representation to the input datatype. + +Example 1 - *BitwiseNot* output for boolean tensor: + +.. code-block:: py + :force: + + # For given boolean input: + input = [True, False] + # Perform logical negation operation same as in LogicalNot operator: + output = [False, True] + +Example 2 - *BitwiseNot* output for uint8 tensor: + +.. code-block:: py + :force: + + # For given uint8 input: + input = [1, 3] + # Create a binary representation of uint8: + # [00000001, 00000011] + # Perform bitwise negation: + # [11111110, 11111100] + # Convert back binary values to uint8: + output = [254, 252] + +**Attributes**: *BitwiseNot* operation has no attributes. + +**Inputs** + +* **1**: A tensor of type *T* and arbitrary shape. **Required.** + +**Outputs** + +* **1**: The result of bitwise logical negation operation. A tensor of type *T* and the same shape as the input tensor. + +**Types** + +* *T*: ``any supported integer or boolean type``. + +**Example** + +.. code-block:: xml + :force: + + + + + 256 + 56 + + + + + 256 + 56 + + + + + +@endsphinxdirective diff --git a/docs/ops/bitwise/BitwiseOr_13.md b/docs/ops/bitwise/BitwiseOr_13.md new file mode 100644 index 00000000000000..59b3bc3195af82 --- /dev/null +++ b/docs/ops/bitwise/BitwiseOr_13.md @@ -0,0 +1,138 @@ +# BitwiseOr {#openvino_docs_ops_bitwise_BitwiseOr_13} + +@sphinxdirective + +.. meta:: + :description: Learn about BitwiseOr-13 - an element-wise, bitwise OR operation, which can be performed on two required input tensors. + +**Versioned name**: *BitwiseOr-13* + +**Category**: *Bitwise binary* + +**Short description**: *BitwiseOr* performs a bitwise logical OR operation with two given tensors element-wise, applying multi-directional broadcast rules. + +**Detailed description**: Before performing the operation, input tensors *a* and *b* are broadcasted if their shapes are different and the ``auto_broadcast`` attribute is not ``none``. Broadcasting is performed according to the ``auto_broadcast`` value. + +After broadcasting input tensors *a* and *b*, *BitwiseOr* performs a bitwise logical OR operation for each corresponding element in the given tensors, based on the following algorithm. + +For ``boolean`` type tensors, BitwiseOr is equivalent to :doc:`LogicalOr `. + +If tensor is of ``any supported integer`` type, for each element of the tensor: + +1. Convert values from input tensors to their binary representation according to the input tensor datatype. +2. Perform a logical OR on each bit in the binary representation of values from *a* and *b*, where value ``0`` represents ``false`` and value ``1`` represents ``true``. +3. Convert the results of OR in binary representation to the input datatype. + +Example 1 - *BitwiseOr* output for boolean tensor: + +.. code-block:: py + :force: + + # For given boolean inputs: + a = [True, False, False] + b = [True, True, False] + # Perform logical OR operation same as in LogicalOr operator: + output = [True, True, False] + +Example 2 - *BitwiseOr* output for uint8 tensor: + +.. code-block:: py + :force: + + # For given uint8 inputs: + a = [21, 120] + b = [3, 37] + # Create a binary representation of uint8: + # binary a: [00010101, 01111000] + # binary b: [00000011, 00100101] + # Perform bitwise OR of corresponding elements in a and b: + # [00010111, 01111101] + # Convert binary values to uint8: + output = [23, 125] + +**Attributes**: + +* *auto_broadcast* + + * **Description**: specifies the rules used for auto-broadcasting of input tensors. + * **Range of values**: + + * *none* - no auto-broadcasting is allowed, all input shapes must match, + * *numpy* - numpy broadcasting rules, description is available in :doc:`Broadcast Rules For Elementwise Operations `, + * *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in :doc:`Broadcast Rules For Elementwise Operations `. + + * **Type**: string + * **Default value**: "numpy" + * **Required**: *no* + +**Inputs** + +* **1**: A tensor of type *T* and arbitrary shape. **Required.** +* **2**: A tensor of type *T* and arbitrary shape. **Required.** + +**Outputs** + +* **1**: The result of element-wise *BitwiseOr* operation. A tensor of type *T* and the same shape equal to the broadcasted shape of two inputs. + +**Types** + +* *T*: ``any supported integer or boolean type``. + +**Examples** + +*Example 1: no broadcast* + +.. code-block:: xml + :force: + + + + + 256 + 56 + + + 256 + 56 + + + + + 256 + 56 + + + + + +*Example 2: numpy broadcast* + +.. code-block:: xml + :force: + + + + + 8 + 1 + 6 + 1 + + + 7 + 1 + 5 + + + + + 8 + 7 + 6 + 5 + + + + + +@endsphinxdirective diff --git a/docs/ops/bitwise/BitwiseXor_13.md b/docs/ops/bitwise/BitwiseXor_13.md new file mode 100644 index 00000000000000..31287854f46148 --- /dev/null +++ b/docs/ops/bitwise/BitwiseXor_13.md @@ -0,0 +1,138 @@ +# BitwiseXor {#openvino_docs_ops_bitwise_BitwiseXor_13} + +@sphinxdirective + +.. meta:: + :description: Learn about BitwiseXor-13 - an element-wise, bitwise XOR operation, which can be performed on two required input tensors. + +**Versioned name**: *BitwiseXor-13* + +**Category**: *Bitwise binary* + +**Short description**: *BitwiseXor* performs a bitwise logical XOR operation with two given tensors element-wise, applying multi-directional broadcast rules. + +**Detailed description**: Before performing the operation, input tensors *a* and *b* are broadcasted if their shapes are different and the ``auto_broadcast`` attribute is not ``none``. Broadcasting is performed according to the ``auto_broadcast`` value. + +After broadcasting input tensors *a* and *b*, *BitwiseXor* performs a bitwise logical XOR operation for each corresponding element in the given tensors, based on the following algorithm. + +For ``boolean`` type tensors, BitwiseXor is equivalent to :doc:`LogicalXor `. + +If tensor is of ``any supported integer`` type, for each element of the tensor: + +1. Convert values from input tensors to their binary representation according to the input tensor datatype. +2. Perform a logical XOR on each bit in the binary representation of values from *a* and *b*, where value ``0`` represents ``false`` and value ``1`` represents ``true``. +3. Convert the results of XOR in binary representation to the input datatype. + +Example 1 - *BitwiseXor* output for boolean tensor: + +.. code-block:: py + :force: + + # For given boolean inputs: + a = [True, False, False] + b = [True, True, False] + # Perform logical XOR operation same as in LogicalXor operator: + output = [False, True, False] + +Example 2 - *BitwiseXor* output for uint8 tensor: + +.. code-block:: py + :force: + + # For given uint8 inputs: + a = [21, 120] + b = [3, 37] + # Create a binary representation of uint8: + # binary a: [00010101, 01111000] + # binary b: [00000011, 00100101] + # Perform bitwise XOR of corresponding elements in a and b: + # [00010110, 01011101] + # Convert binary values to uint8: + output = [22, 93] + +**Attributes**: + +* *auto_broadcast* + + * **Description**: specifies the rules used for auto-broadcasting of input tensors. + * **Range of values**: + + * *none* - no auto-broadcasting is allowed, all input shapes must match, + * *numpy* - numpy broadcasting rules, description is available in :doc:`Broadcast Rules For Elementwise Operations `, + * *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in :doc:`Broadcast Rules For Elementwise Operations `. + + * **Type**: string + * **Default value**: "numpy" + * **Required**: *no* + +**Inputs** + +* **1**: A tensor of type *T* and arbitrary shape. **Required.** +* **2**: A tensor of type *T* and arbitrary shape. **Required.** + +**Outputs** + +* **1**: The result of element-wise *BitwiseXor* operation. A tensor of type *T* and the same shape equal to the broadcasted shape of two inputs. + +**Types** + +* *T*: ``any supported integer or boolean type``. + +**Examples** + +*Example 1: no broadcast* + +.. code-block:: xml + :force: + + + + + 256 + 56 + + + 256 + 56 + + + + + 256 + 56 + + + + + +*Example 2: numpy broadcast* + +.. code-block:: xml + :force: + + + + + 8 + 1 + 6 + 1 + + + 7 + 1 + 5 + + + + + 8 + 7 + 6 + 5 + + + + + +@endsphinxdirective diff --git a/docs/ops/opset13.md b/docs/ops/opset13.md index f1411293a17028..dde2f5ce4888b6 100644 --- a/docs/ops/opset13.md +++ b/docs/ops/opset13.md @@ -32,6 +32,10 @@ Table of Contents * :doc:`BatchNormInference ` * :doc:`BatchToSpace ` * :doc:`BinaryConvolution ` +* :doc:`BitwiseAnd ` +* :doc:`BitwiseOr ` +* :doc:`BitwiseXor ` +* :doc:`BitwiseNot ` * :doc:`Broadcast ` * :doc:`Bucketize ` * :doc:`CTCGreedyDecoder ` From 5611f7d65c4ee0b6a78ed460d0ab093c7f559321 Mon Sep 17 00:00:00 2001 From: Vladimir Paramuzov Date: Fri, 22 Sep 2023 15:29:38 +0400 Subject: [PATCH 24/43] [GPU] Fix constants reuse (#20003) --- .../intel_gpu/plugin/program_builder.hpp | 2 +- .../intel_gpu/src/plugin/ops/constant.cpp | 19 ++--- .../subgraph_tests/shared_constant.cpp | 75 +++++++++++++++++++ 3 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_constant.cpp diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/program_builder.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/program_builder.hpp index 5bd2d3b4dfcfaf..22864106fb39f5 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/program_builder.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/program_builder.hpp @@ -89,7 +89,7 @@ class ProgramBuilder final { std::vector profiling_ids; std::map inputLayouts; - using BlobCacheKey = std::pair>; + using BlobCacheKey = std::tuple; std::map blobMemCache; std::shared_ptr get_compiled_program() const; diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp index 10eaa80327ff9c..b74d05e4f9aca6 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp @@ -67,30 +67,31 @@ struct ConstProperties { bool needsBatchInterpretation; }; -static void create_data(ProgramBuilder& p, const ov::Shape& constDims, const std::shared_ptr& op, const ConstProperties& props) { - cldnn::tensor constTensor = getConstTensor(constDims); - auto constFormat = cldnn::format::get_default_format(constDims.size()); +static void create_data(ProgramBuilder& p, const ov::Shape& const_shape, const std::shared_ptr& op, const ConstProperties& props) { + cldnn::tensor constTensor = getConstTensor(const_shape); + auto constFormat = cldnn::format::get_default_format(const_shape.size()); if (props.needsBatchInterpretation) { constTensor.batch[0] = static_cast(constTensor.count()); constTensor.feature[0] = 1; } - // If constDims has a dimension = 0, then create tensor with single value + // If const_shape has a dimension = 0, then create tensor with single value // TODO: check if dim=0 is a valid case - if (std::accumulate(constDims.begin(), constDims.end(), size_t(1), std::multiplies()) == 0) + if (std::accumulate(const_shape.begin(), const_shape.end(), size_t(1), std::multiplies()) == 0) constTensor = cldnn::tensor{1}; - auto newDims = constDims; cldnn::data_types out_dtype = cldnn::element_type_to_data_type(op->get_output_element_type(0)); - cldnn::layout constLayout = p.use_new_shape_infer() ? cldnn::layout(newDims, out_dtype, constFormat) : + cldnn::layout constLayout = p.use_new_shape_infer() ? cldnn::layout(const_shape, out_dtype, constFormat) : cldnn::layout(out_dtype, constFormat, constTensor); cldnn::primitive_id initialconstPrimID = layer_type_name_ID(op); cldnn::primitive_id constPrimID; auto data = op->get_data_ptr(); - auto bufIter = p.blobMemCache.find(std::make_pair(data, newDims)); + const auto cache_key = std::make_tuple(data, const_shape, op->get_output_element_type(0)); + + auto bufIter = p.blobMemCache.find(cache_key); if (bufIter != p.blobMemCache.end()) { constPrimID = bufIter->second; @@ -112,7 +113,7 @@ static void create_data(ProgramBuilder& p, const ov::Shape& constDims, const std std::memcpy(&buf[0], &data[0], bufSize); p.add_primitive(*op, cldnn::data(initialconstPrimID, mem)); - p.blobMemCache[std::make_pair(data, newDims)] = initialconstPrimID; + p.blobMemCache[cache_key] = initialconstPrimID; constPrimID = initialconstPrimID; } } diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_constant.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_constant.cpp new file mode 100644 index 00000000000000..2363d2b5e912a8 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_constant.cpp @@ -0,0 +1,75 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/partial_shape.hpp" +#include "openvino/runtime/properties.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/test_constants.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" + +using namespace ov::test; + +namespace ov { +namespace test { +namespace intel_gpu { + +class SharedConstantGPUTest : public SubgraphBaseTest { +protected: + void SetUp() override { + targetDevice = ov::test::utils::DEVICE_GPU; + + std::vector input_shapes { + {ov::PartialShape{1}, {{1}}}, + {ov::PartialShape{1}, {{1}}}, + {ov::PartialShape{2}, {{2}}}, + {ov::PartialShape{1, 2}, {{1, 2}}}, + }; + init_input_shapes(input_shapes); + + auto p0 = std::make_shared(ov::element::f32, input_shapes[0].first); + auto p1 = std::make_shared(ov::element::i32, input_shapes[1].first); + auto p2 = std::make_shared(ov::element::f32, input_shapes[2].first); + auto p3 = std::make_shared(ov::element::f32, input_shapes[3].first); + + std::vector values0{0}; + std::vector values1{0.0f, 1.0f}; + + ov::Tensor t0(ov::element::f32, input_shapes[0].first.to_shape(), values0.data()); + ov::Tensor t1(ov::element::i32, input_shapes[1].first.to_shape(), values0.data()); + ov::Tensor t2(ov::element::f32, input_shapes[2].first.to_shape(), values1.data()); + ov::Tensor t3(ov::element::f32, input_shapes[3].first.to_shape(), values1.data()); + + auto c0 = std::make_shared(t0); + auto c1 = std::make_shared(t1); + auto c2 = std::make_shared(t2); + auto c3 = std::make_shared(t3); + + auto add0 = std::make_shared(p0, c0); + auto add1 = std::make_shared(p1, c1); + auto add2 = std::make_shared(p2, c2); + auto add3 = std::make_shared(p3, c3); + + ov::ParameterVector params{p0, p1, p2, p3}; + ov::ResultVector results { + std::make_shared(add0->output(0)), + std::make_shared(add1->output(0)), + std::make_shared(add2->output(0)), + std::make_shared(add3->output(0)) + }; + function = std::make_shared(results, params, "SharedConstantGPUTest"); + + this->configuration.insert({ov::hint::inference_precision(ov::element::f32)}); + } +}; + +TEST_F(SharedConstantGPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + run(); +} + +} // namespace intel_gpu +} // namespace test +} // namespace ov From ce378739f0f8a6b7ca173e1613b2b5fcbb5bc84e Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Fri, 22 Sep 2023 14:35:20 +0200 Subject: [PATCH 25/43] Refactor DetectionOutputLayerTest, DFTLayerTest, EltwiseLayerTest (#19922) * Refactor DetectionOutputLayerTest * Refactor DFTLayerTest * Refactor EltwiseLayerTest * Fix * Fix * Disable tests --- .../single_layer_tests/detection_output.cpp | 6 +- .../single_layer_tests/dft.cpp | 53 +++---- .../single_layer_tests/eltwise.cpp | 117 +++++++-------- .../skip_tests_config.cpp | 3 + .../single_op_tests/detection_output.hpp | 15 ++ .../shared/include/single_op_tests/dft.hpp | 15 ++ .../include/single_op_tests/eltwise.hpp | 15 ++ .../shared_test_classes/base/utils/ranges.hpp | 5 + .../single_op/detection_output.hpp | 73 ++++++++++ .../shared_test_classes/single_op/dft.hpp | 33 +++++ .../shared_test_classes/single_op/eltwise.hpp | 38 +++++ .../src/single_op/detection_output.cpp | 116 +++++++++++++++ .../shared_test_classes/src/single_op/dft.cpp | 58 ++++++++ .../src/single_op/eltwise.cpp | 135 ++++++++++++++++++ 14 files changed, 596 insertions(+), 86 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/detection_output.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/dft.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/eltwise.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/detection_output.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/dft.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eltwise.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/detection_output.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/dft.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/detection_output.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/detection_output.cpp index 8d44f46f6d6439..2028d643d67295 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/detection_output.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/detection_output.cpp @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "single_layer_tests/detection_output.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/detection_output.hpp" namespace { +using ov::test::DetectionOutputLayerTest; +using ov::test::ParamsWhichSizeDepends; const int numClasses = 11; const int backgroundLabelId = 0; diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/dft.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/dft.cpp index 9982fa013ca8d3..9d91f2d5ca53e7 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/dft.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/dft.cpp @@ -4,28 +4,30 @@ #include -#include "single_layer_tests/dft.hpp" +#include "single_op_tests/dft.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; +namespace { +using ov::test::DFTLayerTest; -const std::vector opTypes = { - ngraph::helpers::DFTOpType::FORWARD, - ngraph::helpers::DFTOpType::INVERSE +const std::vector op_types = { + ov::test::utils::DFTOpType::FORWARD, + ov::test::utils::DFTOpType::INVERSE }; -const std::vector inputPrecision = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::BF16 +const std::vector input_type = { + ov::element::f32, + ov::element::bf16 }; -const std::vector> inputShapes = { - {10, 4, 20, 32, 2}, - {2, 5, 7, 8, 2}, - {1, 120, 128, 1, 2}, +const std::vector> input_shapes_static = { + {{10, 4, 20, 32, 2}}, + {{2, 5, 7, 8, 2}}, + {{1, 120, 128, 1, 2}}, }; /* 1D DFT */ + const std::vector> axes1D = { {0}, {1}, {2}, {3}, {-2} }; @@ -35,11 +37,11 @@ const std::vector> signalSizes1D = { }; const auto testCase1D = ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(input_type), ::testing::ValuesIn(axes1D), ::testing::ValuesIn(signalSizes1D), - ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(op_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -53,15 +55,14 @@ const std::vector> signalSizes2D = { }; const auto testCase2D = ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(input_type), ::testing::ValuesIn(axes2D), ::testing::ValuesIn(signalSizes2D), - ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(op_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); - /* 3D DFT */ const std::vector> axes3D = { @@ -73,11 +74,11 @@ const std::vector> signalSizes3D = { }; const auto testCase3D = ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(input_type), ::testing::ValuesIn(axes3D), ::testing::ValuesIn(signalSizes3D), - ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(op_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -92,16 +93,16 @@ const std::vector> signalSizes4D = { }; const auto testCase4D = ::testing::Combine( - ::testing::ValuesIn(inputShapes), - ::testing::ValuesIn(inputPrecision), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)), + ::testing::ValuesIn(input_type), ::testing::ValuesIn(axes4D), ::testing::ValuesIn(signalSizes4D), - ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(op_types), ::testing::Values(ov::test::utils::DEVICE_CPU) ); - INSTANTIATE_TEST_SUITE_P(smoke_TestsDFT_1d, DFTLayerTest, testCase1D, DFTLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsDFT_2d, DFTLayerTest, testCase2D, DFTLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsDFT_3d, DFTLayerTest, testCase3D, DFTLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_TestsDFT_4d, DFTLayerTest, testCase4D, DFTLayerTest::getTestCaseName); +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp index 49ccc2c37bcf2d..f8a80efe1f6223 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/eltwise.cpp @@ -3,13 +3,16 @@ // #include -#include "single_layer_tests/eltwise.hpp" +#include "single_op_tests/eltwise.hpp" #include "common_test_utils/test_constants.hpp" -using namespace ov::test::subgraph; - namespace { -std::vector> inShapesStatic = { +using ov::test::EltwiseLayerTest; +using ov::test::utils::InputLayerType; +using ov::test::utils::OpType; +using ov::test::utils::EltwiseTypes; + +std::vector> in_shapes_static = { {{2}}, {{2, 200}}, {{10, 200}}, @@ -29,103 +32,103 @@ std::vector> inShapesStatic = { {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}, }; -std::vector> inShapesStaticCheckCollapse = { +std::vector> in_shapes_static_check_collapse = { {{16, 16, 16, 16}, {16, 16, 16, 1}}, {{16, 16, 16, 1}, {16, 16, 16, 1}}, {{16, 16, 16, 16}, {16, 16, 1, 16}}, {{16, 16, 1, 16}, {16, 16, 1, 16}}, }; -std::vector> inShapesDynamic = { +std::vector> in_shapes_dynamic = { {{{ngraph::Dimension(1, 10), 200}, {{2, 200}, {1, 200}}}, {{ngraph::Dimension(1, 10), 200}, {{2, 200}, {5, 200}}}}, }; -std::vector> inShapesDynamicLargeUpperBound = { +std::vector> in_shapes_dynamic_large_upper_bound = { {{{ngraph::Dimension(1, 1000000000000), 200}, {{2, 200}, {5, 200}}}}, }; -std::vector netPrecisions = { +std::vector model_types = { ov::element::f32, ov::element::f16, ov::element::i32, }; -std::vector secondaryInputTypes = { - ngraph::helpers::InputLayerType::CONSTANT, - ngraph::helpers::InputLayerType::PARAMETER, +std::vector secondary_input_types = { + InputLayerType::CONSTANT, + InputLayerType::PARAMETER, }; -std::vector secondaryInputTypesDynamic = { - ngraph::helpers::InputLayerType::PARAMETER, +std::vector secondary_input_types_dynamic = { + InputLayerType::PARAMETER, }; -std::vector opTypes = { - ov::test::utils::OpType::SCALAR, - ov::test::utils::OpType::VECTOR, +std::vector op_types = { + OpType::SCALAR, + OpType::VECTOR, }; -std::vector opTypesDynamic = { - ov::test::utils::OpType::VECTOR, +std::vector op_types_dynamic = { + OpType::VECTOR, }; -std::vector eltwiseOpTypes = { - ngraph::helpers::EltwiseTypes::ADD, - ngraph::helpers::EltwiseTypes::MULTIPLY, - ngraph::helpers::EltwiseTypes::SUBTRACT, - ngraph::helpers::EltwiseTypes::DIVIDE, - ngraph::helpers::EltwiseTypes::FLOOR_MOD, - ngraph::helpers::EltwiseTypes::SQUARED_DIFF, - ngraph::helpers::EltwiseTypes::POWER, - ngraph::helpers::EltwiseTypes::MOD +std::vector eltwise_op_types = { + EltwiseTypes::ADD, + EltwiseTypes::MULTIPLY, + EltwiseTypes::SUBTRACT, + EltwiseTypes::DIVIDE, + EltwiseTypes::FLOOR_MOD, + EltwiseTypes::SQUARED_DIFF, + EltwiseTypes::POWER, + EltwiseTypes::MOD }; -std::vector eltwiseOpTypesDynamic = { - ngraph::helpers::EltwiseTypes::ADD, - ngraph::helpers::EltwiseTypes::MULTIPLY, - ngraph::helpers::EltwiseTypes::SUBTRACT, +std::vector eltwise_op_types_dynamic = { + EltwiseTypes::ADD, + EltwiseTypes::MULTIPLY, + EltwiseTypes::SUBTRACT, }; ov::test::Config additional_config = {}; const auto multiply_params = ::testing::Combine( - ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesStatic)), - ::testing::ValuesIn(eltwiseOpTypes), - ::testing::ValuesIn(secondaryInputTypes), - ::testing::ValuesIn(opTypes), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_static)), + ::testing::ValuesIn(eltwise_op_types), + ::testing::ValuesIn(secondary_input_types), + ::testing::ValuesIn(op_types), + ::testing::ValuesIn(model_types), ::testing::Values(ov::element::undefined), ::testing::Values(ov::element::undefined), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); const auto collapsing_params = ::testing::Combine( - ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesStaticCheckCollapse)), - ::testing::ValuesIn(eltwiseOpTypes), - ::testing::ValuesIn(secondaryInputTypes), - ::testing::Values(opTypes[1]), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_static_check_collapse)), + ::testing::ValuesIn(eltwise_op_types), + ::testing::ValuesIn(secondary_input_types), + ::testing::Values(op_types[1]), + ::testing::ValuesIn(model_types), ::testing::Values(ov::element::undefined), ::testing::Values(ov::element::undefined), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); const auto multiply_params_dynamic = ::testing::Combine( - ::testing::ValuesIn(inShapesDynamic), - ::testing::ValuesIn(eltwiseOpTypesDynamic), - ::testing::ValuesIn(secondaryInputTypesDynamic), - ::testing::ValuesIn(opTypesDynamic), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(in_shapes_dynamic), + ::testing::ValuesIn(eltwise_op_types_dynamic), + ::testing::ValuesIn(secondary_input_types_dynamic), + ::testing::ValuesIn(op_types_dynamic), + ::testing::ValuesIn(model_types), ::testing::Values(ov::element::undefined), ::testing::Values(ov::element::undefined), ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::Values(additional_config)); const auto multiply_params_dynamic_large_upper_bound = ::testing::Combine( - ::testing::ValuesIn(inShapesDynamicLargeUpperBound), - ::testing::Values(ngraph::helpers::EltwiseTypes::ADD), - ::testing::ValuesIn(secondaryInputTypesDynamic), - ::testing::ValuesIn(opTypesDynamic), + ::testing::ValuesIn(in_shapes_dynamic_large_upper_bound), + ::testing::Values(EltwiseTypes::ADD), + ::testing::ValuesIn(secondary_input_types_dynamic), + ::testing::ValuesIn(op_types_dynamic), ::testing::Values(ov::element::f32), ::testing::Values(ov::element::undefined), ::testing::Values(ov::element::undefined), @@ -147,9 +150,9 @@ std::vector> inShapesSingleThread = { {{2, 1, 2, 1, 2, 2}}, }; -std::vector eltwiseOpTypesSingleThread = { - ngraph::helpers::EltwiseTypes::ADD, - ngraph::helpers::EltwiseTypes::POWER, +std::vector eltwise_op_typesSingleThread = { + EltwiseTypes::ADD, + EltwiseTypes::POWER, }; ov::AnyMap additional_config_single_thread = { @@ -158,10 +161,10 @@ ov::AnyMap additional_config_single_thread = { const auto single_thread_params = ::testing::Combine( ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShapesSingleThread)), - ::testing::ValuesIn(eltwiseOpTypesSingleThread), - ::testing::ValuesIn(secondaryInputTypes), - ::testing::ValuesIn(opTypes), - ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(eltwise_op_typesSingleThread), + ::testing::ValuesIn(secondary_input_types), + ::testing::ValuesIn(op_types), + ::testing::ValuesIn(model_types), ::testing::Values(ov::element::undefined), ::testing::Values(ov::element::undefined), ::testing::Values(ov::test::utils::DEVICE_CPU), diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 9c8bfc2a7b0d68..0d6f932e000b5e 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -195,6 +195,8 @@ std::vector disabledTestPatterns() { R"(.*smoke_TopK/TopKLayerTest.Inference.*_k=7_axis=3_.*_modelType=f16_trgDev=CPU.*)", R"(.*smoke_TopK/TopKLayerTest.Inference.*_k=18_.*_modelType=f16_trgDev=CPU.*)", R"(.*smoke_TopK/TopKLayerTest.Inference.*_k=21_.*_sort=value_modelType=f16_trgDev=CPU.*)", + // Issue: 121228 + R"(smoke_TestsDFT_(1|2|3|4)d/DFTLayerTest.Inference.*bf16.*)", }; #if defined(__APPLE__) && defined(OPENVINO_ARCH_ARM64) // Issue: 120950 @@ -238,6 +240,7 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(smoke_ExecGraph/ExecGraphRuntimePrecision.CheckRuntimePrecision/Function=(EltwiseWithTwoDynamicInputs|FakeQuantizeRelu).*)"); // Issue 108803: bug in CPU scalar implementation retVector.emplace_back(R"(smoke_TestsDFT_(1|2|3|4)d/DFTLayerTest.CompareWithRefs.*)"); + retVector.emplace_back(R"(smoke_TestsDFT_(1|2|3|4)d/DFTLayerTest.Inference.*)"); // Issue 88764, 91647, 108802: accuracy issue retVector.emplace_back(R"(MultipleLSTMCellTest/MultipleLSTMCellTest.CompareWithRefs.*)"); // int8 / code-generation specific diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/detection_output.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/detection_output.hpp new file mode 100644 index 00000000000000..0eb0ca2bd36e1b --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/detection_output.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/detection_output.hpp" + +namespace ov { +namespace test { +TEST_P(DetectionOutputLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/dft.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/dft.hpp new file mode 100644 index 00000000000000..b6b1400dc4b6a2 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/dft.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/dft.hpp" + +namespace ov { +namespace test { +TEST_P(DFTLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/eltwise.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/eltwise.hpp new file mode 100644 index 00000000000000..1add45da7fb42a --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/eltwise.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/eltwise.hpp" + +namespace ov { +namespace test { +TEST_P(EltwiseLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp index 32d585c449b89c..17121e8a57aff3 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/ranges.hpp @@ -20,6 +20,9 @@ #include "ngraph/op/max.hpp" #include "ngraph/op/min.hpp" +#include "openvino/op/dft.hpp" +#include "openvino/op/idft.hpp" + #include #include @@ -82,6 +85,8 @@ static std::map>> i { ov::op::v4::Proposal::get_type_info_static(), {{{0, 1, 1000, 8234231}}, {{0, 1, 1000, 8234231}}} }, { ov::op::v4::ReduceL1::get_type_info_static(), {{{0, 5}}, {{0, 5, 1000}}} }, { ov::op::v4::ReduceL2::get_type_info_static(), {{{0, 5}}, {{0, 5, 1000}}} }, + { ov::op::v7::DFT::get_type_info_static(), {{{0, 1}}, {{0, 1, 1000000}}} }, + { ov::op::v7::IDFT::get_type_info_static(), {{{0, 1}}, {{0, 1, 1000000}}} }, }; } // namespace utils diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/detection_output.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/detection_output.hpp new file mode 100644 index 00000000000000..6c8da15babdd98 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/detection_output.hpp @@ -0,0 +1,73 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "openvino/op/detection_output.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +using Attributes = ov::op::v0::DetectionOutput::Attributes; + +std::ostream& operator <<(std::ostream& os, const Attributes& inputShape); + +enum { + idxLocation, + idxConfidence, + idxPriors, + idxArmConfidence, + idxArmLocation, + numInputs +}; + +using DetectionOutputAttributes = std::tuple< + int, // numClasses + int, // backgroundLabelId + int, // topK + std::vector, // keepTopK + std::string, // codeType + float, // nmsThreshold + float, // confidenceThreshold + bool, // clip_afterNms + bool, // clip_beforeNms + bool // decreaseLabelId +>; + +using ParamsWhichSizeDepends = std::tuple< + bool, // varianceEncodedInTarget + bool, // shareLocation + bool, // normalized + size_t, // inputHeight + size_t, // inputWidth + ov::Shape, // "Location" input + ov::Shape, // "Confidence" input + ov::Shape, // "Priors" input + ov::Shape, // "ArmConfidence" input + ov::Shape // "ArmLocation" input +>; + +using DetectionOutputParams = std::tuple< + DetectionOutputAttributes, + ParamsWhichSizeDepends, + size_t, // Number of batch + float, // objectnessScore + std::string // Device name +>; + +class DetectionOutputLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { + public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/dft.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/dft.hpp new file mode 100644 index 00000000000000..4160a36c2e1f9e --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/dft.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "common_test_utils/test_enums.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Input shapes + ov::element::Type, // Model type + std::vector, // Axes + std::vector, // Signal size + ov::test::utils::DFTOpType, + std::string> DFTParams; // Device name + +class DFTLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eltwise.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eltwise.hpp new file mode 100644 index 00000000000000..3cd66acdb8a524 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/eltwise.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +// NOTE: WILL BE REWORKED (31905) + +#pragma once + +#include "common_test_utils/test_enums.hpp" +#include "common_test_utils/common_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // input shapes + ov::test::utils::EltwiseTypes, // eltwise op type + ov::test::utils::InputLayerType, // secondary input type + ov::test::utils::OpType, // op type + ElementType, // Model type + ElementType, // In type + ElementType, // Out type + TargetDevice, // Device name + ov::AnyMap // Additional network configuration +> EltwiseTestParams; + +class EltwiseLayerTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +protected: + void SetUp() override; + +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +private: + void transformInputShapesAccordingEltwise(const ov::PartialShape& secondInputShape); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/detection_output.cpp b/src/tests/functional/shared_test_classes/src/single_op/detection_output.cpp new file mode 100644 index 00000000000000..ac0938643c7292 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/detection_output.cpp @@ -0,0 +1,116 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/detection_output.hpp" + +namespace ov { +namespace test { +std::ostream& operator <<(std::ostream& result, const Attributes& attrs) { + result << "Classes=" << attrs.num_classes << "_"; + result << "backgrId=" << attrs.background_label_id << "_"; + result << "topK=" << attrs.top_k << "_"; + result << "varEnc=" << attrs.variance_encoded_in_target << "_"; + result << "keepTopK=" << ov::test::utils::vec2str(attrs.keep_top_k) << "_"; + result << "codeType=" << attrs.code_type << "_"; + result << "shareLoc=" << attrs.share_location << "_"; + result << "nmsThr=" << attrs.nms_threshold << "_"; + result << "confThr=" << attrs.confidence_threshold << "_"; + result << "clipAfterNms=" << attrs.clip_after_nms << "_"; + result << "clipBeforeNms=" << attrs.clip_before_nms << "_"; + result << "decrId=" << attrs.decrease_label_id << "_"; + result << "norm=" << attrs.normalized << "_"; + result << "inH=" << attrs.input_height << "_"; + result << "inW=" << attrs.input_width << "_"; + result << "OS=" << attrs.objectness_score << "_"; + return result; +} + +std::string DetectionOutputLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + DetectionOutputAttributes common_attrs; + ParamsWhichSizeDepends specific_attrs; + Attributes attrs; + size_t batch; + std::string targetDevice; + std::tie(common_attrs, specific_attrs, batch, attrs.objectness_score, targetDevice) = obj.param; + + std::tie(attrs.num_classes, attrs.background_label_id, attrs.top_k, attrs.keep_top_k, attrs.code_type, attrs.nms_threshold, attrs.confidence_threshold, + attrs.clip_after_nms, attrs.clip_before_nms, attrs.decrease_label_id) = common_attrs; + + const size_t numInputs = 5; + std::vector input_shapes(numInputs); + std::tie(attrs.variance_encoded_in_target, attrs.share_location, attrs.normalized, attrs.input_height, attrs.input_width, + input_shapes[idxLocation], input_shapes[idxConfidence], input_shapes[idxPriors], input_shapes[idxArmConfidence], + input_shapes[idxArmLocation]) = specific_attrs; + + if (input_shapes[idxArmConfidence].empty()) { + input_shapes.resize(3); + } + + for (size_t i = 0; i < input_shapes.size(); i++) { + input_shapes[i][0] = batch; + } + + std::ostringstream result; + result << "IS = { "; + result << "LOC=" << ov::test::utils::vec2str(input_shapes[0]) << "_"; + result << "CONF=" << ov::test::utils::vec2str(input_shapes[1]) << "_"; + result << "PRIOR=" << ov::test::utils::vec2str(input_shapes[2]); + std::string armConf, armLoc; + if (input_shapes.size() > 3) { + armConf = "_ARM_CONF=" + ov::test::utils::vec2str(input_shapes[3]) + "_"; + armLoc = "ARM_LOC=" + ov::test::utils::vec2str(input_shapes[4]); + } + result << armConf; + result << armLoc << " }_"; + + result << attrs; + result << "TargetDevice=" << targetDevice; + return result.str(); +} + +void DetectionOutputLayerTest::SetUp() { + DetectionOutputAttributes common_attrs; + ParamsWhichSizeDepends specific_attrs; + size_t batch; + Attributes attrs; + std::tie(common_attrs, specific_attrs, batch, attrs.objectness_score, targetDevice) = this->GetParam(); + + std::tie(attrs.num_classes, attrs.background_label_id, attrs.top_k, attrs.keep_top_k, attrs.code_type, attrs.nms_threshold, attrs.confidence_threshold, + attrs.clip_after_nms, attrs.clip_before_nms, attrs.decrease_label_id) = common_attrs; + + std::vector input_shapes; + input_shapes.resize(numInputs); + std::tie(attrs.variance_encoded_in_target, attrs.share_location, attrs.normalized, attrs.input_height, attrs.input_width, + input_shapes[idxLocation], input_shapes[idxConfidence], input_shapes[idxPriors], input_shapes[idxArmConfidence], + input_shapes[idxArmLocation]) = specific_attrs; + + if (input_shapes[idxArmConfidence].empty()) { + input_shapes.resize(3); + } + + for (size_t i = 0; i < input_shapes.size(); i++) { + input_shapes[i][0] = batch; + } + init_input_shapes(static_shapes_to_test_representation(input_shapes)); + + ov::ParameterVector params; + for (const auto& shape : inputDynamicShapes) { + params.push_back(std::make_shared(ov::element::f32, shape)); + } + + std::shared_ptr det_out; + if (params.size() == 3) + det_out = std::make_shared(params[0], params[1], params[2], attrs); + else if (params.size() == 5) + det_out = std::make_shared(params[0], + params[1], + params[2], + params[3], + params[4], + attrs); + auto result = std::make_shared(det_out); + function = std::make_shared(result, params, "DetectionOutput"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/dft.cpp b/src/tests/functional/shared_test_classes/src/single_op/dft.cpp new file mode 100644 index 00000000000000..9d39ed7bea6c66 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/dft.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/dft.hpp" + +#include "ngraph_functions/builders.hpp" + +namespace ov { +namespace test { +std::string DFTLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ov::element::Type model_type; + std::vector axes; + std::vector signal_size; + ov::test::utils::DFTOpType op_type; + std::string target_device; + std::tie(shapes, model_type, axes, signal_size, op_type, target_device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "Precision=" << model_type.get_type_name() << "_"; + result << "Axes=" << ov::test::utils::vec2str(axes) << "_"; + result << "signal_size=" << ov::test::utils::vec2str(signal_size) << "_"; + result << "Inverse=" << (op_type == ov::test::utils::DFTOpType::INVERSE) << "_"; + result << "TargetDevice=" << target_device; + return result.str(); +} + +void DFTLayerTest::SetUp() { + std::vector shapes; + ov::element::Type model_type; + std::vector axes; + std::vector signal_size; + ov::test::utils::DFTOpType op_type; + std::tie(shapes, model_type, axes, signal_size, op_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto dft = ngraph::builder::makeDFT(param, axes, signal_size, op_type); + + auto result = std::make_shared(dft); + function = std::make_shared(result, ov::ParameterVector{param}, "DFT"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp b/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp new file mode 100644 index 00000000000000..1297379c267a7e --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/eltwise.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_test_utils/ov_tensor_utils.hpp" + +#include "shared_test_classes/single_op/eltwise.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "ngraph_functions/builders.hpp" + +namespace ov { +namespace test { +using ov::test::utils::InputLayerType; +using ov::test::utils::OpType; +using ov::test::utils::EltwiseTypes; + +std::string EltwiseLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector shapes; + ElementType model_type, in_type, out_type; + InputLayerType secondary_input_type; + OpType op_type; + EltwiseTypes eltwise_op_type; + std::string device_name; + ov::AnyMap additional_config; + std::tie(shapes, eltwise_op_type, secondary_input_type, op_type, model_type, in_type, out_type, device_name, additional_config) = obj.param; + std::ostringstream results; + + results << "IS=("; + for (const auto& shape : shapes) { + results << ov::test::utils::partialShape2str({shape.first}) << "_"; + } + results << ")_TS=("; + for (const auto& shape : shapes) { + for (const auto& item : shape.second) { + results << ov::test::utils::vec2str(item) << "_"; + } + } + results << ")_eltwise_op_type=" << eltwise_op_type << "_"; + results << "secondary_input_type=" << secondary_input_type << "_"; + results << "opType=" << op_type << "_"; + results << "model_type=" << model_type << "_"; + results << "InType=" << in_type << "_"; + results << "OutType=" << out_type << "_"; + results << "trgDev=" << device_name; + for (auto const& config_item : additional_config) { + results << "_config_item=" << config_item.first << "="; + config_item.second.print(results); + } + return results.str(); +} + +void EltwiseLayerTest::transformInputShapesAccordingEltwise(const ov::PartialShape& secondInputShape) { + // propagate shapes in case 1 shape is defined + if (inputDynamicShapes.size() == 1) { + inputDynamicShapes.push_back(inputDynamicShapes.front()); + for (auto& staticShape : targetStaticShapes) { + staticShape.push_back(staticShape.front()); + } + } + ASSERT_EQ(inputDynamicShapes.size(), 2) << "Incorrect inputs number!"; + if (!secondInputShape.is_static()) { + return; + } + if (secondInputShape.get_shape() == ov::Shape{1}) { + inputDynamicShapes[1] = secondInputShape; + for (auto& staticShape : targetStaticShapes) { + staticShape[1] = secondInputShape.get_shape(); + } + } +} + +void EltwiseLayerTest::SetUp() { + std::vector shapes; + ElementType model_type; + InputLayerType secondary_input_type; + OpType op_type; + EltwiseTypes eltwise_type; + Config additional_config; + std::tie(shapes, eltwise_type, secondary_input_type, op_type, model_type, inType, outType, targetDevice, configuration) = this->GetParam(); + init_input_shapes(shapes); + + ov::ParameterVector parameters{std::make_shared(model_type, inputDynamicShapes.front())}; + + ov::PartialShape shape_input_secondary; + switch (op_type) { + case OpType::SCALAR: { + shape_input_secondary = {1}; + break; + } + case OpType::VECTOR: + shape_input_secondary = inputDynamicShapes.back(); + break; + default: + FAIL() << "Unsupported Secondary operation type"; + } + // To propagate shape_input_secondary just in static case because all shapes are defined in dynamic scenarion + if (secondary_input_type == InputLayerType::PARAMETER) { + transformInputShapesAccordingEltwise(shape_input_secondary); + } + + std::shared_ptr secondary_input; + if (secondary_input_type == InputLayerType::PARAMETER) { + auto param = std::make_shared(model_type, shape_input_secondary); + secondary_input = param; + parameters.push_back(param); + } else { + ov::Shape shape = inputDynamicShapes.back().get_max_shape(); + switch (eltwise_type) { + case EltwiseTypes::DIVIDE: + case EltwiseTypes::MOD: + case EltwiseTypes::FLOOR_MOD: { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, shape, 8, 2); + secondary_input = std::make_shared(tensor); + break; + } + case EltwiseTypes::POWER: { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, shape, 2, 1); + secondary_input = std::make_shared(tensor); + break; + } + default: { + auto tensor = ov::test::utils::create_and_fill_tensor(model_type, shape, 9, 1); + secondary_input = std::make_shared(tensor); + } + } + } + + parameters[0]->set_friendly_name("param0"); + secondary_input->set_friendly_name("param1"); + + auto eltwise = ngraph::builder::makeEltwise(parameters[0], secondary_input, eltwise_type); + function = std::make_shared(eltwise, parameters, "Eltwise"); +} +} // namespace test +} // namespace ov From efb8484124f3c05e401d9df6189731426e46fe40 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Fri, 22 Sep 2023 14:38:24 +0200 Subject: [PATCH 26/43] [core] Api 2.0/migrate swish op to new API (#19934) * Migrate Swish operator to new API * Remove `visit_attributes` as is same in base class --- src/core/include/openvino/op/swish.hpp | 5 +- .../include/openvino/reference/swish.hpp | 24 ++-- src/core/src/op/swish.cpp | 134 ++++++++---------- 3 files changed, 73 insertions(+), 90 deletions(-) diff --git a/src/core/include/openvino/op/swish.hpp b/src/core/include/openvino/op/swish.hpp index bc9935d7f3e88f..d9bb1381a82194 100644 --- a/src/core/include/openvino/op/swish.hpp +++ b/src/core/include/openvino/op/swish.hpp @@ -27,13 +27,10 @@ class OPENVINO_API Swish : public Op { Swish(const Output& arg, const Output& beta); explicit Swish(const Output& arg); - bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; }; } // namespace v4 diff --git a/src/core/reference/include/openvino/reference/swish.hpp b/src/core/reference/include/openvino/reference/swish.hpp index 99d1b9fe273e9c..775e18af28226f 100644 --- a/src/core/reference/include/openvino/reference/swish.hpp +++ b/src/core/reference/include/openvino/reference/swish.hpp @@ -4,20 +4,26 @@ #pragma once +#include #include #include namespace ov { namespace reference { -template -void swish(const T* arg, const T* beta, T* out, size_t count) { - T beta_value = static_cast(1.0); - if (beta != nullptr) { - beta_value = beta[0]; - } - for (size_t i = 0; i < count; i++) { - out[i] = static_cast(arg[i] / (1.0 + std::exp(-arg[i] * beta_value))); - } + +/** + * @brief Reference implementation of Swish operator. + * + * @param arg Input pointer to data. + * @param beta Beta parameter value. + * @param out Output pointer to results. + * @param count Number of elements in input buffer. + */ +template +void swish(const T* arg, const T beta, T* out, const size_t count) { + std::transform(arg, arg + count, out, [beta](const T v) { + return static_cast(v / (1.0 + std::exp(-v * beta))); + }); } } // namespace reference } // namespace ov diff --git a/src/core/src/op/swish.cpp b/src/core/src/op/swish.cpp index b6f2e91be3400a..ccc3d82b682137 100644 --- a/src/core/src/op/swish.cpp +++ b/src/core/src/op/swish.cpp @@ -2,37 +2,46 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/swish.hpp" - -#include +#include "openvino/op/swish.hpp" +#include "compare.hpp" +#include "element_visitor.hpp" #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/runtime/host_tensor.hpp" +#include "openvino/core/attribute_visitor.hpp" #include "openvino/reference/swish.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace swish { +constexpr auto has_1_or_2_inputs = ov::cmp::Between(0, 3); -op::v4::Swish::Swish(const Output& arg) : Op({arg}) { - constructor_validate_and_infer_types(); -} +struct Evaluate : element::NoAction { + using element::NoAction::visit; -op::v4::Swish::Swish(const Output& arg, const Output& beta) : Op({arg, beta}) { + template + static result_type visit(const Tensor& arg0, const Tensor& arg1, Tensor& out, const size_t count) { + using T = typename element_type_traits::value_type; + reference::swish(arg0.data(), arg1 ? *arg1.data() : T{1.0}, out.data(), count); + return true; + } +}; +} // namespace swish + +namespace v4 { +Swish::Swish(const Output& arg) : Op({arg}) { constructor_validate_and_infer_types(); } -bool op::v4::Swish::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v4_Swish_visit_attributes); - return true; +Swish::Swish(const Output& arg, const Output& beta) : Op({arg, beta}) { + constructor_validate_and_infer_types(); } -void op::v4::Swish::validate_and_infer_types() { +void Swish::validate_and_infer_types() { OV_OP_SCOPE(v4_Swish_validate_and_infer_types); - auto inputs_count = input_values().size(); + + const auto inputs_count = input_values().size(); NODE_VALIDATION_CHECK(this, - inputs_count == 1 || inputs_count == 2, + swish::has_1_or_2_inputs(inputs_count), "Swish must have 1 or 2 inputs, but it has: ", inputs_count); @@ -50,81 +59,52 @@ void op::v4::Swish::validate_and_infer_types() { input_value(0).get_element_type(), " and ", input_value(1).get_element_type()); - if (get_input_partial_shape(1).rank().is_static()) { - auto beta_rank = get_input_partial_shape(1).rank().get_length(); - NODE_VALIDATION_CHECK(this, - beta_rank == 0, - "Swish input with beta must be scalar but it has rank: ", - beta_rank); - } + + const auto beta_rank = get_input_partial_shape(1).rank(); + NODE_VALIDATION_CHECK(this, + beta_rank.compatible(0), + "Swish input with beta must be scalar but it has rank: ", + beta_rank); } - set_output_size(1); + set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } -shared_ptr op::v4::Swish::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr Swish::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v4_Swish_clone_with_new_inputs); if (new_args.size() == 1) { - return make_shared(new_args.at(0)); + return std::make_shared(new_args.at(0)); } else { - return make_shared(new_args.at(0), new_args.at(1)); + return std::make_shared(new_args.at(0), new_args.at(1)); } } -OPENVINO_SUPPRESS_DEPRECATED_START -namespace swish { -namespace { -template -inline bool evaluate(const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& out, - const size_t count) { - using T = typename element_type_traits::value_type; - if (arg1 != nullptr) { - ov::reference::swish(arg0->get_data_ptr(), arg1->get_data_ptr(), out->get_data_ptr(), count); - } else { - ov::reference::swish(arg0->get_data_ptr(), nullptr, out->get_data_ptr(), count); - } - return true; -} - -bool evaluate_swish(const HostTensorVector& inputs, const HostTensorPtr& out) { - bool rc = true; - size_t count = shape_size(inputs[0]->get_shape()); - - const HostTensorPtr arg0 = inputs[0]; - const HostTensorPtr arg1 = inputs.size() == 2 ? inputs[1] : nullptr; - out->set_unary(arg0); - - switch (arg0->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_swish, f16, arg0, arg1, out, count); - NGRAPH_TYPE_CASE(evaluate_swish, f32, arg0, arg1, out, count); - default: - rc = false; - break; - } - return rc; -} -} // namespace -} // namespace swish - -bool op::v4::Swish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool Swish::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v4_Swish_evaluate); - OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && - (validate_host_tensor_vector(inputs, 2) || validate_host_tensor_vector(inputs, 1))); - OPENVINO_SUPPRESS_DEPRECATED_END - return swish::evaluate_swish(inputs, outputs[0]); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(swish::has_1_or_2_inputs(inputs.size())); + + outputs[0].set_shape(inputs[0].get_shape()); + const auto& arg1 = inputs.size() == 2 ? inputs[1] : Tensor(); + + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + arg1, + outputs[0], + shape_size(inputs[0].get_shape())); } -bool op::v4::Swish::has_evaluate() const { +bool Swish::has_evaluate() const { OV_OP_SCOPE(v4_Swish_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::f16: - case ngraph::element::f32: + case element::f16: + case element::f32: return true; default: - break; + return false; } - return false; } +} // namespace v4 +} // namespace op +} // namespace ov From 93f2a1947c1744168a87f2aa5b4a100554f76c52 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Fri, 22 Sep 2023 20:41:32 +0200 Subject: [PATCH 27/43] Reduce binary size of CumSum implementation (#20004) --- .../include/openvino/reference/cum_sum.hpp | 15 +-- src/core/src/op/cum_sum.cpp | 114 ++++++++---------- src/plugins/template/backend/ops/cum_sum.cpp | 2 +- 3 files changed, 57 insertions(+), 74 deletions(-) diff --git a/src/core/reference/include/openvino/reference/cum_sum.hpp b/src/core/reference/include/openvino/reference/cum_sum.hpp index df517f0f7b71d4..24c9d543d9fe21 100644 --- a/src/core/reference/include/openvino/reference/cum_sum.hpp +++ b/src/core/reference/include/openvino/reference/cum_sum.hpp @@ -10,18 +10,13 @@ namespace ov { namespace reference { template -void cumsum(const T* arg, - const P* axis_tensor, - T* out, - const Shape& tensor_shape, - const bool exclusive, - const bool reverse) { +void cumsum(const T* arg, const P axis, T* out, const Shape& tensor_shape, const bool exclusive, const bool reverse) { const auto rank = tensor_shape.size(); - const auto axis = axis_tensor[0] >= 0 ? axis_tensor[0] : rank + axis_tensor[0]; - const auto axis_dim = tensor_shape[axis]; + const auto normalized_axis = axis >= 0 ? axis : rank + axis; + const auto axis_dim = tensor_shape[normalized_axis]; - const auto size_before_axis = shape_size(Shape(tensor_shape.begin(), tensor_shape.begin() + axis)); - const auto size_after_axis = shape_size(Shape(tensor_shape.begin() + axis + 1, tensor_shape.end())); + const auto size_before_axis = shape_size(tensor_shape.begin(), tensor_shape.begin() + normalized_axis); + const auto size_after_axis = shape_size(tensor_shape.begin() + normalized_axis + 1, tensor_shape.end()); const auto reverse_shift = reverse ? -1 : 1; const auto element_shift = exclusive ? size_after_axis * reverse_shift : 0; diff --git a/src/core/src/op/cum_sum.cpp b/src/core/src/op/cum_sum.cpp index 9cfb94a13eceb4..774e2be80c8fbc 100644 --- a/src/core/src/op/cum_sum.cpp +++ b/src/core/src/op/cum_sum.cpp @@ -4,36 +4,70 @@ #include "openvino/op/cum_sum.hpp" +#include "element_visitor.hpp" #include "itt.hpp" #include "openvino/core/attribute_visitor.hpp" #include "openvino/op/constant.hpp" #include "openvino/reference/cum_sum.hpp" - -using namespace std; +#include "utils.hpp" namespace ov { -op::v0::CumSum::CumSum(const Output& arg, const Output& axis, const bool exclusive, const bool reverse) +namespace op { +namespace cumsum { +struct Evaluate : ov::element::NoAction { + using ov::element::NoAction::visit; + + template + static result_type visit(const Tensor& in0, + Tensor& out, + const int64_t axis, + const bool exclusive, + const bool reverse) { + using T = typename element_type_traits::value_type; + reference::cumsum(in0.data(), axis, out.data(), in0.get_shape(), exclusive, reverse); + return true; + } +}; + +namespace { +bool evaluate(TensorVector& outputs, const TensorVector& inputs, const bool exclusive, const bool reverse) { + outputs[0].set_shape(inputs[0].get_shape()); + const auto axis = ov::get_tensor_data_as(inputs[1]).front(); + + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + outputs[0], + axis, + exclusive, + reverse); +} +} // namespace +} // namespace cumsum + +namespace v0 { +CumSum::CumSum(const Output& arg, const Output& axis, const bool exclusive, const bool reverse) : Op({arg, axis}), m_exclusive(exclusive), m_reverse(reverse) { constructor_validate_and_infer_types(); } -op::v0::CumSum::CumSum(const Output& arg, const bool exclusive, const bool reverse) +CumSum::CumSum(const Output& arg, const bool exclusive, const bool reverse) : Op({arg, op::v0::Constant::create(element::i32, Shape{}, {0})}), m_exclusive(exclusive), m_reverse(reverse) { constructor_validate_and_infer_types(); } -bool op::v0::CumSum::visit_attributes(AttributeVisitor& visitor) { +bool CumSum::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_CumSum_visit_attributes); visitor.on_attribute("exclusive", m_exclusive); visitor.on_attribute("reverse", m_reverse); return true; } -void op::v0::CumSum::validate_and_infer_types() { +void CumSum::validate_and_infer_types() { OV_OP_SCOPE(v0_CumSum_validate_and_infer_types); set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); @@ -47,76 +81,30 @@ void op::v0::CumSum::validate_and_infer_types() { // No axis input shape check for backward compatibility } -shared_ptr op::v0::CumSum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr CumSum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_CumSum_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 2) - return make_shared(new_args.at(0), new_args.at(1), m_exclusive, m_reverse); + return std::make_shared(new_args.at(0), new_args.at(1), m_exclusive, m_reverse); else { - return make_shared(new_args.at(0), m_exclusive, m_reverse); + return std::make_shared(new_args.at(0), m_exclusive, m_reverse); } } -namespace { -template -bool evaluate_cum_sum(TensorVector& outputs, const TensorVector& inputs, const bool exclusive, const bool reverse) { - using data_t = fundamental_type_for; - using axis_t = fundamental_type_for; - ov::reference::cumsum(inputs[0].data(), - inputs[1].data(), - outputs[0].data(), - inputs[0].get_shape(), - exclusive, - reverse); - return true; -} - -#define CUM_SUM_TYPE_CASE(a, ...) \ - case element::Type_t::a: { \ - OV_OP_SCOPE(OV_PP_CAT4(evaluate_cum_sum, _, a, AXIS_ET)); \ - return evaluate_cum_sum(__VA_ARGS__); \ - } - -template -bool evaluate(TensorVector& outputs, const TensorVector& inputs, const bool exclusive, const bool reverse) { - switch (inputs[0].get_element_type()) { - CUM_SUM_TYPE_CASE(f32, outputs, inputs, exclusive, reverse); - default: - return false; - } -} - -bool evaluate_cum_sum(TensorVector& outputs, const TensorVector& inputs, const bool exclusive, const bool reverse) { - auto rc = true; - switch (inputs[1].get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_cum_sum, i32, outputs, inputs, exclusive, reverse); - NGRAPH_TYPE_CASE(evaluate_cum_sum, i64, outputs, inputs, exclusive, reverse); - default: - rc = false; - break; - } - return rc; -} -} // namespace - -bool op::v0::CumSum::evaluate(TensorVector& outputs, const TensorVector& inputs) const { +bool CumSum::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v0_CumSum_evaluate); - OPENVINO_ASSERT(inputs.size() == 2, - "Invalid size of inputs argument of evaluate method of CumSum operation. Provided: ", - inputs.size(), - ". Expected: 2"); - OPENVINO_ASSERT(outputs.size() == 1, - "Invalid size of outputs argument of evaluate method of CumSum operation. Provided: ", - outputs.size(), - ". Expected: 1"); - - return evaluate_cum_sum(outputs, inputs, is_exclusive(), is_reverse()); + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 2); + + return cumsum::evaluate(outputs, inputs, is_exclusive(), is_reverse()); } -bool op::v0::CumSum::has_evaluate() const { +bool CumSum::has_evaluate() const { OV_OP_SCOPE(v0_CumSum_has_evaluate); const auto& input_0_et = get_input_element_type(0); const auto& input_1_et = get_input_element_type(1); return input_0_et == element::f32 && (input_1_et == element::i32 || input_1_et == element::i64); } +} // namespace v0 +} // namespace op } // namespace ov diff --git a/src/plugins/template/backend/ops/cum_sum.cpp b/src/plugins/template/backend/ops/cum_sum.cpp index 06dc952b233fe7..b855d368731096 100644 --- a/src/plugins/template/backend/ops/cum_sum.cpp +++ b/src/plugins/template/backend/ops/cum_sum.cpp @@ -15,7 +15,7 @@ inline void evaluate(const std::shared_ptr& op, using T1 = typename ov::element_type_traits::value_type; using T2 = typename ov::element_type_traits::value_type; ov::reference::cumsum(inputs[0].data(), - inputs[1].data(), + *inputs[1].data(), outputs[0].data(), inputs[0].get_shape(), op->is_exclusive(), From f735999e7bdd656f9689c02e45ac203b63d58787 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Fri, 22 Sep 2023 22:10:33 +0200 Subject: [PATCH 28/43] Improve testing for hf models (#20017) --- .../models_hub_common/constants.py | 16 +- .../torch_tests/hf_transformers_models | 46 ++-- .../torch_tests/requirements.txt | 1 + .../torch_tests/test_transformers.py | 232 ++++++++++-------- 4 files changed, 157 insertions(+), 138 deletions(-) diff --git a/tests/model_hub_tests/models_hub_common/constants.py b/tests/model_hub_tests/models_hub_common/constants.py index 6fc8a7ec6215a2..01c1d9a1382afd 100644 --- a/tests/model_hub_tests/models_hub_common/constants.py +++ b/tests/model_hub_tests/models_hub_common/constants.py @@ -5,17 +5,13 @@ import os import tempfile -if os.environ.get('TFHUB_CACHE_DIR') is not None: - tf_hub_cache_dir = os.environ['TFHUB_CACHE_DIR'] -else: - tf_hub_cache_dir = os.path.join(tempfile.gettempdir(), "tfhub_modules") - os.environ['TFHUB_CACHE_DIR'] = tf_hub_cache_dir +tf_hub_cache_dir = os.environ.get('TFHUB_CACHE_DIR', + os.path.join(tempfile.gettempdir(), "tfhub_modules")) +os.environ['TFHUB_CACHE_DIR'] = tf_hub_cache_dir -if os.environ.get('HUGGINGFACE_HUB_CACHE') is not None: - hf_hub_cache_dir = os.environ['HUGGINGFACE_HUB_CACHE'] -else: - hf_hub_cache_dir = tempfile.gettempdir() - os.environ['HUGGINGFACE_HUB_CACHE'] = hf_hub_cache_dir +hf_hub_cache_dir = os.environ.get('HUGGINGFACE_HUB_CACHE', + tempfile.gettempdir()) +os.environ['HUGGINGFACE_HUB_CACHE'] = hf_hub_cache_dir # supported_devices : CPU, GPU, GNA test_device = os.environ.get('TEST_DEVICE', 'CPU;GPU').split(';') diff --git a/tests/model_hub_tests/torch_tests/hf_transformers_models b/tests/model_hub_tests/torch_tests/hf_transformers_models index 2f69f6adbcf405..028de156c32459 100644 --- a/tests/model_hub_tests/torch_tests/hf_transformers_models +++ b/tests/model_hub_tests/torch_tests/hf_transformers_models @@ -3,8 +3,8 @@ abcp4/mymodel-test,mymodel,skip,Load problem abeja/gpt-neox-japanese-2.7b,gpt_neox_japanese acl-submission-anonym/EAM-spectral,examuse,skip,Load problem adalbertojunior/modular-test,modular,skip,Load problem -aerner/lm-v2,open-llama,skip,Load problem: maximum recursion depth exceeded while calling a Python object -afonsosamarques/ardt-vanilla-combo_train_hopper_v2-2508_1336-33,decision_transformer,skip,Load problem +aerner/lm-v2,open-llama +afonsosamarques/ardt-vanilla-combo_train_hopper_v2-2508_1336-33,decision_transformer,xfail,Tracing problem aihijo/gec-zh-gector-bert-large,gector,skip,Load problem albert-base-v2,albert AlekseyKorshuk/test_reward_model,reward_model,skip,Load problem @@ -32,7 +32,7 @@ bigscience/bloom-560m,bloom Bono93/basic-cnn-example,simplecnn,skip,Load problem caidas/swin2SR-realworld-sr-x4-64-bsrgan-psnr,swin2sr,xfail,Unsupported op prim::Constant camembert-base,camembert -CarlCochet/trajectory-transformer-ant-expert-v2,trajectory_transformer,skip,Load problem +CarlCochet/trajectory-transformer-ant-expert-v2,trajectory_transformer,xfail,Tracing problem CEBaB/bert-base-uncased.CEBaB.causalm.ambiance.2-class.exclusive.seed_42,bert_causalm,skip,Load problem CEBaB/gpt2.CEBaB.causalm.None__None.2-class.exclusive.seed_42,gpt2_causalm,skip,Load problem CEBaB/lstm.CEBaB.causalm.ambiance__food.2-class.exclusive.seed_42,lstm_causalm,skip,Load problem @@ -40,9 +40,9 @@ CEBaB/roberta-base.CEBaB.causalm.None__None.2-class.exclusive.seed_42,roberta_ca cestwc/lava-small-gigaword,lava,skip,Load problem chlab/efficientnet_61_planet_detection,efficientnet_61_planet_detection,skip,Load problem CIDAS/clipseg-rd64-refined,clipseg -clefourrier/graphormer-base-pcqm4mv2,graphormer,skip,Load problem +clefourrier/graphormer-base-pcqm4mv2,graphormer,xfail,Tracing problem cliang1453/deberta-v3-base-rte-teacher-stage1,ted-deberta-v2,skip,Load problem -clip-italian/clip-italian,vision-text-dual-encoder,skip,Load problem +clip-italian/clip-italian,vision-text-dual-encoder,xfail,Tracing problem Clyde013/deqbert-base,deqbert,skip,Load problem connor-henderson/fastspeech2_conformer,fastspeech2_conformer,skip,Load problem connor-henderson/fastspeech2_conformer_with_hifigan,fastspeech2_conformer_with_hifigan,skip,Load problem @@ -67,9 +67,9 @@ facebook/convnextv2-tiny-22k-384,convnextv2 facebook/detr-resnet-50,detr facebook/dinov2-base,dinov2,skip,Load problem facebook/dpr-question_encoder-single-nq-base,dpr -facebook/encodec_24khz,encodec,skip,Load problem +facebook/encodec_24khz,encodec,xfail,Unsupported op aten::lstm facebook/esm2_t6_8M_UR50D,esm,xfail,Tracing error: The values for attribute 'shape' do not match -facebook/flava-full,flava,skip,Load problem +facebook/flava-full,flava,xfail,Tracing problem facebook/flava-image-codebook,flava_image_codebook,skip,Load problem facebook/m2m100_418M,m2m_100 facebook/mask2former-swin-base-coco-panoptic,mask2former,xfail,Accuracy validation failed @@ -81,9 +81,9 @@ facebook/rag-token-nq,rag,skip,Load problem facebook/sam-vit-large,sam,xfail,No node with name original_sizes facebook/timesformer-base-finetuned-k400,timesformer,xfail,Shape inference of Add node failed: Eltwise shape infer input shapes dim index: 1 mismatch facebook/vit-mae-base,vit_mae,xfail,Accuracy validation failed -facebook/wmt19-ru-en,fsmt,skip,Load problem +facebook/wmt19-ru-en,fsmt,xfail,Tracing problem facebook/xlm-roberta-xl,xlm-roberta-xl -facebook/xmod-base,xmod,skip,Load problem +facebook/xmod-base,xmod flax-community/ft5-cnn-dm,f_t5,skip,Load problem fnlp/elasticbert-base,elasticbert,skip,Load problem FranzStrauss/ponet-base-uncased,ponet,skip,Load problem @@ -105,7 +105,7 @@ google/mt5-base,mt5 google/owlvit-base-patch32,owlvit google/pix2struct-docvqa-base,pix2struct,skip,Load problem google/realm-orqa-nq-openqa,realm,skip,Load problem -google/reformer-crime-and-punishment,reformer,skip,Load problem +google/reformer-crime-and-punishment,reformer,xfail,Tracing problem google/tapas-large-finetuned-wtq,tapas,skip,Load problem google/vit-hybrid-base-bit-384,vit-hybrid,skip,Load problem google/vivit-b-16x2-kinetics400,vivit @@ -114,7 +114,7 @@ gpt2,gpt2 Graphcore/groupbert-base-uncased,groupbert,skip,Load problem haoranzhao419/saffu-100M-0.1,saffu-100M-0.1,skip,Load problem Helsinki-NLP/opus-mt-fr-en,marian -hf-internal-testing/random-nllb-moe-2-experts,nllb-moe,skip,Load problem +#hf-internal-testing/random-nllb-moe-2-experts,nllb-moe,skip,Load problem hf-internal-testing/tiny-random-BlenderbotModel,blenderbot,skip,Load problem hf-internal-testing/tiny-random-CodeGenModel,codegen hf-internal-testing/tiny-random-convnext,convnext @@ -133,7 +133,7 @@ hf-internal-testing/tiny-random-groupvit,groupvit hf-internal-testing/tiny-random-IBertModel,ibert hf-internal-testing/tiny-random-ImageGPTModel,imagegpt hf-internal-testing/tiny-random-LevitModel,levit,skip,Load problem -hf-internal-testing/tiny-random-LiltModel,lilt,skip,Load problem +hf-internal-testing/tiny-random-LiltModel,lilt hf-internal-testing/tiny-random-LongT5Model,longt5,skip,Load problem hf-internal-testing/tiny-random-mbart,mbart,xfail,Compile error: CPU plug-in doesnt support Squeeze operation with dynamic rank hf-internal-testing/tiny-random-MobileNetV2Model,mobilenet_v2 @@ -153,7 +153,7 @@ hf-internal-testing/tiny-random-SEWDModel,sew-d,skip,Load problem hf-internal-testing/tiny-random-SEWModel,sew,skip,Load problem hf-internal-testing/tiny-random-Speech2TextModel,speech_to_text,skip,Load problem hf-internal-testing/tiny-random-speech-encoder-decoder,speech-encoder-decoder,skip,Load problem -hf-internal-testing/tiny-random-SplinterModel,splinter,skip,Load problem +hf-internal-testing/tiny-random-SplinterModel,splinter hf-internal-testing/tiny-random-SqueezeBertModel,squeezebert hf-internal-testing/tiny-random-SwinModel,swin,xfail,Unsupported op aten::adaptive_avg_pool1d hf-internal-testing/tiny-random-unispeech,unispeech,skip,Load problem @@ -242,8 +242,8 @@ microsoft/deberta-base,deberta microsoft/git-large-coco,git,skip,Load problem microsoft/layoutlm-base-uncased,layoutlm microsoft/layoutlmv2-base-uncased,layoutlmv2,skip,Load problem -microsoft/layoutlmv3-base,layoutlmv3,skip,Load problem -microsoft/markuplm-base,markuplm,skip,Load problem +microsoft/layoutlmv3-base,layoutlmv3,xfail,Unsupported op aten::amax aten::clip +microsoft/markuplm-base,markuplm microsoft/resnet-50,resnet microsoft/speecht5_hifigan,hifigan,skip,Load problem microsoft/speecht5_tts,speecht5,skip,Load problem @@ -307,7 +307,7 @@ raman-ai/pcqv2-tokengt-lap16,tokengt,skip,Load problem range3/pegasus-gpt2-medium,pegasusgpt2,skip,Load problem regisss/bridgetower-newyorker-a100-8x,bridgetower rinna/japanese-cloob-vit-b-16,cloob,skip,Load problem -Rocketknight1/tiny-random-falcon-7b,falcon,skip,Load problem +Rocketknight1/tiny-random-falcon-7b,falcon RUCAIBox/mass-base-uncased,mass,skip,Load problem RWKV/rwkv-4-169m-pile,rwkv,xfail,Unsupported op aten::maximum sahasrarjn/interbert,BERT,skip,Load problem @@ -366,23 +366,23 @@ transZ/phrext,phrext,skip,Load problem transZ/reword,reword,skip,Load problem transZ/roberta_texid,roberta_texid,skip,Load problem transZ/tforge_v1.9,Transformer_Forge,skip,Load problem -trl-internal-testing/tiny-random-BigBirdPegasusForConditionalGeneration,bigbird_pegasus,skip,Load problem +trl-internal-testing/tiny-random-BigBirdPegasusForConditionalGeneration,bigbird_pegasus trl-internal-testing/tiny-random-BlenderbotSmallForConditionalGeneration,blenderbot-small,skip,Load problem -trl-internal-testing/tiny-random-MvpForConditionalGeneration,mvp,skip,Load problem +trl-internal-testing/tiny-random-MvpForConditionalGeneration,mvp trl-internal-testing/tiny-random-PegasusXForConditionalGeneration,pegasus_x,skip,Load problem -trl-internal-testing/tiny-random-PLBartForConditionalGeneration,plbart,skip,Load problem +trl-internal-testing/tiny-random-PLBartForConditionalGeneration,plbart,xfail,Compile error: CPU plug-in doesnt support Squeeze operation with dynamic rank trl-internal-testing/tiny-random-ProphetNetForConditionalGeneration,prophetnet,skip,Load problem trl-internal-testing/tiny-random-SwitchTransformersForConditionalGeneration,switch_transformers,skip,Load problem turing-motors/heron-chat-blip-ja-stablelm-base-7b-v0,video_blip,skip,Load problem turing-motors/heron-chat-git-ELYZA-fast-7b-v0,git_llama,skip,Load problem -uclanlp/visualbert-vqa-coco-pre,visual_bert,skip,Load problem +uclanlp/visualbert-vqa-coco-pre,visual_bert ummagumm-a/samolet_room_classifier,AirModelHF,skip,Load problem ummagumm-a/samolet-room-classifier,gru,skip,Load problem UNCANNY69/Misinfo-BERT-LSTM,BertLSTMForSequenceClassification,skip,Load problem UNCANNY69/Miss-BERT-CNN,BertCNNForSequenceClassification,skip,Load problem unc-nlp/lxmert-base-uncased,lxmert,skip,Load problem -uw-madison/mra-base-512-4,mra,skip,Load problem -uw-madison/yoso-4096,yoso,skip,Fatal Python error: Aborted +uw-madison/mra-base-512-4,mra +uw-madison/yoso-4096,yoso,xfail,Compile error: CPU plug-in doesnt support Squeeze operation with dynamic rank valhalla/cogview-gpt2-test,cog_view,skip,Load problem valhalla/s2t_mustc_multilinguial_medium,speech_to_text_transformer,skip,Load problem vblagoje/greaselm-csqa,greaselm,skip,Load problem @@ -397,7 +397,7 @@ WENGSYX/CoNN_Parity,conn,skip,Load problem xlm-roberta-base,xlm-roberta xlnet-base-cased,xlnet ybelkada/focusondepth,focusondepth,skip,Load problem -ybelkada/random-tiny-BertGenerationModel,bert-generation,skip,Load problem +ybelkada/random-tiny-BertGenerationModel,bert-generation ydshieh/temp-testing-kosmos-2,kosmos-2,skip,Load problem YituTech/conv-bert-base,convbert yjernite/retribert-base-uncased,retribert,xfail,Unsupported op aten::cross_entropy_loss diff --git a/tests/model_hub_tests/torch_tests/requirements.txt b/tests/model_hub_tests/torch_tests/requirements.txt index 9668e5c92b12bb..181786db4a4528 100644 --- a/tests/model_hub_tests/torch_tests/requirements.txt +++ b/tests/model_hub_tests/torch_tests/requirements.txt @@ -14,3 +14,4 @@ pyctcdecode pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com protobuf soundfile +pandas diff --git a/tests/model_hub_tests/torch_tests/test_transformers.py b/tests/model_hub_tests/torch_tests/test_transformers.py index b6f7e9239a9c0f..3a677353c86508 100644 --- a/tests/model_hub_tests/torch_tests/test_transformers.py +++ b/tests/model_hub_tests/torch_tests/test_transformers.py @@ -29,6 +29,21 @@ def flattenize_outputs(outputs): return dict((k, v.numpy(force=True)) for k, v in outputs.items()) +def filter_example(model, example): + try: + import inspect + if isinstance(example, dict): + model_params = inspect.signature(model.forward).parameters + names_set = {p for p in model_params} + new_example = dict() + for k, v in example: + if k in names_set: + new_example[k] = v + return new_example + except: + return example + + # To make tests reproducible we seed the random generator torch.manual_seed(0) @@ -38,6 +53,8 @@ def setup_class(self): from PIL import Image import requests + self.infer_timeout = 1200 + url = "http://images.cocodataset.org/val2017/000000039769.jpg" self.image = Image.open(requests.get(url, stream=True).raw) @@ -101,6 +118,13 @@ def forward(self, x): processor = AutoProcessor.from_pretrained(name) encoded_input = processor(images=self.image, return_tensors="pt") example = (encoded_input.pixel_values,) + elif "flava" in mi.tags: + from transformers import AutoProcessor + processor = AutoProcessor.from_pretrained(name) + encoded_input = processor(text=["a photo of a cat", "a photo of a dog"], + images=[self.image, self.image], + return_tensors="pt") + example = dict(encoded_input) elif "vivit" in mi.tags: from transformers import VivitImageProcessor frames = list(torch.randint( @@ -117,14 +141,6 @@ def forward(self, x): input_dict = processor( images, audio, sampling_rate=44100, return_tensors="pt") example = dict(input_dict) - elif "xmod" in mi.tags: - from transformers import AutoTokenizer, AutoModel - processor = AutoTokenizer.from_pretrained(name) - text = "Replace me by any text you'd like." - encoded_input = processor(text=[text], return_tensors="pt") - model = AutoModel.from_pretrained(name, torchscript=True) - model.set_default_language("de_CH") - example = dict(encoded_input) elif "gptsan-japanese" in mi.tags: from transformers import AutoTokenizer processor = AutoTokenizer.from_pretrained(name) @@ -140,110 +156,114 @@ def forward(self, x): inputs = processor(video, return_tensors="pt") example = dict(inputs) else: - if auto_model == "AutoModelForCausalLM": - from transformers import AutoTokenizer, AutoModelForCausalLM - tokenizer = AutoTokenizer.from_pretrained(name) - model = AutoModelForCausalLM.from_pretrained( - name, torchscript=True) - text = "Replace me by any text you'd like." - encoded_input = tokenizer(text, return_tensors='pt') - inputs_dict = dict(encoded_input) - if "facebook/incoder" in name and "token_type_ids" in inputs_dict: - del inputs_dict["token_type_ids"] - example = inputs_dict - elif auto_model == "AutoModelForMaskedLM": - from transformers import AutoTokenizer, AutoModelForMaskedLM - tokenizer = AutoTokenizer.from_pretrained(name) - model = AutoModelForMaskedLM.from_pretrained( - name, torchscript=True) - text = "Replace me by any text you'd like." - encoded_input = tokenizer(text, return_tensors='pt') - example = dict(encoded_input) - elif auto_model == "AutoModelForImageClassification": - from transformers import AutoProcessor, AutoModelForImageClassification - processor = AutoProcessor.from_pretrained(name) - model = AutoModelForImageClassification.from_pretrained( - name, torchscript=True) - encoded_input = processor( - images=self.image, return_tensors="pt") - example = dict(encoded_input) - elif auto_model == "AutoModelForSeq2SeqLM": - from transformers import AutoTokenizer, AutoModelForSeq2SeqLM - tokenizer = AutoTokenizer.from_pretrained(name) - model = AutoModelForSeq2SeqLM.from_pretrained( - name, torchscript=True) - inputs = tokenizer( - "Studies have been shown that owning a dog is good for you", return_tensors="pt") - decoder_inputs = tokenizer( - " Studien haben gezeigt dass es hilfreich ist einen Hund zu besitzen", - return_tensors="pt", - add_special_tokens=False, - ) - example = dict(input_ids=inputs.input_ids, - decoder_input_ids=decoder_inputs.input_ids) - elif auto_model == "AutoModelForSpeechSeq2Seq": - from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq - from datasets import load_dataset - processor = AutoProcessor.from_pretrained(name) - model = AutoModelForSpeechSeq2Seq.from_pretrained( - name, torchscript=True) - dataset = load_dataset( - "hf-internal-testing/librispeech_asr_demo", "clean", split="validation") - dataset = dataset.sort("id") - sampling_rate = dataset.features["audio"].sampling_rate - inputs = processor( - dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt") - example = dict(inputs) - elif auto_model == "AutoModelForCTC": - from transformers import AutoProcessor, AutoModelForCTC - from datasets import load_dataset - processor = AutoProcessor.from_pretrained(name) - model = AutoModelForCTC.from_pretrained( - name, torchscript=True) - ds = load_dataset( - "patrickvonplaten/librispeech_asr_dummy", "clean", split="validation") - input_values = processor( - ds[0]["audio"]["array"], return_tensors="pt") - example = dict(input_values) - elif auto_model == "AutoModelForTableQuestionAnswering": - import pandas as pd - from transformers import AutoTokenizer, AutoModelForTableQuestionAnswering - tokenizer = AutoTokenizer.from_pretrained(name) - model = AutoModelForTableQuestionAnswering.from_pretrained( - name, torchscript=True) - data = {"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], - "Number of movies": ["87", "53", "69"]} - queries = ["What is the name of the first actor?", - "How many movies has George Clooney played in?", - "What is the total number of movies?",] - answer_coordinates = [[(0, 0)], [(2, 1)], [ - (0, 1), (1, 1), (2, 1)]] - answer_text = [["Brad Pitt"], ["69"], ["209"]] - table = pd.DataFrame.from_dict(data) - encoded_input = tokenizer(table=table, queries=queries, answer_coordinates=answer_coordinates, - answer_text=answer_text, padding="max_length", return_tensors="pt",) - example = dict(encoded_input) - else: - from transformers import AutoTokenizer, AutoProcessor - text = "Replace me by any text you'd like." - if auto_processor is not None and "Tokenizer" not in auto_processor: + try: + if auto_model == "AutoModelForCausalLM": + from transformers import AutoTokenizer, AutoModelForCausalLM + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForCausalLM.from_pretrained( + name, torchscript=True) + text = "Replace me by any text you'd like." + encoded_input = tokenizer(text, return_tensors='pt') + inputs_dict = dict(encoded_input) + if "facebook/incoder" in name and "token_type_ids" in inputs_dict: + del inputs_dict["token_type_ids"] + example = inputs_dict + elif auto_model == "AutoModelForMaskedLM": + from transformers import AutoTokenizer, AutoModelForMaskedLM + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForMaskedLM.from_pretrained( + name, torchscript=True) + text = "Replace me by any text you'd like." + encoded_input = tokenizer(text, return_tensors='pt') + example = dict(encoded_input) + elif auto_model == "AutoModelForImageClassification": + from transformers import AutoProcessor, AutoModelForImageClassification processor = AutoProcessor.from_pretrained(name) + model = AutoModelForImageClassification.from_pretrained( + name, torchscript=True) encoded_input = processor( - text=[text], images=self.image, return_tensors="pt", padding=True) - else: + images=self.image, return_tensors="pt") + example = dict(encoded_input) + elif auto_model == "AutoModelForSeq2SeqLM": + from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained(name) - encoded_input = tokenizer(text, return_tensors='pt') - example = dict(encoded_input) + model = AutoModelForSeq2SeqLM.from_pretrained( + name, torchscript=True) + inputs = tokenizer( + "Studies have been shown that owning a dog is good for you", return_tensors="pt") + decoder_inputs = tokenizer( + " Studien haben gezeigt dass es hilfreich ist einen Hund zu besitzen", + return_tensors="pt", + add_special_tokens=False, + ) + example = dict(input_ids=inputs.input_ids, + decoder_input_ids=decoder_inputs.input_ids) + elif auto_model == "AutoModelForSpeechSeq2Seq": + from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq + from datasets import load_dataset + processor = AutoProcessor.from_pretrained(name) + model = AutoModelForSpeechSeq2Seq.from_pretrained( + name, torchscript=True) + inputs = processor(torch.randn(1000).numpy(), sampling_rate=16000, return_tensors="pt") + example = dict(inputs) + elif auto_model == "AutoModelForCTC": + from transformers import AutoProcessor, AutoModelForCTC + from datasets import load_dataset + processor = AutoProcessor.from_pretrained(name) + model = AutoModelForCTC.from_pretrained( + name, torchscript=True) + input_values = processor(torch.randn(1000).numpy(), return_tensors="pt") + example = dict(input_values) + elif auto_model == "AutoModelForTableQuestionAnswering": + import pandas as pd + from transformers import AutoTokenizer, AutoModelForTableQuestionAnswering + tokenizer = AutoTokenizer.from_pretrained(name) + model = AutoModelForTableQuestionAnswering.from_pretrained( + name, torchscript=True) + data = {"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], + "Number of movies": ["87", "53", "69"]} + queries = ["What is the name of the first actor?", + "How many movies has George Clooney played in?", + "What is the total number of movies?",] + answer_coordinates = [[(0, 0)], [(2, 1)], [ + (0, 1), (1, 1), (2, 1)]] + answer_text = [["Brad Pitt"], ["69"], ["209"]] + table = pd.DataFrame.from_dict(data) + encoded_input = tokenizer(table=table, queries=queries, answer_coordinates=answer_coordinates, + answer_text=answer_text, padding="max_length", return_tensors="pt",) + example = dict(input_ids=encoded_input["input_ids"], + token_type_ids=encoded_input["token_type_ids"], + attention_mask=encoded_input["attention_mask"]) + else: + from transformers import AutoTokenizer, AutoProcessor + text = "Replace me by any text you'd like." + if auto_processor is not None and "Tokenizer" not in auto_processor: + processor = AutoProcessor.from_pretrained(name) + encoded_input = processor( + text=[text], images=self.image, return_tensors="pt", padding=True) + else: + tokenizer = AutoTokenizer.from_pretrained(name) + encoded_input = tokenizer(text, return_tensors='pt') + example = dict(encoded_input) + except: + pass if model is None: from transformers import AutoModel model = AutoModel.from_pretrained(name, torchscript=True) - self.example = example + if hasattr(model, "set_default_language"): + model.set_default_language("en_XX") + if example is None: + if "encodec" in mi.tags: + example = (torch.randn(1, 1, 100),) + else: + example = (torch.randint(1, 1000, [1, 100]),) + self.example = filter_example(model, example) model.eval() # do first inference - if isinstance(example, dict): - model(**example) + if isinstance(self.example, dict): + model(**self.example) else: - model(*example) + model(*self.example) return model def get_inputs_info(self, model_obj): @@ -274,9 +294,11 @@ def teardown_method(self): @pytest.mark.parametrize("name,type", [("bert-base-uncased", "bert"), ("facebook/bart-large-mnli", "bart"), - ("google/flan-t5-base","t5"), + ("google/flan-t5-base", "t5"), + ("google/tapas-large-finetuned-wtq", "tapas"), ("gpt2", "gpt2"), - ("openai/clip-vit-large-patch14", "clip")]) + ("openai/clip-vit-large-patch14", "clip"), + ("RWKV/rwkv-4-169m-pile", "rwkv")]) @pytest.mark.precommit def test_convert_model_precommit(self, name, type, ie_device): self.run(model_name=name, model_link=type, ie_device=ie_device) From 678e919b13c09f82b71c1c8e4a80de8313175df4 Mon Sep 17 00:00:00 2001 From: Sun Xiaoxia Date: Sat, 23 Sep 2023 11:28:15 +0800 Subject: [PATCH 29/43] CPU pinning on Windows (#19405) * add cpu pinning on windows * remove pinning limitation on windows * only support the machine with one numa node * fix code style * fix build error on macos * set mask initial value * fix test failure on window * fix build failure on macos, add limitation on windows machine with two sockets * fix test failure on windows * fix test failure * fix comments --- .../cpu_streams_executor_internal.cpp | 6 +++- .../src/dev/threading/thread_affinity.cpp | 28 ++++++++++++++++- .../src/dev/threading/thread_affinity.hpp | 11 +++++-- .../tests/unit/cpu_stream_info_test.cpp | 25 ---------------- .../intel_cpu/src/cpu_map_scheduling.cpp | 30 ++++++++++++------- .../unit/streams_info/streams_e2e_test.cpp | 2 +- 6 files changed, 62 insertions(+), 40 deletions(-) diff --git a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp index c05509e225c7f5..7936130997b6a2 100644 --- a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp +++ b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp @@ -51,8 +51,12 @@ void get_cur_stream_info(const int stream_id, max_threads_per_core = 2; } -#if defined(_WIN32) || defined(__APPLE__) +#if defined(__APPLE__) cpu_reserve = false; +#elif defined(_WIN32) + if (proc_type_table.size() > 1) { + cpu_reserve = false; + } #endif if (cpu_reserve) { stream_type = STREAM_WITH_OBSERVE; diff --git a/src/inference/src/dev/threading/thread_affinity.cpp b/src/inference/src/dev/threading/thread_affinity.cpp index 1e74c5cd055b63..887e89237b5dd7 100644 --- a/src/inference/src/dev/threading/thread_affinity.cpp +++ b/src/inference/src/dev/threading/thread_affinity.cpp @@ -110,7 +110,33 @@ bool pin_current_thread_to_socket(int socket) { } return res; } -#else // no threads pinning/binding on Win/MacOS +#elif defined(_WIN32) +std::tuple get_process_mask() { + DWORD_PTR pro_mask, sys_mask; + if (0 != GetProcessAffinityMask(GetCurrentProcess(), &pro_mask, &sys_mask)) { + CpuSet mask(new DWORD_PTR(pro_mask)); + return std::make_tuple(std::move(mask), 0); + } + return std::make_tuple(nullptr, 0); +} +void release_process_mask(cpu_set_t*) {} + +bool pin_thread_to_vacant_core(int thrIdx, + int hyperthreads, + int ncores, + const CpuSet& procMask, + const std::vector& cpu_ids, + int cpuIdxOffset) { + return 0 != SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1) << cpu_ids[thrIdx]); +} +bool pin_current_thread_by_mask(int ncores, const CpuSet& procMask) { + DWORD_PTR mask = static_cast(*procMask.get()); + return 0 != SetThreadAffinityMask(GetCurrentThread(), mask); +} +bool pin_current_thread_to_socket(int socket) { + return false; +} +#else // no threads pinning/binding on MacOS std::tuple get_process_mask() { return std::make_tuple(nullptr, 0); } diff --git a/src/inference/src/dev/threading/thread_affinity.hpp b/src/inference/src/dev/threading/thread_affinity.hpp index 1f971d64275334..20c0f7d513a59b 100644 --- a/src/inference/src/dev/threading/thread_affinity.hpp +++ b/src/inference/src/dev/threading/thread_affinity.hpp @@ -11,13 +11,20 @@ #if !(defined(__APPLE__) || defined(__EMSCRIPTEN__) || defined(_WIN32)) # include #endif +#if defined(_WIN32) +# include + +# include +#endif namespace ov { namespace threading { -#if (defined(__APPLE__) || defined(__EMSCRIPTEN__) || defined(_WIN32)) +#if (defined(__APPLE__) || defined(__EMSCRIPTEN__)) using cpu_set_t = void; -#endif // (defined(__APPLE__) || defined(__EMSCRIPTEN__) || defined(_WIN32)) +#elif defined(_WIN32) +using cpu_set_t = DWORD_PTR; +#endif /** * @brief Release the cores affinity mask for the current process diff --git a/src/inference/tests/unit/cpu_stream_info_test.cpp b/src/inference/tests/unit/cpu_stream_info_test.cpp index 51d07015077fb1..56d651a031b40d 100644 --- a/src/inference/tests/unit/cpu_stream_info_test.cpp +++ b/src/inference/tests/unit/cpu_stream_info_test.cpp @@ -357,21 +357,12 @@ LinuxCpuStreamTypeCase _1sockets_4cores_binding = { }, {{8, 4, 0, 4, 0, 0}}, {{4, MAIN_CORE_PROC, 1, 0, 0}}, -# if defined(__linux__) { STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, }, -# else - { - STREAM_WITHOUT_PARAM, - STREAM_WITHOUT_PARAM, - STREAM_WITHOUT_PARAM, - STREAM_WITHOUT_PARAM, - }, -# endif {1, 1, 1, 1}, { MAIN_CORE_PROC, @@ -423,17 +414,10 @@ LinuxCpuStreamTypeCase _1sockets_12cores_pcore_binding = { }, {{20, 8, 4, 8, 0, 0}}, {{2, MAIN_CORE_PROC, 4, 0, 0}}, -# if defined(__linux__) { STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, }, -# else - { - STREAM_WITH_CORE_TYPE, - STREAM_WITH_CORE_TYPE, - }, -# endif {4, 4}, { MAIN_CORE_PROC, @@ -488,21 +472,12 @@ LinuxCpuStreamTypeCase _1sockets_12cores_ecore_binding = { }, {{20, 8, 4, 8, 0, 0}}, {{4, EFFICIENT_CORE_PROC, 1, 0, 0}}, -# if defined(__linux__) { STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, STREAM_WITH_OBSERVE, }, -# else - { - STREAM_WITH_CORE_TYPE, - STREAM_WITH_CORE_TYPE, - STREAM_WITH_CORE_TYPE, - STREAM_WITH_CORE_TYPE, - }, -# endif {1, 1, 1, 1}, { EFFICIENT_CORE_PROC, diff --git a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp index 3554de0636d6f4..9efcc23ddf2fd7 100644 --- a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp +++ b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp @@ -79,19 +79,29 @@ bool get_cpu_pinning(bool& input_value, int num_sockets = get_default_latency_streams(latency_threading_mode); bool latency = num_streams <= num_sockets && num_streams > 0; - if (proc_type_table[0][EFFICIENT_CORE_PROC] > 0 && - proc_type_table[0][EFFICIENT_CORE_PROC] < proc_type_table[0][ALL_PROC]) { - result_value = - input_changed - ? input_value - : ((latency || bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA) ? false : true); + if (input_changed) { + result_value = input_value; } else { - result_value = input_changed - ? input_value - : (bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA ? false : true); + if (proc_type_table[0][EFFICIENT_CORE_PROC] > 0 && + proc_type_table[0][EFFICIENT_CORE_PROC] < proc_type_table[0][ALL_PROC]) { + result_value = + ((latency || bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA) ? false : true); + } else { + result_value = (bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA ? false : true); + } +#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO) +# if defined(_WIN32) + result_value = false; +# endif +#endif } #if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO) -# if defined(__APPLE__) || defined(_WIN32) +# if defined(_WIN32) + if (proc_type_table.size() > 1) { + result_value = false; + } +# endif +# if defined(__APPLE__) result_value = false; # endif #endif diff --git a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp index 05ad350a5f67fa..1bcdb6f84ef590 100644 --- a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp +++ b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp @@ -578,7 +578,7 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_9 = { {{24, MAIN_CORE_PROC, 1, 0, 0}, {24, MAIN_CORE_PROC, 1, 1, 1}}, }; -#ifdef __linux__ +#if defined (__linux__) || defined(_WIN32) INSTANTIATE_TEST_SUITE_P(smoke_StreamsGeneration, StreamGenerationTests, ::testing::Values(generation_latency_1sockets_14cores_3, From 3e82849f3c126312ab3511bf09d7af0129838582 Mon Sep 17 00:00:00 2001 From: Andrey Babushkin Date: Sat, 23 Sep 2023 10:02:28 +0100 Subject: [PATCH 30/43] [workflows/linux] Switch to self-hosted runners in Azure Kubernetes Service (#19183) * [workflows/liux] Trying AKS runners * Remove sudo usages * Fix repositories path * Well, adding debug output * execution bit? * more debug output * using bash... * We should use shell syntax for env variables in 'run' sections * again, may be we should use bash... * fix cloning path for openvino repo * more debug output * Trying to populate WORKSPACE var in other way * Trying different WORKSPACE * export ALL variables for samples tests * Trying to put openvino build into correct directory * Replace more occurences of BUILD_DIR... * Use shell expansion instead of Actions syntax in run steps * Skip unit test failures * Oops, there's no pytest for MO unit tests * Oops, typo * Fix LAYER_TESTS_INSTALL_DIR variable expansion * Fix LAYER_TESTS_INSTALL_DIR for new stages * Replace all the varibles * Comment out CCACHE_DIR I want to test worst-case scenario * Comment setup ccache step * Revert "Comment out CCACHE_DIR" This reverts commit 046663a9f1bd41c0869e7e66392fb57e65daea00. * Just checking something * Update with new stages from master * One more stage to fix * Fix INSTALL_DIR again (new stages were merged to master?) * Remove concurrency limit (for test purposes) * Trigger one more pipeline * Disable concurrency settings * Trigger another build * Disable ccache (for testing purposes) * trigger another build to measure duration without ccache * And one more test commit * Return back ccache * Testing new image * Enable concurrency back * Using new image * And another image * Trying build on the clean image * Install git Upstream ubuntu image doesn't have git * Oops, forgot apt-get update * Upstream Ubuntu image, but using ACR cache * Remove debug output * Use Ubuntu image from ACR cache for the rest of the stages * Display version of ccache * Swith to ubuntu 20 temporarily (I hope) * Set CCACHE_TEMP_DIR outside of shared space * Revert "Swith to ubuntu 20 temporarily (I hope)" This reverts commit 2e53109d83307e9b7f587d609d1e6e346ea6ed48. * trying ccche nohardlink option * Trying to disable ccache file cloning * fix CCACHE_TEMPDIR * Install git to Python unit tests stage * Install libsnappy-dev as tests require it * Install python to test stage * Fix env vars syntax in few places * Update docker image name * Increase timeout for CPU tests * Debug output - trying to find out what's wrong with test reports * Change file name in debug-output 'find' command * let's try shell syntax for upload artifact action... It most likely won't work but I see strange output in the logs: Error: No files were found with the provided path: /__w/openvino/openvino/install/tests/TEST*.xml /runner/_work/openvino/openvino/install/tests/logs/failed/*.log /runner/_work/openvino/openvino/install/tests/logs/crashed/*.log /runner/_work/openvino/openvino/install/tests/logs/hanged/*.log /runner/_work/openvino/openvino/install/tests/logs/interapted/*.log /runner/_work/openvino/openvino/install/tests/logs/disabled_tests.log. No artifacts will be uploaded. So the first path is translated to the path inside the container correctly and the rest are not O_o * Revert "let's try shell syntax for upload artifact action..." This reverts commit eb19b4f319838460a8c0729bf9946b493d76231b. * Leave just disabled_tests.log (as it is the only one present) * Use my own directory instead of github.workspace Inside-container path translation doesn't work for upload-artifact actions (it works only for the first path, but not for the rest) * Revert "Leave just disabled_tests.log (as it is the only one present)" This reverts commit 43218278809d6cef245c0c3c6f422f0893dbfa64. * Okay, let's try hardcoded workspace path... * Okay, path should be inside "official" workspace. Hardcode it * Missed some variables, replace github.workspace to hard-coded value * Remove debug output 'find' command * Remove old-style cache setup * Clean ccache stats after cmake * Change docker image to the one with non-root user * Oops, switch to Ubuntu 20 * Playing with concurrency group name * Oops, forgot sudo for ninja installation * Revert "Oops, forgot sudo for ninja installation" This reverts commit a7e1730279e9c4309957e7b7922c01c992b4c3dc. * Revert "Oops, switch to Ubuntu 20" This reverts commit 19fe75f4afed6f177103d5feba6e67f5babdc695. * Revert "Change docker image to the one with non-root user" This reverts commit 553116492d7047c76d6951431675272284e3c2c7. * Use Ubuntu 20 DockerHub image * Trying to force apt-get packages not to wait for user input * Make DEBIAN_FRONTED for all stages * Update reason of skipped MO unit test * Add DEBIAN_FRONTED to all jobs * Fix environment variables expansion in newly-added stages * Update .github/workflows/linux.yml Co-authored-by: Ilya Lavrenov * Update .github/workflows/linux.yml Co-authored-by: Ilya Lavrenov * Fix review comments * More review comment fixes * Remove DEBIAN_FRONTEND from Python Models job * "Get tools versions" step is absent on master --------- Co-authored-by: Ilya Lavrenov --- .github/workflows/linux.yml | 566 +++++++++--------- .../mo/unit_tests/mo/utils/cli_parser_test.py | 2 + 2 files changed, 301 insertions(+), 267 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 27792b39fb934b..b3d4bbb764c200 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -24,7 +24,7 @@ on: - master concurrency: - group: ${{ github.head_ref || github.run_id }}-linux + group: ${{ github.ref || github.run_id }}-linux cancel-in-progress: true jobs: @@ -32,34 +32,49 @@ jobs: defaults: run: shell: bash - runs-on: ubuntu-20.04-8-cores + runs-on: aks-linux-16-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input CMAKE_BUILD_TYPE: 'Release' CMAKE_GENERATOR: 'Ninja' CMAKE_CXX_COMPILER_LAUNCHER: ccache CMAKE_C_COMPILER_LAUNCHER: ccache - OPENVINO_REPO: ${{ github.workspace }}/openvino - OPENVINO_CONTRIB_REPO: ${{ github.workspace }}/openvino_contrib - INSTALL_DIR: ${{ github.workspace }}/install - INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests - SAMPLES_INSTALL_DIR: ${{ github.workspace }}/install/samples - LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests - MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests - BUILD_DIR: ${{ github.workspace }}/build - OV_TEMP: ${{ github.workspace }}/openvino_temp + GITHUB_WORKSPACE: '/__w/openvino/openvino' + OPENVINO_REPO: /__w/openvino/openvino/openvino + OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + SAMPLES_INSTALL_DIR: /__w/openvino/openvino/install/samples + LAYER_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/layer_tests + MODEL_HUB_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/model_hub_tests + BUILD_DIR: /__w/openvino/openvino/build + OV_TEMP: /__w/openvino/openvino/openvino_temp PYTHON_STATIC_ARGS: -m "not dynamic_library" + CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release + CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp + CCACHE_MAXSIZE: 50G steps: + - name: Install git + run: | + apt-get update + apt-get install -y git git-lfs + - name: Clone OpenVINO uses: actions/checkout@v4 with: - path: 'openvino' + path: ${{ env.OPENVINO_REPO }} submodules: 'true' - name: Clone OpenVINO Contrib uses: actions/checkout@v4 with: repository: 'openvinotoolkit/openvino_contrib' - path: 'openvino_contrib' + path: ${{ env.OPENVINO_CONTRIB_REPO }} + submodules: 'true' # # Dependencies @@ -67,13 +82,13 @@ jobs: - name: Install build dependencies run: | - sudo -E ${{ env.OPENVINO_REPO }}/install_build_dependencies.sh - sudo -E apt update - sudo -E apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers + bash ${OPENVINO_REPO}/install_build_dependencies.sh + apt update + apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers wget https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip unzip ninja-linux.zip - sudo cp -v ninja /usr/local/bin/ + cp -v ninja /usr/local/bin/ - uses: actions/setup-python@v4 with: @@ -84,46 +99,38 @@ jobs: # For Python API python3 -m pip install --upgrade pip python3 -m pip install Scons - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/wheel/requirements-dev.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements_test.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements_test.txt # For running Python API tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt # For running ONNX frontend unit tests - python3 -m pip install --force-reinstall -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt + python3 -m pip install --force-reinstall -r ${OPENVINO_REPO}/src/frontends/onnx/tests/requirements.txt # For running TensorFlow frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow/tests/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow/tests/requirements.txt # For running Paddle frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt - name: Install MO dependencies run: | - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt # # Build # - name: Setup ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - max-size: "2000M" - # Should save cache only if run in the master branch of the base repo - # github.ref_name is 'ref/PR_#' in case of the PR, and 'branch_name' when executed on push - save: ${{ github.ref_name == 'master' && 'true' || 'false' }} - verbose: 2 - key: linux-ubuntu - restore-keys: | - linux-ubuntu + run: | + mkdir -p $CCACHE_DIR - name: Get number of CPU cores uses: SimenB/github-actions-cpu-cores@v2 @@ -151,73 +158,73 @@ jobs: -DBUILD_nvidia_plugin=OFF \ -DENABLE_DEBUG_CAPS=ON \ -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" \ - -DOPENVINO_EXTRA_MODULES=${{ env.OPENVINO_CONTRIB_REPO }}/modules \ - -S ${{ env.OPENVINO_REPO }} \ - -B ${{ env.BUILD_DIR }} + -DOPENVINO_EXTRA_MODULES=${OPENVINO_CONTRIB_REPO}/modules \ + -S ${OPENVINO_REPO} \ + -B ${BUILD_DIR} - name: Clean ccache stats run: ccache --zero-stats --show-config - name: Build - run: cmake --build ${{ env.BUILD_DIR }} --parallel ${{ steps.cpu-cores.outputs.count }} --config Release + run: cmake --build ${BUILD_DIR} --parallel ${{ steps.cpu-cores.outputs.count }} --config Release - name: Show ccache stats run: ccache --show-stats - name: Cmake Layer Tests - run: cmake -GNinja -S ${{ env.OPENVINO_REPO }}/tests/layer_tests -B ${{ env.BUILD_DIR }}/layer_tests + run: cmake -GNinja -S ${OPENVINO_REPO}/tests/layer_tests -B ${BUILD_DIR}/layer_tests - name: Cmake Model Hub Tests - run: cmake -GNinja -S ${{ env.OPENVINO_REPO }}/tests/model_hub_tests -B ${{ env.BUILD_DIR }}/model_hub_tests + run: cmake -GNinja -S ${OPENVINO_REPO}/tests/model_hub_tests -B ${BUILD_DIR}/model_hub_tests - name: Build Layer Tests - run: cmake --build ${{ env.BUILD_DIR }}/layer_tests --parallel --config Release + run: cmake --build ${BUILD_DIR}/layer_tests --parallel --config Release - name: Build Model Hub Tests - run: cmake --build ${{ env.BUILD_DIR }}/model_hub_tests --parallel --config Release + run: cmake --build ${BUILD_DIR}/model_hub_tests --parallel --config Release - name: Install wheel packages - run: cmake -DCOMPONENT=python_wheels -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake + run: cmake -DCOMPONENT=python_wheels -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake - name: Install Layer Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/layer_tests/cmake_install.cmake + run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/layer_tests/cmake_install.cmake - name: Install Model Hub Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/model_hub_tests/cmake_install.cmake + run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/model_hub_tests/cmake_install.cmake - name: Install python wheels - run: python3 -m pip install openvino-dev --find-links=${{ env.INSTALL_DIR }}/tools + run: python3 -m pip install openvino-dev --find-links=${INSTALL_DIR}/tools - name: Install tests - run: cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCOMPONENT=tests -P ${{ env.BUILD_DIR }}/cmake_install.cmake + run: cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DCOMPONENT=tests -P ${BUILD_DIR}/cmake_install.cmake - name: Install OpenVINO - run: cmake -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/cmake_install.cmake + run: cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake - name: CMake Samples Tests - run: cmake -GNinja -S ${{ env.OPENVINO_REPO }}/tests/samples_tests -B ${{ env.BUILD_DIR }}/samples_tests + run: cmake -GNinja -S ${OPENVINO_REPO}/tests/samples_tests -B ${BUILD_DIR}/samples_tests - name: Build Samples Tests - run: cmake --build ${{ env.BUILD_DIR }}/samples_tests --config Release + run: cmake --build ${BUILD_DIR}/samples_tests --config Release - name: Install Samples Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -P ${{ env.BUILD_DIR }}/samples_tests/cmake_install.cmake + run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/samples_tests/cmake_install.cmake - name: Pack Artifacts run: | - pushd ${{ env.INSTALL_DIR }} - tar -czvf ${{ env.BUILD_DIR }}/openvino_package.tar.gz --exclude=tests * + pushd ${INSTALL_DIR} + tar -czvf ${BUILD_DIR}/openvino_package.tar.gz --exclude=tests * popd - pushd ${{ env.INSTALL_DIR }} - tar -czvf ${{ env.BUILD_DIR }}/openvino_tests.tar.gz tests/ + pushd ${INSTALL_DIR} + tar -czvf ${BUILD_DIR}/openvino_tests.tar.gz tests/ popd - name: Build cpp samples - run: ${{ env.SAMPLES_INSTALL_DIR }}/cpp/build_samples.sh -i ${{ env.INSTALL_DIR }} -b ${{ env.BUILD_DIR }}/cpp_samples + run: ${SAMPLES_INSTALL_DIR}/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples - name: Build c samples - run: ${{ env.SAMPLES_INSTALL_DIR }}/c/build_samples.sh -i ${{ env.INSTALL_DIR }} -b ${{ env.BUILD_DIR }}/c_samples + run: ${SAMPLES_INSTALL_DIR}/c/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/c_samples # # Tests @@ -225,26 +232,26 @@ jobs: - name: Samples tests run: | - python3 -m pip install --ignore-installed PyYAML -r ${{ env.INSTALL_TEST_DIR }}/smoke_tests/requirements.txt - export LD_LIBRARY_PATH=${{ env.IE_APP_PATH }}:$LD_LIBRARY_PATH + export WORKSPACE=${INSTALL_DIR} + export IE_APP_PATH=${INSTALL_DIR}/samples_bin + export IE_APP_PYTHON_PATH=${INSTALL_DIR}/samples/python + export SHARE=${INSTALL_TEST_DIR}/smoke_tests/samples_smoke_tests_data - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install --ignore-installed PyYAML -r ${INSTALL_TEST_DIR}/smoke_tests/requirements.txt + export LD_LIBRARY_PATH=${IE_APP_PATH}:$LD_LIBRARY_PATH - python3 -m pytest -sv ${{ env.INSTALL_TEST_DIR }}/smoke_tests \ - --env_conf ${{ env.INSTALL_TEST_DIR }}/smoke_tests/env_config.yml \ - --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-SamplesSmokeTests.xml - env: - IE_APP_PATH: ${{ env.INSTALL_DIR }}/samples_bin - IE_APP_PYTHON_PATH: ${{ env.INSTALL_DIR }}/samples/python - SHARE: ${{ env.INSTALL_TEST_DIR }}/smoke_tests/samples_smoke_tests_data - WORKSPACE: ${{ env.INSTALL_DIR }} + source ${INSTALL_DIR}/setupvars.sh + + python3 -m pytest -sv ${INSTALL_TEST_DIR}/smoke_tests \ + --env_conf ${INSTALL_TEST_DIR}/smoke_tests/env_config.yml \ + --junitxml=${INSTALL_TEST_DIR}/TEST-SamplesSmokeTests.xml # Present in the "Build" job due to the fact that these tests require build directory - name: ONNX frontend tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml # # Upload build artifacts @@ -271,15 +278,20 @@ jobs: defaults: run: shell: bash - runs-on: ubuntu-20.04 + runs-on: aks-linux-4-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: - INSTALL_DIR: ${{ github.workspace }}/install - INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests steps: - name: Create Directories run: | - mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} # # Dependencies @@ -287,8 +299,8 @@ jobs: - name: Install dependencies run: | - sudo -E apt update - sudo -E apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers + apt update + apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - name: Download OpenVINO package uses: actions/download-artifact@v3 @@ -304,11 +316,11 @@ jobs: - name: Extract OpenVINO packages run: | - pushd ${{ env.INSTALL_DIR }} - tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_package.tar.gz || exit 1 + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 popd - pushd ${{ env.INSTALL_TEST_DIR }} - tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz || exit 1 + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd # @@ -317,137 +329,137 @@ jobs: - name: OpenVINO Core Unit Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_core_unit_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVCoreUT.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_core_unit_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVCoreUT.xml - name: OpenVINO Inference Functional Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_inference_functional_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceFunc.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_inference_functional_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceFunc.xml - name: OpenVINO Inference Unit Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_inference_unit_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceUnit.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_inference_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceUnit.xml - name: Low Precision Transformations Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_lp_transformations_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-LpTransformations.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_lp_transformations_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-LpTransformations.xml - name: OpenVINO Conditional compilation tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_conditional_compilation_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ConditionalCompilation.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_conditional_compilation_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ConditionalCompilation.xml - name: IR frontend tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_ir_frontend_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-IRFrontend.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_ir_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-IRFrontend.xml # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L403 # - name: PaddlePaddle frontend tests # run: | - # source ${{ env.INSTALL_DIR }}/setupvars.sh - # ${{ env.INSTALL_TEST_DIR }}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* \ - # --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-PaddleTests.xml + # source ${INSTALL_DIR}/setupvars.sh + # ${INSTALL_TEST_DIR}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* \ + # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-PaddleTests.xml # Present in the "Build" job as these tests require build directory # - name: ONNX frontend tests # run: | - # source ${{ env.INSTALL_DIR }}/setupvars.sh - # ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ - # --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml + # source ${INSTALL_DIR}/setupvars.sh + # ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ + # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml - name: TensorFlow Common tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_common_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowCommonFrontend.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_common_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowCommonFrontend.xml - name: TensorFlow frontend tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_frontend_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowFrontend.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowFrontend.xml - name: TensorFlow Lite frontend tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TensorFlowLiteFrontend.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowLiteFrontend.xml - name: Transformations Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_transformations_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-Transformations.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_transformations_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-Transformations.xml - name: Common test utils tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_util_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-CommonUtilTests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_util_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CommonUtilTests.xml - name: Snippets func tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_snippets_func_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-SnippetsFuncTests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_snippets_func_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-SnippetsFuncTests.xml - name: CPU plugin unit tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_cpu_unit_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-CPUUnitTests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_cpu_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CPUUnitTests.xml # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L409 # - name: GNA plugin unit tests # run: | - # source ${{ env.INSTALL_DIR }}/setupvars.sh - # ${{ env.INSTALL_TEST_DIR }}/ov_gna_unit_tests --gtest_print_time=1 \ - # --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-GNAUnitTests.xml + # source ${INSTALL_DIR}/setupvars.sh + # ${INSTALL_TEST_DIR}/ov_gna_unit_tests --gtest_print_time=1 \ + # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-GNAUnitTests.xml - name: AUTO UT run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_auto_unit_tests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_unit_tests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_auto_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_unit_tests.xml - name: Template plugin tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_template_func_tests --gtest_print_time=1 \ + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_template_func_tests --gtest_print_time=1 \ --gtest_filter=*smoke* \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-TemplateFuncTests.xml + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TemplateFuncTests.xml - name: Inference Engine C API tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/InferenceEngineCAPITests --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-InferenceEngineCAPITests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/InferenceEngineCAPITests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceEngineCAPITests.xml - name: OpenVINO C API tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_capi_test --gtest_print_time=1 \ - --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OpenVINOCAPITests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_capi_test --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OpenVINOCAPITests.xml - name: AutoBatch FuncTests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_auto_batch_func_tests --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_batch_func_tests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_auto_batch_func_tests --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_batch_func_tests.xml - name: Proxy Plugin Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVProxyTests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVProxyTests.xml - name: Hetero Unit Tests run: | @@ -456,8 +468,8 @@ jobs: - name: Hetero Func Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - ${{ env.INSTALL_TEST_DIR }}/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVHeteroFuncTests.xml + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVHeteroFuncTests.xml - name: Upload Test Results uses: actions/upload-artifact@v3 @@ -472,23 +484,32 @@ jobs: defaults: run: shell: bash - runs-on: ubuntu-20.04 + runs-on: aks-linux-4-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: - OPENVINO_REPO: ${{ github.workspace }}/openvino - OPENVINO_CONTRIB_REPO: ${{ github.workspace }}/openvino_contrib - INSTALL_DIR: ${{ github.workspace }}/install - INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests - SAMPLES_INSTALL_DIR: ${{ github.workspace }}/install/samples - LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests - MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests - BUILD_DIR: ${{ github.workspace }}/build - OV_TEMP: ${{ github.workspace }}/openvino_temp + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + OPENVINO_REPO: /__w/openvino/openvino/openvino + OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + SAMPLES_INSTALL_DIR: /__w/openvino/openvino/install/samples + LAYER_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/layer_tests + MODEL_HUB_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/model_hub_tests + OV_TEMP: /__w/openvino/openvino/openvino_temp PYTHON_STATIC_ARGS: -m "not dynamic_library" steps: - name: Create Directories run: | - mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} + + - name: Install git + run: | + apt update + apt --assume-yes install git git-lfs - name: Clone OpenVINO uses: actions/checkout@v4 @@ -501,8 +522,8 @@ jobs: - name: Install dependencies run: | - sudo -E apt update - sudo -E apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers + apt update + apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - uses: actions/setup-python@v4 with: @@ -512,32 +533,32 @@ jobs: run: | # For Python API python3 -m pip install --upgrade pip - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/wheel/requirements-dev.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements.txt # For running Python API tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt # For running ONNX frontend unit tests - python3 -m pip install --force-reinstall -r ${{ env.OPENVINO_REPO }}/src/frontends/onnx/tests/requirements.txt + python3 -m pip install --force-reinstall -r ${OPENVINO_REPO}/src/frontends/onnx/tests/requirements.txt # For running TensorFlow frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/tensorflow/tests/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow/tests/requirements.txt # For running Paddle frontend unit tests - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/frontends/paddle/tests/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt # For torchvision to OpenVINO preprocessing converter - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/src/bindings/python/src/openvino/preprocess/torchvision/requirements.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/openvino/preprocess/torchvision/requirements.txt - name: Install MO dependencies run: | - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt - name: Download OpenVINO package uses: actions/download-artifact@v3 @@ -553,169 +574,169 @@ jobs: - name: Extract OpenVINO packages run: | - pushd ${{ env.INSTALL_DIR }} - tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_package.tar.gz || exit 1 + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 popd - pushd ${{ env.INSTALL_TEST_DIR }} - tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz || exit 1 + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd - name: Install Python wheels run: | - python3 -m pip install openvino-dev --find-links=${{ env.INSTALL_DIR }}/tools + python3 -m pip install openvino-dev --find-links=${INSTALL_DIR}/tools - name: nGraph and IE Python Bindings Tests run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/pyngraph ${{ env.PYTHON_STATIC_ARGS }} \ - --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml \ - --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests/test_onnx/test_zoo_models.py \ - --ignore=${{ env.INSTALL_TEST_DIR }}/pyngraph/tests/test_onnx/test_backend.py + source ${INSTALL_DIR}/setupvars.sh + python3 -m pytest -s ${INSTALL_TEST_DIR}/pyngraph ${{ env.PYTHON_STATIC_ARGS }} \ + --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ + --ignore=${INSTALL_TEST_DIR}/pyngraph/tests/test_onnx/test_zoo_models.py \ + --ignore=${INSTALL_TEST_DIR}/pyngraph/tests/test_onnx/test_backend.py - name: Python API 2.0 Tests run: | # For python imports to import pybind_mock_frontend - export PYTHONPATH=${{ env.INSTALL_TEST_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh - export LD_LIBRARY_PATH=${{ env.INSTALL_TEST_DIR }}:$LD_LIBRARY_PATH + export PYTHONPATH=${INSTALL_TEST_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh + export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH - python3 -m pytest -sv ${{ env.INSTALL_TEST_DIR }}/pyopenvino ${{ env.PYTHON_STATIC_ARGS }} \ - --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-Pyngraph.xml \ - --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_utils/test_utils.py \ - --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_onnx/test_zoo_models.py \ - --ignore=${{ env.INSTALL_TEST_DIR }}/pyopenvino/tests/test_onnx/test_backend.py + python3 -m pytest -sv ${INSTALL_TEST_DIR}/pyopenvino ${{ env.PYTHON_STATIC_ARGS }} \ + --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ + --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_utils/test_utils.py \ + --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_onnx/test_zoo_models.py \ + --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_onnx/test_backend.py - name: Python API snippets run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - export PYTHONPATH=${{ env.INSTALL_TEST_DIR }}:${{ github.workspace }}/openvino/docs/:$PYTHONPATH - export LD_LIBRARY_PATH=${{ env.INSTALL_TEST_DIR }}:$LD_LIBRARY_PATH + source ${INSTALL_DIR}/setupvars.sh + export PYTHONPATH=${INSTALL_TEST_DIR}:${OPENVINO_REPO}/docs/:$PYTHONPATH + export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH - python3 ${{ github.workspace }}/openvino/docs/snippets/main.py + python3 ${OPENVINO_REPO}/docs/snippets/main.py - name: Model Optimizer UT run: | - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:${{ env.INSTALL_TEST_DIR }}:${{ env.INSTALL_DIR }}/python/python3.11:$PYTHONPATH + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:${INSTALL_TEST_DIR}:${INSTALL_DIR}/python/python3.11:$PYTHONPATH # TODO: figure out why they need to be reinstalled - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_tf2.txt - python3 -m pip install -r ${{ env.OPENVINO_REPO }}/tools/mo/requirements_dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt + python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt - source ${{ env.INSTALL_DIR }}/setupvars.sh + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest -s ${{ env.INSTALL_TEST_DIR }}/mo/unit_tests \ - --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-ModelOptimizer.xml + python3 -m pytest -s ${INSTALL_TEST_DIR}/mo/unit_tests \ + --junitxml=${INSTALL_TEST_DIR}/TEST-ModelOptimizer.xml - name: PyTorch Layer Tests run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/pytorch_tests -m precommit --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-pytorch.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: TensorFlow 1 Layer Tests - TF FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_fe.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf_fe.xml env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: TensorFlow 2 Layer Tests - TF FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_fe.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: JAX Layer Tests - TF FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/jax_tests/ -m precommit --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-jax.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/jax_tests/ -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-jax.xml env: TEST_DEVICE: CPU - name: TensorFlow 1 Layer Tests - Legacy FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf_Roll.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${INSTALL_TEST_DIR}/TEST-tf_Roll.xml - name: TensorFlow 2 Layer Tests - Legacy FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow2_keras_tests/test_tf2_keras_activation.py \ - --ir_version=11 --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tf2_Activation.xml -k "sigmoid" + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/test_tf2_keras_activation.py \ + --ir_version=11 --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_Activation.xml -k "sigmoid" env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: TensorFlow Lite Layer Tests - TFL FE run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/tensorflow_lite_tests/ --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-tfl_fe.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_lite_tests/ --junitxml=${INSTALL_TEST_DIR}/TEST-tfl_fe.xml env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: MO Python API Tests run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/mo_python_api_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_mo_convert.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/mo_python_api_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_mo_convert.xml env: TEST_DEVICE: CPU TEST_PRECISION: FP16 - name: Python Frontend tests run: | - python3 -m pip install -r ${{ env.LAYER_TESTS_INSTALL_DIR }}/requirements.txt - export PYTHONPATH=${{ env.OPENVINO_REPO }}/tools/mo/:${{ env.LAYER_TESTS_INSTALL_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${{ env.LAYER_TESTS_INSTALL_DIR }}/py_frontend_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-test_py_fontend.xml + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/py_frontend_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_py_fontend.xml - name: Conversion UT run: | # For python imports to import pybind_mock_frontend - export PYTHONPATH=${{ env.INSTALL_TEST_DIR }}:$PYTHONPATH - source ${{ env.INSTALL_DIR }}/setupvars.sh + export PYTHONPATH=${INSTALL_TEST_DIR}:$PYTHONPATH + source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest -s ${{ env.OPENVINO_REPO }}/tools/ovc/unit_tests --junitxml=${{ env.INSTALL_TEST_DIR }}/TEST-OpenVinoConversion.xml + python3 -m pytest -s ${OPENVINO_REPO}/tools/ovc/unit_tests --junitxml=${INSTALL_TEST_DIR}/TEST-OpenVinoConversion.xml - name: Upload Test Results uses: actions/upload-artifact@v3 @@ -732,21 +753,26 @@ jobs: defaults: run: shell: bash - runs-on: ubuntu-20.04-4-cores + runs-on: aks-linux-4-cores + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches env: - INSTALL_DIR: ${{ github.workspace }}/install - INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests - PARALLEL_TEST_SCRIPT: ${{ github.workspace }}/install/tests/functional_test_utils/run_parallel.py - PARALLEL_TEST_CACHE: ${{ github.workspace }}/install/tests/test_cache.lst + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + PARALLEL_TEST_SCRIPT: /__w/openvino/openvino/install/tests/functional_test_utils/run_parallel.py + PARALLEL_TEST_CACHE: /__w/openvino/openvino/install/tests/test_cache.lst steps: - name: Create Directories - run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} - name: Install dependencies run: | - sudo -E apt update - sudo -E apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers + apt update + apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - name: Download OpenVINO package uses: actions/download-artifact@v3 @@ -762,17 +788,21 @@ jobs: - name: Extract OpenVINO packages run: | - pushd ${{ env.INSTALL_DIR }} - tar -xzf openvino_package.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_package.tar.gz || exit 1 + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 popd - pushd ${{ env.INSTALL_TEST_DIR }} - tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz || exit 1 + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install python dependencies run: | python3 -m pip install --upgrade pip - python3 -m pip install -r ${{ env.INSTALL_TEST_DIR }}/functional_test_utils/requirements.txt + python3 -m pip install -r ${INSTALL_TEST_DIR}/functional_test_utils/requirements.txt - name: Restore tests execution time uses: actions/cache/restore@v3 @@ -784,9 +814,9 @@ jobs: - name: Intel CPU plugin func tests (parallel) run: | - source ${{ env.INSTALL_DIR }}/setupvars.sh - python3 ${{ env.PARALLEL_TEST_SCRIPT }} -e ${{ env.INSTALL_TEST_DIR }}/ov_cpu_func_tests -c ${{ env.PARALLEL_TEST_CACHE }} -w ${{ env.INSTALL_TEST_DIR }} -s suite -rf 0 -- --gtest_print_time=1 --gtest_filter=*smoke* - timeout-minutes: 25 + source ${INSTALL_DIR}/setupvars.sh + python3 ${PARALLEL_TEST_SCRIPT} -e ${INSTALL_TEST_DIR}/ov_cpu_func_tests -c ${PARALLEL_TEST_CACHE} -w ${INSTALL_TEST_DIR} -s suite -rf 0 -- --gtest_print_time=1 --gtest_filter=*smoke* + timeout-minutes: 40 - name: Save tests execution time uses: actions/cache/save@v3 @@ -882,6 +912,7 @@ jobs: shell: bash runs-on: ${{ github.event_name == 'schedule' && 'ubuntu-20.04-8-cores' || 'ubuntu-20.04'}} env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input INSTALL_DIR: ${{ github.workspace }}/install INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests @@ -924,6 +955,7 @@ jobs: - name: Install Python wheels run: | python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools + - name: Install requirements run: | python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements.txt diff --git a/tools/mo/unit_tests/mo/utils/cli_parser_test.py b/tools/mo/unit_tests/mo/utils/cli_parser_test.py index 1f2cce048aba07..b3c7c4c125d540 100644 --- a/tools/mo/unit_tests/mo/utils/cli_parser_test.py +++ b/tools/mo/unit_tests/mo/utils/cli_parser_test.py @@ -1224,11 +1224,13 @@ def test_single_writable_dir(self): self.assertEqual(__class__.WRITABLE_DIR, writable_dir(__class__.WRITABLE_DIR)) @unittest.skipIf(sys.platform.startswith("win"), "chmod() on Windows do nor support not writable dir") + @unittest.skipIf(os.geteuid() == 0, "root user does not support not writable dir") def test_single_non_writable_dir(self): with self.assertRaises(Error) as cm: writable_dir(__class__.NOT_WRITABLE_DIR) @unittest.skipIf(sys.platform.startswith("win"), "chmod() on Windows do nor support not writable dir") + @unittest.skipIf(os.geteuid() == 0, "root user does not support not writable dir") def test_single_non_writable_sub_dir(self): with self.assertRaises(Error) as cm: writable_dir(__class__.NOT_WRITABLE_SUB_DIR) From c983b464baf75eb414b544adc81dacbf841a8ad8 Mon Sep 17 00:00:00 2001 From: Sun Xiaoxia Date: Mon, 25 Sep 2023 12:51:09 +0800 Subject: [PATCH 31/43] enable cpu pinning on Windows by setting property affinity CORE (#19418) * set enableCpuPinning=true by '-p YES' * add test case of setting ov::Affinity::CORE * add affinity=NUMA/HYBRID_AWARW * fix build failure --- src/plugins/intel_cpu/src/config.cpp | 10 ++++++++ .../intel_cpu/src/cpu_map_scheduling.cpp | 12 ++-------- .../intel_cpu/src/cpu_map_scheduling.hpp | 2 -- .../intel_cpu/src/cpu_streams_calculation.cpp | 1 - .../behavior/ov_plugin/properties.cpp | 20 ++++++++++++++++ .../unit/streams_info/streams_e2e_test.cpp | 24 ------------------- 6 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp index 10630c8891dddf..277bdb412563e7 100644 --- a/src/plugins/intel_cpu/src/config.cpp +++ b/src/plugins/intel_cpu/src/config.cpp @@ -79,6 +79,16 @@ void Config::readProperties(const std::map &prop, cons if (streamExecutorConfigKeys.end() != std::find(std::begin(streamExecutorConfigKeys), std::end(streamExecutorConfigKeys), key)) { streamExecutorConfig.SetConfig(key, val); + if (key == ov::affinity.name()) { + const auto affinity_val = ov::util::from_string(val, ov::affinity); + if (affinity_val == ov::Affinity::CORE || affinity_val == ov::Affinity::HYBRID_AWARE) { + enableCpuPinning = true; + changedCpuPinning = true; + } else if (affinity_val == ov::Affinity::NUMA) { + enableCpuPinning = false; + changedCpuPinning = true; + } + } } else if (hintsConfigKeys.end() != std::find(hintsConfigKeys.begin(), hintsConfigKeys.end(), key)) { perfHintsConfig.SetConfig(key, val); } else if (key == ov::hint::enable_cpu_pinning.name()) { diff --git a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp index 9efcc23ddf2fd7..5b125f45934e26 100644 --- a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp +++ b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp @@ -72,7 +72,6 @@ std::vector> apply_hyper_threading(bool& input_ht_hint, bool get_cpu_pinning(bool& input_value, const bool input_changed, const int num_streams, - const threading::IStreamsExecutor::ThreadBindingType bind_type, const Config::LatencyThreadingMode latency_threading_mode, const std::vector>& proc_type_table) { int result_value; @@ -82,18 +81,11 @@ bool get_cpu_pinning(bool& input_value, if (input_changed) { result_value = input_value; } else { + result_value = true; if (proc_type_table[0][EFFICIENT_CORE_PROC] > 0 && proc_type_table[0][EFFICIENT_CORE_PROC] < proc_type_table[0][ALL_PROC]) { - result_value = - ((latency || bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA) ? false : true); - } else { - result_value = (bind_type == threading::IStreamsExecutor::ThreadBindingType::NUMA ? false : true); + result_value = latency ? false : true; } -#if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO) -# if defined(_WIN32) - result_value = false; -# endif -#endif } #if (IE_THREAD == IE_THREAD_TBB || IE_THREAD == IE_THREAD_TBB_AUTO) # if defined(_WIN32) diff --git a/src/plugins/intel_cpu/src/cpu_map_scheduling.hpp b/src/plugins/intel_cpu/src/cpu_map_scheduling.hpp index 6da16053bcae12..950f5e5d6f46a6 100644 --- a/src/plugins/intel_cpu/src/cpu_map_scheduling.hpp +++ b/src/plugins/intel_cpu/src/cpu_map_scheduling.hpp @@ -45,7 +45,6 @@ std::vector> apply_hyper_threading(bool& input_ht_hint, * @param[in] input_type indicate value of property enableCpuPinning. * @param[in] input_changed indicate if value is set by user. * @param[in] num_streams number of streams - * @param[in] bind_type thread binding core type * @param[in] latency_threading_mode is the scope of candidate processors per stream for latency hint * @param[in] proc_type_table candidate processors available at this time * @return whether pinning threads to cpu cores @@ -53,7 +52,6 @@ std::vector> apply_hyper_threading(bool& input_ht_hint, bool get_cpu_pinning(bool& input_value, const bool input_changed, const int num_streams, - const threading::IStreamsExecutor::ThreadBindingType bind_type, const Config::LatencyThreadingMode latency_threading_mode, const std::vector>& proc_type_table); diff --git a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp b/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp index 64d7cdb40245c3..f9e336bcaba279 100644 --- a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp +++ b/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp @@ -502,7 +502,6 @@ std::vector> generate_stream_info(const int streams, executor_config._cpu_reservation = get_cpu_pinning(config.enableCpuPinning, config.changedCpuPinning, streams, - executor_config._threadBindingType, config.latencyThreadingMode, proc_type_table); if (-1 == preferred_nthreads_per_stream) { diff --git a/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp b/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp index 12df6009e93b6b..0e959ab865a6ed 100644 --- a/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp +++ b/src/plugins/intel_cpu/tests/functional/behavior/ov_plugin/properties.cpp @@ -153,6 +153,26 @@ TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigAffinity) { ASSERT_EQ(affinity, value); } +TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigAffinityCore) { + ov::Core ie; + ov::Affinity affinity = ov::Affinity::CORE; + bool value = false; + + ASSERT_NO_THROW(ie.set_property("CPU", ov::affinity(affinity))); + ASSERT_NO_THROW(value = ie.get_property("CPU", ov::hint::enable_cpu_pinning)); + ASSERT_EQ(true, value); + + affinity = ov::Affinity::HYBRID_AWARE; + ASSERT_NO_THROW(ie.set_property("CPU", ov::affinity(affinity))); + ASSERT_NO_THROW(value = ie.get_property("CPU", ov::hint::enable_cpu_pinning)); + ASSERT_EQ(true, value); + + affinity = ov::Affinity::NUMA; + ASSERT_NO_THROW(ie.set_property("CPU", ov::affinity(affinity))); + ASSERT_NO_THROW(value = ie.get_property("CPU", ov::hint::enable_cpu_pinning)); + ASSERT_EQ(false, value); +} + TEST_F(OVClassConfigTestCPU, smoke_PluginSetConfigHintInferencePrecision) { ov::Core ie; auto value = ov::element::f32; diff --git a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp index 1bcdb6f84ef590..7174b616377456 100644 --- a/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp +++ b/src/plugins/intel_cpu/tests/unit/streams_info/streams_e2e_test.cpp @@ -29,7 +29,6 @@ struct StreamGenerateionTestCase { bool input_cpu_changed; ov::hint::PerformanceMode input_pm_hint; ov::intel_cpu::Config::LatencyThreadingMode input_latency_threading_mode; - ov::threading::IStreamsExecutor::ThreadBindingType input_binding_type; std::vector> input_proc_type_table; ov::hint::SchedulingCoreType output_type; bool output_ht_value; @@ -51,7 +50,6 @@ void make_config(StreamGenerateionTestCase& test_data, ov::intel_cpu::Config& co config.streamExecutorConfig._streams = test_data.input_stream; config.streamExecutorConfig._streams_changed = test_data.input_stream_changed; config.streamExecutorConfig._threads = test_data.input_thread; - config.streamExecutorConfig._threadBindingType = test_data.input_binding_type; } class StreamGenerationTests : public ov::test::TestsCommon, @@ -95,8 +93,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_1_pinning = { ov::hint::PerformanceMode::LATENCY, // param[in]: simulated setting for performance mode (throughput/latency) ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, // param[in]: simulated setting for scope of candidate // processors on latency mode - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, // param[in]: simulated setting for - // threadBindingType {{20, 6, 8, 6, 0, 0}}, // param[in]: simulated proc_type_table for platform which has one socket, 6 Pcores, 8 // Ecores and hyper threading enabled ov::hint::SchedulingCoreType::ANY_CORE, // param[expected out]: scheduling core type needs to be the same as input @@ -125,7 +121,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_2_pinning = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{14, 6, 8, 0, 0, 0}}, ov::hint::SchedulingCoreType::ANY_CORE, false, @@ -148,7 +143,6 @@ StreamGenerateionTestCase generation_tput_1sockets_14cores_1_pinning = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::ANY_CORE, true, @@ -171,7 +165,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_1_unpinning = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::ANY_CORE, true, @@ -197,7 +190,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_2_unpinning = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{14, 6, 8, 0, 0, 0}}, ov::hint::SchedulingCoreType::ANY_CORE, false, @@ -220,7 +212,6 @@ StreamGenerateionTestCase generation_tput_1sockets_14cores_1_unpinning = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::ANY_CORE, true, @@ -243,7 +234,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_3 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{14, 6, 8, 0, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -266,7 +256,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_4 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, true, @@ -289,7 +278,6 @@ StreamGenerateionTestCase generation_latency_1sockets_14cores_5 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -312,7 +300,6 @@ StreamGenerateionTestCase generation_latency_2sockets_48cores_6 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -335,7 +322,6 @@ StreamGenerateionTestCase generation_latency_2sockets_48cores_7 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -358,7 +344,6 @@ StreamGenerateionTestCase generation_latency_2sockets_48cores_8 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -381,7 +366,6 @@ StreamGenerateionTestCase generation_latency_2sockets_48cores_9 = { true, ov::hint::PerformanceMode::LATENCY, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::HYBRID_AWARE, {{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -404,7 +388,6 @@ StreamGenerateionTestCase generation_tput_1sockets_14cores_2 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, false, @@ -427,7 +410,6 @@ StreamGenerateionTestCase generation_tput_1sockets_14cores_3 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, true, @@ -450,7 +432,6 @@ StreamGenerateionTestCase generation_tput_1sockets_14cores_4 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{20, 6, 8, 6, 0, 0}}, ov::hint::SchedulingCoreType::PCORE_ONLY, true, @@ -473,7 +454,6 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_5 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::ANY_CORE, true, @@ -499,7 +479,6 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_6 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::ANY_CORE, false, @@ -522,7 +501,6 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_7 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::ANY_CORE, false, @@ -545,7 +523,6 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_8 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::ANY_CORE, false, @@ -568,7 +545,6 @@ StreamGenerateionTestCase generation_tput_2sockets_48cores_9 = { true, ov::hint::PerformanceMode::THROUGHPUT, ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, - ov::threading::IStreamsExecutor::ThreadBindingType::CORES, {{96, 48, 0, 48, -1, -1}, {48, 24, 0, 24, 0, 0}, {48, 24, 0, 24, 1, 1}}, ov::hint::SchedulingCoreType::ANY_CORE, false, From 2e88aa07705eab765a417dbaada2e00f6f2256d2 Mon Sep 17 00:00:00 2001 From: Roman Lyamin Date: Mon, 25 Sep 2023 09:23:47 +0400 Subject: [PATCH 32/43] [GPU] Added int32 weights support for reorder_weights kernels (#20015) --- .../include/intel_gpu/primitives/reorder.hpp | 2 +- .../impls/ocl/kernel_selector_helper.cpp | 16 +-- .../src/kernel_selector/common_tools.h | 1 + .../src/kernel_selector/common_types.h | 1 + .../intel_gpu/src/kernel_selector/jitter.cpp | 4 + .../kernel_selector_common.cpp | 1 + .../kernel_selector_params.cpp | 4 + .../kernel_selector/kernel_selector_utils.cpp | 2 + .../reorder/reorder_weights_kernel.cpp | 2 + .../kernels/reorder/reorder_weights_opt.cpp | 2 + .../unit/test_cases/reorder_gpu_test.cpp | 98 +++++++++++++++++++ 11 files changed, 124 insertions(+), 9 deletions(-) diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/reorder.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/reorder.hpp index 7b2ada5d77f1ab..b9c86b7391a485 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/reorder.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/reorder.hpp @@ -20,7 +20,7 @@ enum class reorder_mean_mode { }; struct WeightsReorderParams { - WeightsReorderParams(const layout& in_layout, const layout& out_layout, bool transposed, bool grouped = false) + WeightsReorderParams(const layout& in_layout, const layout& out_layout, bool transposed = false, bool grouped = false) : _in_layout(in_layout), _out_layout(out_layout), _transposed(transposed), diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp index 281daf7108c717..5cc70002debf39 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp @@ -136,8 +136,7 @@ kernel_selector::data_type to_data_type(data_types dt) { case cldnn::data_types::f32: return kernel_selector::data_type::F32; default: - assert(0); - return kernel_selector::data_type::F16; + OPENVINO_THROW("[GPU] Unable to convert cldnn data type ", dt, " to kernel_selector data type"); } } @@ -158,8 +157,7 @@ data_types from_data_type(kernel_selector::data_type dt) { case kernel_selector::data_type::F32: return cldnn::data_types::f32; default: - assert(0); - return cldnn::data_types::f16; + OPENVINO_THROW("[GPU] Unable to convert kernel_selector data type ", kernel_selector::toString(dt), " to cldnn data type"); } } @@ -175,9 +173,10 @@ kernel_selector::weights_type to_weights_type(data_types dt) { return kernel_selector::weights_type::F16; case cldnn::data_types::f32: return kernel_selector::weights_type::F32; + case cldnn::data_types::i32: + return kernel_selector::weights_type::INT32; default: - assert(0); - return kernel_selector::weights_type::F16; + OPENVINO_THROW("[GPU] Unable to convert cldnn data type ", dt, " to kernel_selector weights type"); } } @@ -193,9 +192,10 @@ data_types from_weights_type(kernel_selector::weights_type dt) { return data_types::f16; case kernel_selector::weights_type::F32: return data_types::f32; + case kernel_selector::weights_type::INT32: + return data_types::i32; default: - assert(0); - return data_types::f16; + OPENVINO_THROW("[GPU] Unable to convert kernel_selector weights type ", kernel_selector::toString(dt), " to cldnn data type"); } } diff --git a/src/plugins/intel_gpu/src/kernel_selector/common_tools.h b/src/plugins/intel_gpu/src/kernel_selector/common_tools.h index f9a2ddbf83a476..b9f3e69acf8c3e 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/common_tools.h +++ b/src/plugins/intel_gpu/src/kernel_selector/common_tools.h @@ -41,6 +41,7 @@ inline uint32_t BytesPerElement(WeightsType wt) { return 2; case WeightsType::F32: case WeightsType::BINARY: + case WeightsType::INT32: return 4; default: throw std::runtime_error("[GPU] BytesPerElement doesn't support given precision"); diff --git a/src/plugins/intel_gpu/src/kernel_selector/common_types.h b/src/plugins/intel_gpu/src/kernel_selector/common_types.h index 1dc4155b2ff86f..464877342ea6a0 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/common_types.h +++ b/src/plugins/intel_gpu/src/kernel_selector/common_types.h @@ -125,6 +125,7 @@ enum class WeightsType { F32, INT8, UINT8, + INT32 }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp index 09a219306c26f7..92dbe560ef6e1d 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp @@ -123,6 +123,8 @@ std::string toCLType(WeightsType wType) { return "half"; case WeightsType::F32: return GetTypeName(); + case WeightsType::INT32: + return GetTypeName(); default: return ""; } @@ -1505,6 +1507,8 @@ JitConstants MakeTypeJitConstants(WeightsType weightsType, const std::string& ma return MakeTypeJitConstants(Datatype::UINT8, macroName); case WeightsType::BINARY: return MakeTypeJitConstants(Datatype::UINT32, macroName); + case WeightsType::INT32: + return MakeTypeJitConstants(Datatype::INT32, macroName); } assert(false || "Unreachable!"); // FIXME: Is there some builtin_unreachable available? diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp index 2538197d08eed7..dfae8451980674 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp @@ -157,6 +157,7 @@ std::string toString(WeightsType wType) { case WeightsType::F32: return "F32"; case WeightsType::INT8: return "INT8"; case WeightsType::UINT8: return "UINT8"; + case WeightsType::INT32: return "INT32"; default: return ""; } } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp index 0c294882a24e7e..32d451704fafa4 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_params.cpp @@ -137,6 +137,8 @@ void ParamsKey::EnableInputWeightsType(WeightsType wt) { case WeightsType::BINARY: key.inputWeightsType.val.binary = 1; break; + case WeightsType::INT32: + key.inputWeightsType.val.int32 = 1; default: break; } @@ -158,6 +160,8 @@ void ParamsKey::EnableOutputWeightsType(WeightsType wt) { case WeightsType::BINARY: key.outputWeightsType.val.binary = 1; break; + case WeightsType::INT32: + key.outputWeightsType.val.int32 = 1; default: break; } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp index f1914ddfc78d24..59a003c554eb62 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.cpp @@ -26,6 +26,8 @@ static WeightsType DataTypeToWeightsType(Datatype t) { return WeightsType::F32; case Datatype::BINARY: return WeightsType::BINARY; + case Datatype::INT32: + return WeightsType::INT32; default: return WeightsType::UNSUPPORTED; } diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_kernel.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_kernel.cpp index 67c48716fcbbd9..dacdc3ecf49afa 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_kernel.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_kernel.cpp @@ -12,9 +12,11 @@ ParamsKey ReorderWeightsKernel::GetSupportedKey() const { k.EnableInputWeightsType(WeightsType::INT8); k.EnableInputWeightsType(WeightsType::F16); k.EnableInputWeightsType(WeightsType::F32); + k.EnableInputWeightsType(WeightsType::INT32); k.EnableOutputWeightsType(WeightsType::INT8); k.EnableOutputWeightsType(WeightsType::F16); k.EnableOutputWeightsType(WeightsType::F32); + k.EnableOutputWeightsType(WeightsType::INT32); k.EnableAllInputWeightsLayout(); k.EnableAllOutputWeightsLayout(); k.EnableDifferentTypes(); diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_opt.cpp index a5d26a4a3ba623..9a9333c757be4f 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_opt.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_weights_opt.cpp @@ -13,9 +13,11 @@ ParamsKey ReorderWeightsOpt::GetSupportedKey() const { k.EnableInputWeightsType(WeightsType::INT8); k.EnableInputWeightsType(WeightsType::F16); k.EnableInputWeightsType(WeightsType::F32); + k.EnableInputWeightsType(WeightsType::INT32); k.EnableOutputWeightsType(WeightsType::INT8); k.EnableOutputWeightsType(WeightsType::F16); k.EnableOutputWeightsType(WeightsType::F32); + k.EnableOutputWeightsType(WeightsType::INT32); k.EnableInputWeightsLayout(WeightsLayout::oiyx); k.EnableInputWeightsLayout(WeightsLayout::ioyx); k.EnableInputWeightsLayout(WeightsLayout::oizyx); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp index 9ad80f4066c933..669162d73ae2e8 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp @@ -1928,6 +1928,104 @@ TEST(reorder_gpu_i32, basic) ASSERT_EQ(*(a_ptr++), val); } +TEST(reorder_weights_gpu_i32, reorder_weights) +{ + auto& engine = get_test_engine(); + + layout in_layout(data_types::f32, format::bfyx, { 2, 2, 2, 2 }); + layout out_layout(data_types::i32, format::oiyx, { 2, 2, 2, 2 }); + auto weights_reorder_params = std::make_shared(in_layout, out_layout); + + auto input = engine.allocate_memory(in_layout); + + set_values(input, { + 1.f, 0.f, 5.f, 1.5f, + 2.f, 0.f, 6.f, 5.2f, + 3.f, 0.5f, 7.f, 12.f, + 4.f, -0.5f, 8.f, 8.f + }); + + topology topology { + input_layout("input", in_layout), + reorder("reorder", input_info("input"), weights_reorder_params) + }; + + ExecutionConfig config = get_test_default_config(engine); + ov::intel_gpu::ImplementationDesc wr_impl_desc = { format::oiyx, "reorder_weights", impl_types::ocl }; + config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"reorder", wr_impl_desc} })); + + network network(engine, topology, config); + network.set_input_data("input", input); + + auto outputs = network.execute(); + ASSERT_EQ(outputs.size(), size_t(1)); + ASSERT_EQ(outputs.begin()->first, "reorder"); + + std::vector ref_output = { + 1, 0, 5, 1, + 2, 0, 6, 5, + 3, 0, 7, 12, + 4, 0, 8, 8 + }; + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + + ASSERT_EQ(output_ptr.size(), ref_output.size()); + for (size_t i = 0; i < ref_output.size(); ++i) { + ASSERT_EQ(output_ptr[i], ref_output[i]); + } +} + +TEST(reorder_weights_gpu_i32, reorder_weights_opt) +{ + auto& engine = get_test_engine(); + + layout in_layout(data_types::f32, format::bfyx, { 16, 1, 2, 1 }); + layout out_layout(data_types::i32, format::os_iyx_osv16, { 16, 1, 2, 1 }); + auto weights_reorder_params = std::make_shared(in_layout, out_layout); + + auto input = engine.allocate_memory(in_layout); + + set_values(input, { + 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, + 8.f, 9.f, 10.f, 0.5f, 12.f, 13.f, 14.f, 15.f, + 16.f, 17.f, 18.f, 19.f, 20.f, -1.6f, 22.f, 23.f, + -1.0f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f + }); + + topology topology { + input_layout("input", in_layout), + reorder("reorder", input_info("input"), weights_reorder_params) + }; + + ExecutionConfig config = get_test_default_config(engine); + ov::intel_gpu::ImplementationDesc wr_impl_desc = { format::os_iyx_osv16, "reorder_weights_opt", impl_types::ocl }; + config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"reorder", wr_impl_desc} })); + + network network(engine, topology, config); + network.set_input_data("input", input); + + auto outputs = network.execute(); + ASSERT_EQ(outputs.size(), size_t(1)); + ASSERT_EQ(outputs.begin()->first, "reorder"); + + std::vector ref_output = { + 0, 2, 4, 6, 8, 10, 12, 14, + 16, 18, 20, 22, -1, 26, 28, 30, + 1, 3, 5, 7, 9, 0, 13, 15, + 17, 19, -1, 23, 25, 27, 29, 31 + }; + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + + ASSERT_EQ(output_ptr.size(), ref_output.size()); + for (size_t i = 0; i < ref_output.size(); ++i) { + ASSERT_EQ(output_ptr[i], ref_output[i]); + } +} + TEST(reorder_gpu_i64, basic) { // Test for converting data types f32->i64 From f82c668d2839779bea4636f460d7d58fd2dbf94d Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Mon, 25 Sep 2023 09:29:57 +0200 Subject: [PATCH 33/43] Refactor GatherLayerTest, GatherElementsLayerTest (#20020) * Refactor GatherLayerTest * Refactor GatherElementsLayerTest --- .../single_layer_tests/gather.cpp | 283 +++++++----------- .../single_layer_tests/gather_elements.cpp | 73 +++-- .../shared/include/single_op_tests/gather.hpp | 27 ++ .../single_op_tests/gather_elements.hpp | 15 + .../shared_test_classes/single_op/gather.hpp | 67 +++++ .../single_op/gather_elements.hpp | 34 +++ .../src/single_op/gather.cpp | 171 +++++++++++ .../src/single_op/gather_elements.cpp | 65 ++++ 8 files changed, 517 insertions(+), 218 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp create mode 100644 src/tests/functional/plugin/shared/include/single_op_tests/gather_elements.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather_elements.hpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/gather.cpp create mode 100644 src/tests/functional/shared_test_classes/src/single_op/gather_elements.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp index e08fc04c3e7750..b82cadb87d9d80 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather.cpp @@ -4,47 +4,35 @@ #include -#include "single_layer_tests/gather.hpp" -#include "ngraph_functions/builders.hpp" - -using namespace LayerTestsDefinitions; +#include "single_op_tests/gather.hpp" namespace { +using ov::test::Gather7LayerTest; +using ov::test::Gather8LayerTest; -const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::BF16, - InferenceEngine::Precision::I8 +const std::vector model_types = { + ov::element::f32, + ov::element::bf16, + ov::element::i8 }; // Just need to check types transformation. -const std::vector netPrecisionsTrCheck = { - InferenceEngine::Precision::I64, - InferenceEngine::Precision::FP16 +const std::vector model_types_tr_check = { + ov::element::i64, + ov::element::f16 }; -const std::vector> inputShapes_1D = { - std::vector{4}, -}; +const std::vector input_shapes_1d = {{4}}; -const std::vector> indicesShapes_1D = { - std::vector{1}, - std::vector{3}, -}; +const std::vector indices_shapes_1d = {{1}, {3}}; -const std::vector> axes_batchdims_1D = { - std::tuple{0, 0} -}; +const std::vector> axes_batchdims_1d = {{0, 0}}; const auto gather7Params_1D = testing::Combine( - testing::ValuesIn(inputShapes_1D), - testing::ValuesIn(indicesShapes_1D), - testing::ValuesIn(axes_batchdims_1D), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_1d)), + testing::ValuesIn(indices_shapes_1d), + testing::ValuesIn(axes_batchdims_1d), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); @@ -52,174 +40,100 @@ INSTANTIATE_TEST_SUITE_P(smoke_Gather7_1D, Gather7LayerTest, gather7Params_1D, G INSTANTIATE_TEST_SUITE_P(smoke_TypesTrf, Gather7LayerTest, testing::Combine( - testing::ValuesIn(inputShapes_1D), - testing::ValuesIn(indicesShapes_1D), - testing::ValuesIn(axes_batchdims_1D), - testing::ValuesIn(netPrecisionsTrCheck), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_1d)), + testing::ValuesIn(indices_shapes_1d), + testing::ValuesIn(axes_batchdims_1d), + testing::ValuesIn(model_types_tr_check), testing::Values(ov::test::utils::DEVICE_CPU)), Gather7LayerTest::getTestCaseName); -const std::vector> inputShapes_2D = { - std::vector{4, 19}, -}; +const std::vector input_shapes_2d = {{4, 19}}; -const std::vector> indicesShapes_2D = { - std::vector{4, 1}, - std::vector{4, 2}, -}; +const std::vector indices_shapes_2d = {{4, 1}, {4, 2}}; -const std::vector> axes_batchdims_2D = { - std::tuple{0, 0}, - std::tuple{1, 0}, - std::tuple{1, 1}, - std::tuple{-1, -1}, -}; +const std::vector> axes_batchdims_2d = {{0, 0}, {1, 0}, {1, 1}, {-1, -1}}; const auto gather7Params_2D = testing::Combine( - testing::ValuesIn(inputShapes_2D), - testing::ValuesIn(indicesShapes_2D), - testing::ValuesIn(axes_batchdims_2D), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_2d)), + testing::ValuesIn(indices_shapes_2d), + testing::ValuesIn(axes_batchdims_2d), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_SUITE_P(smoke_Gather7_2D, Gather7LayerTest, gather7Params_2D, Gather7LayerTest::getTestCaseName); -const std::vector> inputShapes4D = { - std::vector{4, 5, 6, 7}, -}; +const std::vector input_shapes_4d = {{4, 5, 6, 7}}; -const std::vector> indicesShapes_BD0 = { - std::vector{4}, - std::vector{2, 2}, - std::vector{3, 3}, - std::vector{5, 2}, - std::vector{3, 2, 4}, -}; +const std::vector indices_shapes_bd0 = {{4}, {2, 2}, {3, 3}, {5, 2}, {3, 2, 4}}; -const std::vector> axes_BD0 = { - std::tuple{0, 0}, - std::tuple{1, 0}, - std::tuple{2, 0}, - std::tuple{-1, 0}, -}; +const std::vector> axes_bd0 = {{0, 0}, {1, 0}, {2, 0}, {-1, 0}}; -const auto gather7ParamsSubset_BD0 = testing::Combine( - testing::ValuesIn(inputShapes4D), - testing::ValuesIn(indicesShapes_BD0), - testing::ValuesIn(axes_BD0), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), +const auto gather7ParamsSubset_bd0 = testing::Combine( + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_4d)), + testing::ValuesIn(indices_shapes_bd0), + testing::ValuesIn(axes_bd0), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_BD0, Gather7LayerTest, gather7ParamsSubset_BD0, Gather7LayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_BD0, Gather8LayerTest, gather7ParamsSubset_BD0, Gather8LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_bd0, Gather7LayerTest, gather7ParamsSubset_bd0, Gather7LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_bd0, Gather8LayerTest, gather7ParamsSubset_bd0, Gather8LayerTest::getTestCaseName); -const std::vector> indicesShapes_BD1 = { - std::vector{4, 2}, - std::vector{4, 5, 3}, - std::vector{4, 1, 2, 3}, -}; +const std::vector indices_shapes_bd1 = {{4, 2}, {4, 5, 3}, {4, 1, 2, 3}}; -const std::vector> axes_BD1 = { - std::tuple{1, 1}, - std::tuple{2, 1}, - std::tuple{-1, 1}, - std::tuple{-2, 1}, -}; +const std::vector> axes_bd1 = {{1, 1}, {2, 1}, {-1, 1}, {-2, 1}}; -const auto gather7ParamsSubset_BD1 = testing::Combine( - testing::ValuesIn(inputShapes4D), - testing::ValuesIn(indicesShapes_BD1), - testing::ValuesIn(axes_BD1), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), +const auto gather7ParamsSubset_bd1 = testing::Combine( + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_4d)), + testing::ValuesIn(indices_shapes_bd1), + testing::ValuesIn(axes_bd1), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_Gather7_BD1, Gather7LayerTest, gather7ParamsSubset_BD1, Gather7LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Gather7_bd1, Gather7LayerTest, gather7ParamsSubset_bd1, Gather7LayerTest::getTestCaseName); -const std::vector> indicesShapes_BD2 = { - std::vector{4, 5, 4, 3}, - std::vector{4, 5, 3, 2} -}; +const std::vector indices_shapes_bd2 = {{4, 5, 4, 3}, {4, 5, 3, 2}}; -const std::vector> axes_BD2 = { - std::tuple{2, 2}, - std::tuple{3, -2}, - std::tuple{-1, 2}, - std::tuple{-1, -2}, -}; +const std::vector> axes_bd2 = {{2, 2}, {3, -2}, {-1, 2}, {-1, -2}}; -const auto gather7ParamsSubset_BD2 = testing::Combine( - testing::ValuesIn(inputShapes4D), - testing::ValuesIn(indicesShapes_BD2), - testing::ValuesIn(axes_BD2), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), +const auto gather7ParamsSubset_bd2 = testing::Combine( + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_4d)), + testing::ValuesIn(indices_shapes_bd2), + testing::ValuesIn(axes_bd2), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_Gather7_BD2, Gather7LayerTest, gather7ParamsSubset_BD2, Gather7LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Gather7_bd2, Gather7LayerTest, gather7ParamsSubset_bd2, Gather7LayerTest::getTestCaseName); -const std::vector> indicesShapes_NegativeBD = { - std::vector{4, 5, 4}, - std::vector{4, 5, 3} -}; +const std::vector indices_shapes_negative_bd = {{4, 5, 4}, {4, 5, 3}}; -const std::vector> axes_NegativeBD = { - std::tuple{0, -3}, - std::tuple{1, -2}, - std::tuple{2, -2}, - std::tuple{-2, -2}, - std::tuple{-1, -1}, - std::tuple{-2, -1}, -}; +const std::vector> axes_negative_bd = {{0, -3}, {1, -2}, {2, -2}, {-2, -2}, {-1, -1}, {-2, -1}}; -const auto gather7ParamsSubset_NegativeBD = testing::Combine( - testing::ValuesIn(inputShapes4D), - testing::ValuesIn(indicesShapes_NegativeBD), - testing::ValuesIn(axes_NegativeBD), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), +const auto gather7ParamsSubset_negative_bd = testing::Combine( + testing::Values(ov::test::static_shapes_to_test_representation(input_shapes_4d)), + testing::ValuesIn(indices_shapes_negative_bd), + testing::ValuesIn(axes_negative_bd), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); -INSTANTIATE_TEST_SUITE_P(smoke_Gather7_NegativeBD, Gather7LayerTest, gather7ParamsSubset_NegativeBD, Gather7LayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_Gather7_negative_bd, Gather7LayerTest, gather7ParamsSubset_negative_bd, Gather7LayerTest::getTestCaseName); ///// GATHER-8 ///// -const std::vector> dataShapes4DGather8 = { - {10, 3, 1, 2}, - {10, 3, 3, 1}, - {10, 2, 2, 7}, - {10, 2, 2, 2}, - {10, 3, 4, 4}, - {10, 2, 3, 17} +const std::vector> data_shapes_4d_gather8 = { + {{10, 3, 1, 2}}, + {{10, 3, 3, 1}}, + {{10, 2, 2, 7}}, + {{10, 2, 2, 2}}, + {{10, 3, 4, 4}}, + {{10, 2, 3, 17}} }; -const std::vector> idxShapes4DGather8 = { +const std::vector idx_shapes_4d_gather8 = { {10, 1, 1}, {10, 1, 2}, {10, 1, 3}, @@ -231,7 +145,7 @@ const std::vector> idxShapes4DGather8 = { {10, 7, 3}, {10, 8, 7} }; -const std::vector> axesBatches4DGather8 = { +const std::vector> axes_batches_4d_gather8 = { {3, 0}, {-1, -2}, {2, -3}, @@ -243,40 +157,47 @@ const std::vector> axesBatches4DGather8 = { INSTANTIATE_TEST_CASE_P(smoke_static_4D, Gather8LayerTest, testing::Combine( - testing::ValuesIn(dataShapes4DGather8), - testing::ValuesIn(idxShapes4DGather8), - testing::ValuesIn(axesBatches4DGather8), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(data_shapes_4d_gather8)), + testing::ValuesIn(idx_shapes_4d_gather8), + testing::ValuesIn(axes_batches_4d_gather8), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU)), Gather8LayerTest::getTestCaseName); + +const std::vector> data_shapes_vec2_gather8 = { + {{5, 4}}, + {{11, 4}}, + {{23, 4}}, + {{35, 4}}, + {{51, 4}}, + {{71, 4}} +}; +const std::vector idx_shapes_vec2_gather8 = {{1}}; + +const std::vector> axes_batches_vec2_gather8 = {{1, 0}}; + const auto gatherParamsVec2 = testing::Combine( - testing::ValuesIn(std::vector>({{5, 4}, {11, 4}, {23, 4}, {35, 4}, {51, 4}, {71, 4}})), - testing::ValuesIn(std::vector>({{1}})), - testing::ValuesIn(std::vector>{std::tuple{1, 0}}), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::ValuesIn(ov::test::static_shapes_to_test_representation(data_shapes_vec2_gather8)), + testing::ValuesIn(idx_shapes_vec2_gather8), + testing::ValuesIn(axes_batches_vec2_gather8), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); INSTANTIATE_TEST_CASE_P(smoke_Vec2, Gather8LayerTest, gatherParamsVec2, Gather8LayerTest::getTestCaseName); + +const std::vector data_shapes_vec3_gather8 = {{4, 4}}; +const std::vector idx_shapes_vec3_gather8 = {{5}, {11}, {21}, {35}, {55}, {70}}; + +const std::vector> axes_batches_vec3_gather8 = {{1, 0}}; + const auto gatherParamsVec3 = testing::Combine( - testing::ValuesIn(std::vector>({{4, 4}})), - testing::ValuesIn(std::vector>({{5}, {11}, {21}, {35}, {55}, {70}})), - testing::ValuesIn(std::vector>{std::tuple{1, 0}}), - testing::ValuesIn(netPrecisions), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Precision::UNSPECIFIED), - testing::Values(InferenceEngine::Layout::ANY), - testing::Values(InferenceEngine::Layout::ANY), + testing::Values(ov::test::static_shapes_to_test_representation(data_shapes_vec3_gather8)), + testing::ValuesIn(idx_shapes_vec3_gather8), + testing::ValuesIn(axes_batches_vec3_gather8), + testing::ValuesIn(model_types), testing::Values(ov::test::utils::DEVICE_CPU) ); diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp index ade161481815fa..881b395d4e7638 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/gather_elements.cpp @@ -4,72 +4,71 @@ #include -#include "single_layer_tests/gather_elements.hpp" +#include "single_op_tests/gather_elements.hpp" #include "common_test_utils/test_constants.hpp" -using namespace LayerTestsDefinitions; - namespace { +using ov::test::GatherElementsLayerTest; -const std::vector dPrecisions = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64, - InferenceEngine::Precision::I16, +const std::vector model_types = { + ov::element::f32, + ov::element::f16, + ov::element::i32, + ov::element::i64, + ov::element::i16, }; -const std::vector iPrecisions = { - InferenceEngine::Precision::I32, - InferenceEngine::Precision::I64 +const std::vector indices_types = { + ov::element::i32, + ov::element::i64 }; INSTANTIATE_TEST_SUITE_P(smoke_set1, GatherElementsLayerTest, ::testing::Combine( - ::testing::Values(std::vector({2, 2})), // Data shape - ::testing::Values(std::vector({2, 2})), // Indices shape - ::testing::ValuesIn(std::vector({-1, 0, 1})), // Axis - ::testing::ValuesIn(dPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{2, 2}})), + ::testing::Values(ov::Shape{2, 2}), + ::testing::ValuesIn(std::vector{-1, 0, 1}), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(indices_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), GatherElementsLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_set2, GatherElementsLayerTest, ::testing::Combine( - ::testing::Values(std::vector({2, 2, 1})), // Data shape - ::testing::Values(std::vector({4, 2, 1})), // Indices shape - ::testing::ValuesIn(std::vector({0, -3})), // Axis - ::testing::ValuesIn(dPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{2, 2, 1}})), + ::testing::Values(ov::Shape{4, 2, 1}), + ::testing::ValuesIn(std::vector({0, -3})), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(indices_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), GatherElementsLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_set3, GatherElementsLayerTest, ::testing::Combine( - ::testing::Values(std::vector({2, 2, 3, 5})), // Data shape - ::testing::Values(std::vector({2, 2, 3, 7})), // Indices shape - ::testing::Values(3, -1), // Axis - ::testing::ValuesIn(dPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{2, 2, 3, 5}})), + ::testing::Values(ov::Shape{2, 2, 3, 7}), + ::testing::Values(3, -1), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(indices_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), GatherElementsLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_set4, GatherElementsLayerTest, ::testing::Combine( - ::testing::Values(std::vector({3, 2, 3, 8})), // Data shape - ::testing::Values(std::vector({2, 2, 3, 8})), // Indices shape - ::testing::Values(0, -4), // Axis - ::testing::ValuesIn(dPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{3, 2, 3, 8}})), + ::testing::Values(ov::Shape{2, 2, 3, 8}), + ::testing::Values(0, -4), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(indices_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), GatherElementsLayerTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_set5, GatherElementsLayerTest, ::testing::Combine( - ::testing::Values(std::vector({3, 2, 3, 4, 8})), // Data shape - ::testing::Values(std::vector({3, 2, 3, 5, 8})), // Indices shape - ::testing::Values(3, -2), // Axis - ::testing::ValuesIn(dPrecisions), - ::testing::ValuesIn(iPrecisions), + ::testing::Values(ov::test::static_shapes_to_test_representation({ov::Shape{3, 2, 3, 4, 8}})), + ::testing::Values(ov::Shape{3, 2, 3, 5, 8}), + ::testing::Values(3, -2), + ::testing::ValuesIn(model_types), + ::testing::ValuesIn(indices_types), ::testing::Values(ov::test::utils::DEVICE_CPU)), GatherElementsLayerTest::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp new file mode 100644 index 00000000000000..6c27459fc18712 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/gather.hpp @@ -0,0 +1,27 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/gather.hpp" + +namespace ov { +namespace test { +TEST_P(GatherLayerTest, Inference) { + run(); +}; + +TEST_P(Gather7LayerTest, Inference) { + run(); +}; + +TEST_P(Gather8LayerTest, Inference) { + run(); +}; + +TEST_P(Gather8IndiceScalarLayerTest, Inference) { + run(); +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/gather_elements.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/gather_elements.hpp new file mode 100644 index 00000000000000..e861b69c849503 --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_op_tests/gather_elements.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "shared_test_classes/single_op/gather_elements.hpp" + +namespace ov { +namespace test { +TEST_P(GatherElementsLayerTest, Inference) { + run(); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp new file mode 100644 index 00000000000000..36d6ba48dfd25a --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather.hpp @@ -0,0 +1,67 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Indices + ov::Shape, // Indices shape + int, // Gather axis + std::vector, // Input shapes + ov::element::Type, // Model type + std::string // Device name +> gatherParamsTuple; + +class GatherLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); +protected: + void SetUp() override; +}; + +typedef std::tuple< + std::vector, // Input shapes + ov::Shape, // Indices shape + std::tuple, // Gather axis and batch + ov::element::Type, // Model type + std::string // Device name +> gather7ParamsTuple; + +class Gather7LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +class Gather8LayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +class Gather8IndiceScalarLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather_elements.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather_elements.hpp new file mode 100644 index 00000000000000..c6ec38b801b053 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_op/gather_elements.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +typedef std::tuple< + std::vector, // Input shapes + ov::Shape, // Indices shape + int, // Axis + ov::element::Type, // Model type + ov::element::Type, // Indices type + std::string // Device name +> GatherElementsParams; + +class GatherElementsLayerTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; + +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/gather.cpp b/src/tests/functional/shared_test_classes/src/single_op/gather.cpp new file mode 100644 index 00000000000000..0dad09af952720 --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/gather.cpp @@ -0,0 +1,171 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/gather.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/gather.hpp" + +namespace ov { +namespace test { +std::string GatherLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + int axis; + std::vector indices; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::string device_name; + std::tie(indices, indices_shape, axis, shapes, model_type, device_name) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "axis=" << axis << "_"; + result << "indices=" << ov::test::utils::vec2str(indices) << "_"; + result << "indices_shape=" << ov::test::utils::vec2str(indices_shape) << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << device_name << "_"; + return result.str(); +} + +void GatherLayerTest::SetUp() { + int axis; + std::vector indices; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::tie(indices, indices_shape, axis, shapes, model_type, targetDevice) = GetParam(); + init_input_shapes(shapes); + ASSERT_EQ(ov::shape_size(indices_shape), indices.size()) << "Indices vector size and provided indices shape doesn't fit each other"; + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto indices_node = ov::op::v0::Constant::create(ov::element::i64, indices_shape, indices); + auto axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {axis}); + + auto gather = std::make_shared(param, indices_node, axis_node); + auto result = std::make_shared(gather); + function = std::make_shared(result, ov::ParameterVector{param}, "gather"); +} + +std::string Gather7LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::tuple axis_batch_idx; + std::vector indices; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::string device_name; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, device_name) = obj.param; + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "axis=" << std::get<0>(axis_batch_idx) << "_"; + result << "batch_idx=" << std::get<1>(axis_batch_idx) << "_"; + result << "indices_shape=" << ov::test::utils::vec2str(indices_shape) << "_"; + result << "netPRC=" << model_type.get_type_name() << "_"; + result << "trgDev=" << device_name << "_"; + return result.str(); +} + +void Gather7LayerTest::SetUp() { + std::tuple axis_batch_idx; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, targetDevice) = GetParam(); + init_input_shapes(shapes); + + int axis = std::get<0>(axis_batch_idx); + int batch_idx = std::get<1>(axis_batch_idx); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + int axis_dim = targetStaticShapes[0][0][axis < 0 ? axis + targetStaticShapes[0][0].size() : axis]; + auto indices_node_tensor = ov::test::utils::create_and_fill_tensor(ov::element::i64, indices_shape, axis_dim - 1); + auto indices_node = std::make_shared(indices_node_tensor); + auto axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {axis}); + + auto gather = std::make_shared(param, indices_node, axis_node, batch_idx); + + auto result = std::make_shared(gather); + function = std::make_shared(result, ov::ParameterVector{param}, "gather"); +} + +std::string Gather8LayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + return Gather7LayerTest::getTestCaseName(obj); +} + +void Gather8LayerTest::SetUp() { + std::tuple axis_batch_idx; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, targetDevice) = GetParam(); + init_input_shapes(shapes); + + int axis = std::get<0>(axis_batch_idx); + int batch_idx = std::get<1>(axis_batch_idx); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + int axis_dim = targetStaticShapes[0][0][axis < 0 ? axis + targetStaticShapes[0][0].size() : axis]; + auto indices_node_tensor = ov::test::utils::create_and_fill_tensor(ov::element::i64, indices_shape, 2 * axis_dim, -axis_dim); + auto indices_node = std::make_shared(indices_node_tensor); + auto axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {axis}); + + auto gather = std::make_shared(param, indices_node, axis_node, batch_idx); + + auto result = std::make_shared(gather); + function = std::make_shared(result, ov::ParameterVector{param}, "gather"); +} + +std::string Gather8IndiceScalarLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + return Gather7LayerTest::getTestCaseName(obj); +} + +void Gather8IndiceScalarLayerTest::SetUp() { + std::tuple axis_batch_idx; + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type; + std::tie(shapes, indices_shape, axis_batch_idx, model_type, targetDevice) = GetParam(); + init_input_shapes(shapes); + + int axis = std::get<0>(axis_batch_idx); + int batch_idx = std::get<1>(axis_batch_idx); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto indices_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {targetStaticShapes[0][0][axis] - 1}); + auto axis_node = ov::op::v0::Constant::create(ov::element::i64, ov::Shape(), {axis}); + + auto gather = std::make_shared(param, indices_node, axis_node, batch_idx); + + auto result = std::make_shared(gather); + function = std::make_shared(result, ov::ParameterVector{param}, "gather"); +} +} // namespace test +} // namespace ov diff --git a/src/tests/functional/shared_test_classes/src/single_op/gather_elements.cpp b/src/tests/functional/shared_test_classes/src/single_op/gather_elements.cpp new file mode 100644 index 00000000000000..1366ff6505bc6f --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/single_op/gather_elements.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_op/gather_elements.hpp" + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/gather_elements.hpp" + +namespace ov { +namespace test { +std::string GatherElementsLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type, indices_type; + int axis; + std::string device; + std::tie(shapes, indices_shape, axis, model_type, indices_type, device) = obj.param; + + std::ostringstream result; + result << "IS=("; + for (size_t i = 0lu; i < shapes.size(); i++) { + result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < shapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < shapes.size(); j++) { + result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << "IS=" << ov::test::utils::vec2str(indices_shape) << "_"; + result << "Ax=" << axis << "_"; + result << "DP=" << model_type.get_type_name() << "_"; + result << "IP=" << indices_type.get_type_name() << "_"; + result << "device=" << device; + return result.str(); +} + +void GatherElementsLayerTest::SetUp() { + ov::Shape indices_shape; + std::vector shapes; + ov::element::Type model_type, indices_type; + int axis; + std::tie(shapes, indices_shape, axis, model_type, indices_type, targetDevice) = this->GetParam(); + init_input_shapes(shapes); + + auto param = std::make_shared(model_type, inputDynamicShapes.front()); + + auto axis_dim = targetStaticShapes[0][0][axis < 0 ? axis + targetStaticShapes[0][0].size() : axis]; + auto indices_node_tensor = ov::test::utils::create_and_fill_tensor(indices_type, indices_shape, axis_dim - 1); + auto indices_node = std::make_shared(indices_node_tensor); + + auto gather_el = std::make_shared(param, indices_node, axis); + gather_el->set_friendly_name("GatherElements"); + + auto result = std::make_shared(gather_el); + function = std::make_shared(result, ov::ParameterVector{param}, "gatherEl"); +} +} // namespace test +} // namespace ov From 37271c1e7cee55b7340438c6ccbee0e326dde676 Mon Sep 17 00:00:00 2001 From: Katarzyna Mitrus Date: Mon, 25 Sep 2023 10:20:37 +0200 Subject: [PATCH 34/43] [Opset13][CPP] Initialization of Opset13 (#20005) * Opset13 init * Update test pattern ops * Update remaining files --- .../test_transformations/test_pattern_ops.py | 2 +- src/core/include/openvino/opsets/opset.hpp | 5 + src/core/include/openvino/opsets/opset13.hpp | 15 ++ .../include/openvino/opsets/opset13_tbl.hpp | 211 ++++++++++++++++++ src/core/src/opsets/opset.cpp | 14 +- src/core/tests/op.cpp | 1 + src/core/tests/opset.cpp | 4 +- .../openvino/frontend/extension/op.hpp | 2 +- .../src/op_impl_check/single_op_graph.cpp | 1 + 9 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 src/core/include/openvino/opsets/opset13.hpp create mode 100644 src/core/include/openvino/opsets/opset13_tbl.hpp diff --git a/src/bindings/python/tests/test_transformations/test_pattern_ops.py b/src/bindings/python/tests/test_transformations/test_pattern_ops.py index 0c43fe01150154..94d42ffe3f853c 100644 --- a/src/bindings/python/tests/test_transformations/test_pattern_ops.py +++ b/src/bindings/python/tests/test_transformations/test_pattern_ops.py @@ -20,7 +20,7 @@ def test_wrap_type_pattern_type(): - last_opset_number = 12 + last_opset_number = 13 for i in range(1, last_opset_number + 1): WrapType(f"opset{i}.Parameter") WrapType(f"opset{i}::Parameter") diff --git a/src/core/include/openvino/opsets/opset.hpp b/src/core/include/openvino/opsets/opset.hpp index 0e487e95a0fe09..e9d483f27eeaa2 100644 --- a/src/core/include/openvino/opsets/opset.hpp +++ b/src/core/include/openvino/opsets/opset.hpp @@ -179,6 +179,11 @@ const OPENVINO_API OpSet& get_opset11(); * @ingroup ov_opset_cpp_api */ const OPENVINO_API OpSet& get_opset12(); +/** + * @brief Returns opset13 + * @ingroup ov_opset_cpp_api + */ +const OPENVINO_API OpSet& get_opset13(); /** * @brief Returns map of available opsets * @ingroup ov_opset_cpp_api diff --git a/src/core/include/openvino/opsets/opset13.hpp b/src/core/include/openvino/opsets/opset13.hpp new file mode 100644 index 00000000000000..a97cefba5967cd --- /dev/null +++ b/src/core/include/openvino/opsets/opset13.hpp @@ -0,0 +1,15 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/ops.hpp" + +namespace ov { +namespace opset13 { +#define _OPENVINO_OP_REG(a, b) using b::a; +#include "openvino/opsets/opset13_tbl.hpp" +#undef _OPENVINO_OP_REG +} // namespace opset13 +} // namespace ov diff --git a/src/core/include/openvino/opsets/opset13_tbl.hpp b/src/core/include/openvino/opsets/opset13_tbl.hpp new file mode 100644 index 00000000000000..f8b1709648e860 --- /dev/null +++ b/src/core/include/openvino/opsets/opset13_tbl.hpp @@ -0,0 +1,211 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#ifndef _OPENVINO_OP_REG +# warning "_OPENVINO_OP_REG not defined" +# define _OPENVINO_OP_REG(x, y) +#endif + +_OPENVINO_OP_REG(Abs, ov::op::v0) +_OPENVINO_OP_REG(Acos, ov::op::v0) +_OPENVINO_OP_REG(Add, ov::op::v1) +_OPENVINO_OP_REG(Asin, ov::op::v0) +_OPENVINO_OP_REG(Atan, ov::op::v0) +_OPENVINO_OP_REG(AvgPool, ov::op::v1) +_OPENVINO_OP_REG(BatchNormInference, ov::op::v5) +_OPENVINO_OP_REG(BinaryConvolution, ov::op::v1) +_OPENVINO_OP_REG(Broadcast, ov::op::v3) +_OPENVINO_OP_REG(Bucketize, ov::op::v3) +_OPENVINO_OP_REG(CTCGreedyDecoder, ov::op::v0) +_OPENVINO_OP_REG(Ceiling, ov::op::v0) +_OPENVINO_OP_REG(Clamp, ov::op::v0) +_OPENVINO_OP_REG(Concat, ov::op::v0) +_OPENVINO_OP_REG(Constant, ov::op::v0) +_OPENVINO_OP_REG(Convert, ov::op::v0) +_OPENVINO_OP_REG(ConvertLike, ov::op::v1) +_OPENVINO_OP_REG(Convolution, ov::op::v1) +_OPENVINO_OP_REG(ConvolutionBackpropData, ov::op::v1) +_OPENVINO_OP_REG(Cos, ov::op::v0) +_OPENVINO_OP_REG(Cosh, ov::op::v0) +_OPENVINO_OP_REG(CumSum, ov::op::v0) +_OPENVINO_OP_REG(DeformablePSROIPooling, ov::op::v1) +_OPENVINO_OP_REG(DepthToSpace, ov::op::v0) +_OPENVINO_OP_REG(Divide, ov::op::v1) +_OPENVINO_OP_REG(Elu, ov::op::v0) +_OPENVINO_OP_REG(Erf, ov::op::v0) +_OPENVINO_OP_REG(Equal, ov::op::v1) +_OPENVINO_OP_REG(Exp, ov::op::v0) +_OPENVINO_OP_REG(ExtractImagePatches, ov::op::v3) +_OPENVINO_OP_REG(FakeQuantize, ov::op::v0) +_OPENVINO_OP_REG(Floor, ov::op::v0) +_OPENVINO_OP_REG(FloorMod, ov::op::v1) +_OPENVINO_OP_REG(GatherTree, ov::op::v1) +_OPENVINO_OP_REG(Greater, ov::op::v1) +_OPENVINO_OP_REG(GreaterEqual, ov::op::v1) +_OPENVINO_OP_REG(GridSample, ov::op::v9) +_OPENVINO_OP_REG(GroupConvolution, ov::op::v1) +_OPENVINO_OP_REG(GroupConvolutionBackpropData, ov::op::v1) +_OPENVINO_OP_REG(GRN, ov::op::v0) +_OPENVINO_OP_REG(HardSigmoid, ov::op::v0) +_OPENVINO_OP_REG(Less, ov::op::v1) +_OPENVINO_OP_REG(LessEqual, ov::op::v1) +_OPENVINO_OP_REG(Log, ov::op::v0) +_OPENVINO_OP_REG(LogicalAnd, ov::op::v1) +_OPENVINO_OP_REG(LogicalNot, ov::op::v1) +_OPENVINO_OP_REG(LogicalOr, ov::op::v1) +_OPENVINO_OP_REG(LogicalXor, ov::op::v1) +_OPENVINO_OP_REG(LRN, ov::op::v0) +_OPENVINO_OP_REG(LSTMCell, ov::op::v4) +_OPENVINO_OP_REG(MatMul, ov::op::v0) +_OPENVINO_OP_REG(Maximum, ov::op::v1) +_OPENVINO_OP_REG(Minimum, ov::op::v1) +_OPENVINO_OP_REG(Mod, ov::op::v1) +_OPENVINO_OP_REG(Multiply, ov::op::v1) +_OPENVINO_OP_REG(Negative, ov::op::v0) +_OPENVINO_OP_REG(NormalizeL2, ov::op::v0) +_OPENVINO_OP_REG(NotEqual, ov::op::v1) +_OPENVINO_OP_REG(OneHot, ov::op::v1) +_OPENVINO_OP_REG(PRelu, ov::op::v0) +_OPENVINO_OP_REG(PSROIPooling, ov::op::v0) +_OPENVINO_OP_REG(Parameter, ov::op::v0) +_OPENVINO_OP_REG(Power, ov::op::v1) +_OPENVINO_OP_REG(PriorBoxClustered, ov::op::v0) +_OPENVINO_OP_REG(Proposal, ov::op::v4) +_OPENVINO_OP_REG(Range, ov::op::v4) +_OPENVINO_OP_REG(Relu, ov::op::v0) +_OPENVINO_OP_REG(ReduceMax, ov::op::v1) +_OPENVINO_OP_REG(ReduceLogicalAnd, ov::op::v1) +_OPENVINO_OP_REG(ReduceLogicalOr, ov::op::v1) +_OPENVINO_OP_REG(ReduceMean, ov::op::v1) +_OPENVINO_OP_REG(ReduceMin, ov::op::v1) +_OPENVINO_OP_REG(ReduceProd, ov::op::v1) +_OPENVINO_OP_REG(ReduceSum, ov::op::v1) +_OPENVINO_OP_REG(RegionYolo, ov::op::v0) +_OPENVINO_OP_REG(ReorgYolo, ov::op::v0) +_OPENVINO_OP_REG(Reshape, ov::op::v1) +_OPENVINO_OP_REG(Result, ov::op::v0) +_OPENVINO_OP_REG(ReverseSequence, ov::op::v0) +_OPENVINO_OP_REG(ROIPooling, ov::op::v0) +_OPENVINO_OP_REG(ScatterNDUpdate, ov::op::v3) +_OPENVINO_OP_REG(Select, ov::op::v1) +_OPENVINO_OP_REG(Selu, ov::op::v0) +_OPENVINO_OP_REG(Sign, ov::op::v0) +_OPENVINO_OP_REG(Sigmoid, ov::op::v0) +_OPENVINO_OP_REG(Sin, ov::op::v0) +_OPENVINO_OP_REG(Sinh, ov::op::v0) +_OPENVINO_OP_REG(Sqrt, ov::op::v0) +_OPENVINO_OP_REG(SpaceToDepth, ov::op::v0) +_OPENVINO_OP_REG(Split, ov::op::v1) +_OPENVINO_OP_REG(SquaredDifference, ov::op::v0) +_OPENVINO_OP_REG(Squeeze, ov::op::v0) +_OPENVINO_OP_REG(StridedSlice, ov::op::v1) +_OPENVINO_OP_REG(Subtract, ov::op::v1) +_OPENVINO_OP_REG(Tan, ov::op::v0) +_OPENVINO_OP_REG(Tanh, ov::op::v0) +_OPENVINO_OP_REG(TensorIterator, ov::op::v0) +_OPENVINO_OP_REG(Tile, ov::op::v0) +_OPENVINO_OP_REG(Transpose, ov::op::v1) +_OPENVINO_OP_REG(Unsqueeze, ov::op::v0) +_OPENVINO_OP_REG(VariadicSplit, ov::op::v1) + +// New operations added in opset2 +_OPENVINO_OP_REG(BatchToSpace, ov::op::v1) +_OPENVINO_OP_REG(SpaceToBatch, ov::op::v1) + +// New operations added in opset3 +_OPENVINO_OP_REG(EmbeddingBagPackedSum, ov::op::v3) +_OPENVINO_OP_REG(EmbeddingSegmentsSum, ov::op::v3) +_OPENVINO_OP_REG(EmbeddingBagOffsetsSum, ov::op::v3) +_OPENVINO_OP_REG(GRUCell, ov::op::v3) +_OPENVINO_OP_REG(NonZero, ov::op::v3) +_OPENVINO_OP_REG(RNNCell, ov::op::v0) +_OPENVINO_OP_REG(ScatterUpdate, ov::op::v3) +_OPENVINO_OP_REG(ShuffleChannels, ov::op::v0) +_OPENVINO_OP_REG(ShapeOf, ov::op::v3) + +// New operations added in opset4 +_OPENVINO_OP_REG(Acosh, ov::op::v3) +_OPENVINO_OP_REG(Asinh, ov::op::v3) +_OPENVINO_OP_REG(Atanh, ov::op::v3) +_OPENVINO_OP_REG(CTCLoss, ov::op::v4) +_OPENVINO_OP_REG(HSwish, ov::op::v4) +_OPENVINO_OP_REG(Mish, ov::op::v4) +_OPENVINO_OP_REG(ReduceL1, ov::op::v4) +_OPENVINO_OP_REG(ReduceL2, ov::op::v4) +_OPENVINO_OP_REG(SoftPlus, ov::op::v4) +_OPENVINO_OP_REG(Swish, ov::op::v4) + +// New operations added in opset5 +_OPENVINO_OP_REG(GRUSequence, ov::op::v5) +_OPENVINO_OP_REG(HSigmoid, ov::op::v5) +_OPENVINO_OP_REG(LogSoftmax, ov::op::v5) +_OPENVINO_OP_REG(Loop, ov::op::v5) +_OPENVINO_OP_REG(LSTMSequence, ov::op::v5) +_OPENVINO_OP_REG(RNNSequence, ov::op::v5) +_OPENVINO_OP_REG(Round, ov::op::v5) + +// New operations added in opset6 +_OPENVINO_OP_REG(CTCGreedyDecoderSeqLen, ov::op::v6) +_OPENVINO_OP_REG(ExperimentalDetectronDetectionOutput, ov::op::v6) +_OPENVINO_OP_REG(ExperimentalDetectronGenerateProposalsSingleImage, ov::op::v6) +_OPENVINO_OP_REG(ExperimentalDetectronPriorGridGenerator, ov::op::v6) +_OPENVINO_OP_REG(ExperimentalDetectronROIFeatureExtractor, ov::op::v6) +_OPENVINO_OP_REG(ExperimentalDetectronTopKROIs, ov::op::v6) +_OPENVINO_OP_REG(GatherElements, ov::op::v6) +_OPENVINO_OP_REG(MVN, ov::op::v6) +_OPENVINO_OP_REG(Assign, ov::op::v6) // new version +_OPENVINO_OP_REG(ReadValue, ov::op::v6) // new version + +// New operations added in opset7 +_OPENVINO_OP_REG(DFT, ov::op::v7) +_OPENVINO_OP_REG(Einsum, ov::op::v7) +_OPENVINO_OP_REG(Gelu, ov::op::v7) +_OPENVINO_OP_REG(IDFT, ov::op::v7) +_OPENVINO_OP_REG(Roll, ov::op::v7) + +// New operations added in opset8 +_OPENVINO_OP_REG(Gather, ov::op::v8) +_OPENVINO_OP_REG(GatherND, ov::op::v8) +_OPENVINO_OP_REG(AdaptiveAvgPool, ov::op::v8) +_OPENVINO_OP_REG(AdaptiveMaxPool, ov::op::v8) +_OPENVINO_OP_REG(DeformableConvolution, ov::op::v8) +_OPENVINO_OP_REG(DetectionOutput, ov::op::v8) +_OPENVINO_OP_REG(I420toBGR, ov::op::v8) +_OPENVINO_OP_REG(I420toRGB, ov::op::v8) +_OPENVINO_OP_REG(MatrixNms, ov::op::v8) +_OPENVINO_OP_REG(MaxPool, ov::op::v8) +_OPENVINO_OP_REG(NV12toBGR, ov::op::v8) +_OPENVINO_OP_REG(NV12toRGB, ov::op::v8) +_OPENVINO_OP_REG(RandomUniform, ov::op::v8) +_OPENVINO_OP_REG(Slice, ov::op::v8) +_OPENVINO_OP_REG(Softmax, ov::op::v8) +_OPENVINO_OP_REG(If, ov::op::v8) +_OPENVINO_OP_REG(PriorBox, ov::op::v8) + +// New operations added in opset9 +_OPENVINO_OP_REG(IRDFT, ov::op::v9) +_OPENVINO_OP_REG(RDFT, ov::op::v9) +_OPENVINO_OP_REG(Eye, ov::op::v9) +_OPENVINO_OP_REG(NonMaxSuppression, ov::op::v9) +_OPENVINO_OP_REG(ROIAlign, ov::op::v9) +_OPENVINO_OP_REG(SoftSign, ov::op::v9) +_OPENVINO_OP_REG(GenerateProposals, ov::op::v9) +_OPENVINO_OP_REG(MulticlassNms, ov::op::v9) + +// New operations added in opset10 +_OPENVINO_OP_REG(IsFinite, ov::op::v10) +_OPENVINO_OP_REG(IsInf, ov::op::v10) +_OPENVINO_OP_REG(IsNaN, ov::op::v10) +_OPENVINO_OP_REG(Unique, ov::op::v10) + +// New operations added in opset11 +_OPENVINO_OP_REG(Interpolate, ov::op::v11) +_OPENVINO_OP_REG(TopK, ov::op::v11) + +// New operations added in opset12 +_OPENVINO_OP_REG(GroupNormalization, ov::op::v12) +_OPENVINO_OP_REG(Pad, ov::op::v12) +_OPENVINO_OP_REG(ScatterElementsUpdate, ov::op::v12) + +// New operations added in opset13 diff --git a/src/core/src/opsets/opset.cpp b/src/core/src/opsets/opset.cpp index 041503a973c61a..1a61c91e7a1133 100644 --- a/src/core/src/opsets/opset.cpp +++ b/src/core/src/opsets/opset.cpp @@ -83,7 +83,8 @@ const std::map>& ov::get_availabl _OPENVINO_REG_OPSET(opset9), _OPENVINO_REG_OPSET(opset10), _OPENVINO_REG_OPSET(opset11), - _OPENVINO_REG_OPSET(opset12)}; + _OPENVINO_REG_OPSET(opset12), + _OPENVINO_REG_OPSET(opset13)}; #undef _OPENVINO_REG_OPSET return opset_map; } @@ -220,6 +221,17 @@ const ov::OpSet& ov::get_opset12() { return opset; } +const ov::OpSet& ov::get_opset13() { + static OpSet opset; + static std::once_flag flag; + std::call_once(flag, [&]() { +#define _OPENVINO_OP_REG(NAME, NAMESPACE) opset.insert(); +#include "openvino/opsets/opset13_tbl.hpp" +#undef _OPENVINO_OP_REG + }); + return opset; +} + const ngraph::OpSet& ngraph::get_opset1() { static OpSet opset(ov::get_opset1()); return opset; diff --git a/src/core/tests/op.cpp b/src/core/tests/op.cpp index 20f6d919c89464..b249c0698bf1db 100644 --- a/src/core/tests/op.cpp +++ b/src/core/tests/op.cpp @@ -64,4 +64,5 @@ TEST(op, opset_multi_thread) { doTest(ov::get_opset10); doTest(ov::get_opset11); doTest(ov::get_opset12); + doTest(ov::get_opset13); } diff --git a/src/core/tests/opset.cpp b/src/core/tests/opset.cpp index cafea943c8321b..e8007d9b74b95b 100644 --- a/src/core/tests/opset.cpp +++ b/src/core/tests/opset.cpp @@ -11,6 +11,7 @@ #include "openvino/opsets/opset10.hpp" #include "openvino/opsets/opset11.hpp" #include "openvino/opsets/opset12.hpp" +#include "openvino/opsets/opset13.hpp" #include "openvino/opsets/opset2.hpp" #include "openvino/opsets/opset3.hpp" #include "openvino/opsets/opset4.hpp" @@ -69,7 +70,8 @@ INSTANTIATE_TEST_SUITE_P(opset, OpsetTestParams{ov::get_opset9, 173}, OpsetTestParams{ov::get_opset10, 177}, OpsetTestParams{ov::get_opset11, 177}, - OpsetTestParams{ov::get_opset12, 178}), + OpsetTestParams{ov::get_opset12, 178}, + OpsetTestParams{ov::get_opset13, 178}), OpsetTestNameGenerator{}); class MyOpOld : public ov::op::Op { diff --git a/src/frontends/common/include/openvino/frontend/extension/op.hpp b/src/frontends/common/include/openvino/frontend/extension/op.hpp index 916426f77056b1..0bb7b76fe54817 100644 --- a/src/frontends/common/include/openvino/frontend/extension/op.hpp +++ b/src/frontends/common/include/openvino/frontend/extension/op.hpp @@ -25,7 +25,7 @@ inline const ov::OpSet& get_opset_by_name(const std::string& opset_name) { if (opsets.find(opset_name) != opsets.end()) return opsets.at(opset_name)(); if (opset_name.empty() || opset_name == "latest") { - return ov::get_opset12(); + return ov::get_opset13(); } else { FRONT_END_GENERAL_CHECK(false, "Unsupported opset name: ", opset_name); } diff --git a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp index 7dad25bbab8efb..a5383310174bc9 100644 --- a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp +++ b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp @@ -2003,6 +2003,7 @@ OpGenerator getOpGeneratorMap() { #include "openvino/opsets/opset10_tbl.hpp" #include "openvino/opsets/opset11_tbl.hpp" #include "openvino/opsets/opset12_tbl.hpp" +#include "openvino/opsets/opset13_tbl.hpp" #undef _OPENVINO_OP_REG }; return opGeneratorMap; From 9091afc26c44a31648aa7af7377dc1d503a406f7 Mon Sep 17 00:00:00 2001 From: jmacekx <115208282+jmacekx@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:38:58 +0200 Subject: [PATCH 35/43] [DOCS] use etree to fix docs generated by doxygen (#20024) --- docs/scripts/prepare_xml.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/scripts/prepare_xml.py b/docs/scripts/prepare_xml.py index 2a14121a2e6fca..dc4e1a18f79ce9 100644 --- a/docs/scripts/prepare_xml.py +++ b/docs/scripts/prepare_xml.py @@ -4,7 +4,6 @@ import re import logging import argparse -import lxml.html from lxml import etree from pathlib import Path from xml.sax import saxutils @@ -29,7 +28,7 @@ def prepare_xml(xml_dir: Path): # escape asterisks contents = contents.replace('*', '\\*') contents = str.encode(contents) - root = lxml.html.fromstring(contents) + root = etree.fromstring(contents) # unescape * in sphinxdirectives sphinxdirectives = root.xpath('//sphinxdirective') From ec451077234df295c6f9f93cee7e08f158773df1 Mon Sep 17 00:00:00 2001 From: Yuan Hu Date: Mon, 25 Sep 2023 16:45:25 +0800 Subject: [PATCH 36/43] [CPU] Fix memory leak in binconv (#19999) --- src/plugins/intel_cpu/src/nodes/bin_conv.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/bin_conv.cpp b/src/plugins/intel_cpu/src/nodes/bin_conv.cpp index f37c9a51946c0a..66fd73c086eb9f 100644 --- a/src/plugins/intel_cpu/src/nodes/bin_conv.cpp +++ b/src/plugins/intel_cpu/src/nodes/bin_conv.cpp @@ -8,6 +8,7 @@ #include "eltwise.h" #include "fake_quantize.h" #include "conv.h" +#include #include #include #include @@ -63,10 +64,10 @@ struct jit_uni_bin_conv_kernel_f32 : public jit_uni_bin_conv_kernel, public jit_ for (int i = 0; i < end_idx; i++) { auto &post_op = p.entry_[i]; if (post_op.is_eltwise()) { - eltwise_injectors.push_back(new jit_uni_eltwise_injector_f32( + eltwise_injectors.push_back(std::make_shared>( this, post_op.eltwise, true, eltwise_reserved, mask_post_op_reserved)); } else if (post_op.is_depthwise()) { - depthwise_injectors.push_back(new jit_uni_depthwise_injector_f32( + depthwise_injectors.push_back(std::make_shared>( this, post_op, mask_post_op_reserved)); } } @@ -210,8 +211,8 @@ struct jit_uni_bin_conv_kernel_f32 : public jit_uni_bin_conv_kernel, public jit_ Xbyak::Label l_table; - nstl::vector*> eltwise_injectors; - nstl::vector*> depthwise_injectors; + nstl::vector>> eltwise_injectors; + nstl::vector>> depthwise_injectors; void cvt2ps(dnnl::memory::data_type type_in, Vmm vmm_in, const Xbyak::Operand &op, bool scalar_load) { Xmm xmm_in = Xmm(vmm_in.getIdx()); From a4e1f9dbf8234caabc285d701a0ad3138354d397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Krzemi=C5=84ski?= Date: Mon, 25 Sep 2023 10:54:40 +0200 Subject: [PATCH 37/43] [Spec][Opset13] Multinomial specification (#19866) * [Spec] Multinomial specification * [Spec] Apply recommended style fixes to Multinomial_13.md * [Spec] Add range mathematical formulation * [Spec] Update Multinomial input types * Update opset13.md * Update opset.md * Update docs/ops/generation/Multinomial_13.md Co-authored-by: Katarzyna Mitrus * Update Multinomial_13.md * Update opset13.md * Update docs/ops/generation/Multinomial_13.md Co-authored-by: Katarzyna Mitrus * Update Multinomial_13.md * Update Multinomial_13.md * Update Multinomial_13.md * Update docs/ops/generation/Multinomial_13.md Co-authored-by: Katarzyna Mitrus * Update docs/ops/generation/Multinomial_13.md Co-authored-by: Katarzyna Mitrus * Update docs/ops/generation/Multinomial_13.md Co-authored-by: Katarzyna Mitrus * Update Multinomial_13.md * [Spec] Replace 3107670 syntax with ..math * Update Multinomial_13.md * Update Multinomial_13.md * Update docs/ops/opset13.md Co-authored-by: Mateusz Mikolajczyk * [Spec] Apply changes from Ref/Core PR * Update Multinomial_13.md --------- Co-authored-by: Katarzyna Mitrus Co-authored-by: Mateusz Mikolajczyk --- .../Operations_specifications.md | 1 + docs/ops/generation/Multinomial_13.md | 200 ++++++++++++++++++ docs/ops/opset13.md | 1 + 3 files changed, 202 insertions(+) create mode 100644 docs/ops/generation/Multinomial_13.md diff --git a/docs/OV_Runtime_UG/Operations_specifications.md b/docs/OV_Runtime_UG/Operations_specifications.md index 000b3e89525098..0e5756824b69e5 100644 --- a/docs/OV_Runtime_UG/Operations_specifications.md +++ b/docs/OV_Runtime_UG/Operations_specifications.md @@ -128,6 +128,7 @@ Mod-1 MulticlassNonMaxSuppression-8 MulticlassNonMaxSuppression-9 + Multinomial-13 Multiply-1 Negative-1 NMSRotated-13 diff --git a/docs/ops/generation/Multinomial_13.md b/docs/ops/generation/Multinomial_13.md new file mode 100644 index 00000000000000..e39842ec030323 --- /dev/null +++ b/docs/ops/generation/Multinomial_13.md @@ -0,0 +1,200 @@ +# Multinomial {#openvino_docs_ops_generation_Multinomial_13} + +@sphinxdirective + +.. meta:: + :description: Learn about Multinomial-13 - a generation operation, that creates a sequence of indices of classes sampled from the multinomial distribution. + +**Versioned name**: *Multinomial-13* + +**Category**: *Generation* + +**Short description**: *Multinomial* operation generates a sequence of class indices sampled from the multinomial distribution based on the input class probabilities. + +**Detailed description**: *Multinomial* operation generates a sequence of class indices sampled from the multinomial distribution. In this context, the *probs* values represent the probabilities associated with each class within the multinomial distribution. When executing this operation, it randomly selects a class based on these probabilities. Subsequently, the index of the chosen class in the *probs* array is appended to the *output* sequence in the corresponding batch. + +**Algorithm formulation**: + +Note: The following notation + +.. math:: + + [a, b] => { x \in \mathbb{R}, a <= x <= b } + +denotes a range of real numbers between a and b. + +Given a list of probabilities x1, x2, ..., xn: + +* If *log_probs* is true: + * For each probability x, replace it with a value e^x +* Create an array - discrete CDF ([Cumulative Distribution Function](https://en.wikipedia.org/wiki/Cumulative_distribution_function)) - the cumulative sum of those probabilities, ie. create an array of values where the ith value is the sum of the probabilities x1, ..., xi +* Divide the created array by its maximum value to normalize the cumulative probabilities between the real values in the range [0, 1]. This array is, by definition of CDF, sorted in ascending order, hence the maximum value is the last value of the array. +* Randomly generate a sequence of double-precision floating point numbers in the range [0, 1]. +* For each generated number, assign the class with the lowest index for which the cumulative probability is less or equal to the generated value. +* If *with_replacement* is False (sampling without replacement): + + * Assume a class with index i has been selected - then every CDF value starting at i-th index should be lowered by the original probability of the selected class. This effectively sets the probability of sampling the given class to 0. + * Afterwards, divide the CDF by its last (maximum) value to normalize the cumulative probabilities between the real values in the range [0, 1] + +* Convert the output indices to *convert_type* +* Return output indices + +**Example computations**: +Example 1 - 1D tensor + +* Let ``probs`` = ``[0.1, 0.5, 0.4]``, ``num_samples`` = 5, ``log_probs`` = false, ``with_replacement`` = true +* CDF of ``probs`` = ``[0.1, 0.1 + 0.5, 0.1 + 0.5 + 0.4]`` = ``[0.1, 0.6, 1]`` +* Randomly generated floats = ``[0.2, 0.4, 0.6, 0.8, 1]`` +* Assigned classes = ``[1, 1, 1, 2, 2]`` + +Example 2 - 2D tensor, log probabilities + +* Let ``probs`` = ``[[-1, 1, 2], [50, 1, 21]]``, ``num_samples`` = 10, ``log_probs`` = true, ``with_replacement`` = true +* Exponentiated ``probs`` = ``[[0.36, 2.71, 7.38], [5184705528587072464087.45, 2.71, 1318815734.48]]`` +* CDF of ``probs``, per batch = ``[[0.36, 3.07, 10.45], [5184705528587072464087.45, 5184705528587072464090.16, 5184705528588391279824.64]]`` +* Normalized CDF = ``[[0.03, 0.29, 1], [1.0, 1.0, 1.0]]`` +* Randomly generated floats = ``[[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]]`` +* Assigned classes = ``[[1, 1, 2, 2, 2, 2, 2, 2, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]`` + +Example 3 - 1D tensor, without replacement + +* Let ``probs`` = ``[0.1, 0.5, 0.4]``, ``num_samples`` = 2, ``log_probs`` = false, ``with_replacement`` = false +* CDF of ``probs`` = ``[0.1, 0.6, 1]`` +* Randomly generated floats = ``[0.3, 0.2]`` +* In a loop: + + * For a value of 0.3, a class with idx ``1`` is selected + * Therefore, in CDF, for every class starting with idx ``1`` subtract the probability of class at idx ``1`` = ``probs[1]`` = 0.5 + * CDF = ``[0.1, 0.6 - 0.5, 1.0 - 0.5]`` = ``[0.1, 0.1, 0.5]`` + * Normalize CDF by dividing by last value: CDF = ``[0.2, 0.2, 1.0]`` + * Take the next randomly generated float, here 0.2, and repeat until all random samples have assigned classes. Notice that for ``sampled values`` <= 0.2, only the class wih idx ``0`` can be selected, since the search stops at the index with the first value satisfying ``sample value`` <= ``CDF probability`` + +* Assigned classes = ``[1, 2]`` + + +**Attributes**: + +* ``convert_type`` + + * **Description**: the type of the output. Determines generation algorithm and affects resulting values. Output numbers generated for different values of *convert_type* may not be equal. + * **Range of values**: "i32", "i64". + * **Type**: string + * **Required**: *Yes* + +* ``with_replacement`` + + * **Description**: controls whether to sample with replacement (classes can be sampled multiple times). + * **Range of values**: `true`, `false` + + * ``true`` - class indices can be sampled multiple times. + * ``false`` - class indices will not repeat in the output and the size of ``probs``' ``class_size`` dimension is required to be larger or equal to *num_samples* value. Might affect performance. + + * **Type**: `bool` + * **Required**: *Yes* + +* ``log_probs`` + + * **Description**: allows to control whether *inputs* should be treated as probabilities or unnormalized log probabilities. + * **Range of values**: `true`, `false` + + * ``true`` - set values in *inputs* are unnormalized log probabilities that can be any real number. + * ``false`` - probabilities in *inputs* are expected to be non-negative, finite and have a non-zero-sum. + + * **Type**: `bool` + * **Required**: *Yes* + +* ``global_seed`` + + * **Description**: global seed value. + * **Range of values**: non-negative integers + * **Type**: `unsigned int 64-bit` + * **Default value**: 0 + * **Required**: *No* + +* ``op_seed`` + + * **Description**: operational seed value. + * **Range of values**: non-negative integers + * **Type**: `unsigned int 64-bit` + * **Default value**: 0 + * **Required**: *No* + +**Inputs**: + +* **1**: ``probs`` - A 1D or 2D tensor of type `T_IN` and shape `[class_size]` or `[batch_size, class_size]` with probabilities. Allowed values depend on the *log_probs* attribute. The values are internally normalized to have values in the range of `[0, 1]` with the sum of all probabilities in the given batch equal to 1. **Required.** + +* **2**: ``num_samples`` - A scalar or 1D tensor with a single element of type `T_SAMPLES` specifying the number of samples to draw from the multinomial distribution. **Required.** + +**Outputs**: + +* **1**: ``output``- A tensor with type specified by the attribute *convert_type* and shape depending on the rank of *probs*, either ``[num_samples]`` for one-dimensional *probs* or ``[batch_size, num_samples]`` for the two-dimensional one. + +**Types** + +* **T_IN**: any supported floating-point type. +* **T_SAMPLES**: 32-bit or 64-bit integers. + + +*Example 1: 1D input tensor.* + +.. code-block:: xml + :force: + + + + + < !-- probs value: [0.1, 0.5, 0.4] --> + 3 + + < !-- num_samples value: 5 --> + + + + 5 + + + + +*Example 2: 2D input tensor.* + +.. code-block:: xml + :force: + + + + + < !-- probs value: [[-1, 1, 2], [50, 1, 21]] --> + 2 < !-- batch size of 2 --> + 3 + + < !-- num_samples value: 10 --> + + + + 2 < !--dimension depends on input batch size --> + 10 < !--dimension depends on num_samples --> + + + + +*Example 3: 1D input tensor without replacement.* + +.. code-block:: xml + :force: + + + + + < !-- probs value: [0.1, 0.5, 0.4] --> + 3 + + < !-- num_samples value: 2 --> + + + + 2 < !-- 2 unique samples of classes --> + + + + +@endsphinxdirective diff --git a/docs/ops/opset13.md b/docs/ops/opset13.md index dde2f5ce4888b6..d5d7169c8af127 100644 --- a/docs/ops/opset13.md +++ b/docs/ops/opset13.md @@ -123,6 +123,7 @@ Table of Contents * :doc:`Mod ` * :doc:`MVN ` * :doc:`MulticlassNMS ` +* :doc:`Multinomial ` * :doc:`Multiply ` * :doc:`Negative ` * :doc:`NMSRotated ` From 7d1b7b6becf7b75d8d7f675d5262b1182235d90f Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Mon, 25 Sep 2023 12:22:59 +0200 Subject: [PATCH 38/43] [core] Api 2.0/migrate operators without evaluate (#19988) * Migrate ops evaluate * Remove using ngraph and std from ops * Use OPENVINO_ASSERT instead of NGRAPH_CHECK * Move `shape_util.hpp` to `dev_api/openvino/core/` * Remove visit_attributes, same as base impl * Fix build issues * Fix build issues --- .../{ => openvino/core}/shape_util.hpp | 0 .../ngraph/op/util/recurrent_sequence.hpp | 12 +- src/core/include/openvino/op/convert_like.hpp | 1 - src/core/include/openvino/op/dft.hpp | 2 - src/core/include/openvino/op/gather.hpp | 1 - src/core/include/openvino/op/gather_tree.hpp | 1 - src/core/include/openvino/op/hard_sigmoid.hpp | 1 - src/core/include/openvino/op/idft.hpp | 2 - src/core/include/openvino/op/irdft.hpp | 1 - src/core/include/openvino/op/rdft.hpp | 1 - src/core/include/openvino/op/selu.hpp | 2 - .../openvino/op/util/recurrent_sequence.hpp | 26 +++ .../include/openvino/reference/reduce_l1.hpp | 2 +- .../include/openvino/reference/reduce_l2.hpp | 2 +- src/core/reference/src/op/function.cpp | 2 +- src/core/src/bound_evaluate.cpp | 2 +- src/core/src/node.cpp | 2 +- src/core/src/op/adaptive_avg_pool.cpp | 6 +- src/core/src/op/adaptive_max_pool.cpp | 5 +- src/core/src/op/avg_pool.cpp | 26 +-- src/core/src/op/batch_norm.cpp | 53 ++--- src/core/src/op/batch_to_space.cpp | 4 +- src/core/src/op/binary_convolution.cpp | 22 +- src/core/src/op/broadcast.cpp | 2 +- src/core/src/op/bucketize.cpp | 6 +- src/core/src/op/clamp.cpp | 2 +- src/core/src/op/concat.cpp | 8 +- src/core/src/op/constant.cpp | 18 +- src/core/src/op/convert.cpp | 6 +- src/core/src/op/convert_like.cpp | 32 +-- src/core/src/op/ctc_greedy_decoder.cpp | 28 +-- .../src/op/ctc_greedy_decoder_seq_len.cpp | 33 ++- src/core/src/op/ctc_loss.cpp | 34 ++- src/core/src/op/deformable_convolution.cpp | 1 - src/core/src/op/deformable_psroi_pooling.cpp | 50 ++--- src/core/src/op/detection_output.cpp | 34 ++- src/core/src/op/dft.cpp | 19 +- src/core/src/op/divide.cpp | 8 +- src/core/src/op/einsum.cpp | 33 ++- src/core/src/op/embedding_segments_sum.cpp | 41 ++-- src/core/src/op/embeddingbag_offsets_sum.cpp | 29 ++- src/core/src/op/embeddingbag_packedsum.cpp | 13 +- src/core/src/op/exp.cpp | 2 +- ...xperimental_detectron_detection_output.cpp | 14 +- ...erimental_detectron_generate_proposals.cpp | 13 +- .../op/experimental_detectron_roi_feature.cpp | 6 +- .../op/experimental_detectron_topkrois.cpp | 5 +- src/core/src/op/gather.cpp | 33 ++- src/core/src/op/gather_elements.cpp | 15 +- src/core/src/op/gather_nd.cpp | 15 +- src/core/src/op/gather_tree.cpp | 17 +- src/core/src/op/gelu.cpp | 2 +- src/core/src/op/generate_proposals.cpp | 15 +- src/core/src/op/greater_eq.cpp | 2 +- src/core/src/op/grn.cpp | 13 +- src/core/src/op/group_conv.cpp | 60 +++--- src/core/src/op/gru_cell.cpp | 74 ++++--- src/core/src/op/gru_sequence.cpp | 37 ++-- src/core/src/op/hard_sigmoid.cpp | 15 +- src/core/src/op/hsigmoid.cpp | 2 +- src/core/src/op/hswish.cpp | 2 +- src/core/src/op/idft.cpp | 17 +- src/core/src/op/if.cpp | 49 ++--- src/core/src/op/interpolate.cpp | 25 ++- src/core/src/op/irdft.cpp | 9 +- src/core/src/op/log_softmax.cpp | 11 +- src/core/src/op/logical_and.cpp | 2 +- src/core/src/op/logical_not.cpp | 2 +- src/core/src/op/logical_or.cpp | 2 +- src/core/src/op/loop.cpp | 15 +- src/core/src/op/lrn.cpp | 30 ++- src/core/src/op/lstm_cell.cpp | 197 +++++++++--------- src/core/src/op/lstm_sequence.cpp | 110 +++++----- src/core/src/op/mish.cpp | 2 +- src/core/src/op/mod.cpp | 1 + src/core/src/op/negative.cpp | 4 +- src/core/src/op/not_equal.cpp | 2 +- src/core/src/op/one_hot.cpp | 14 +- src/core/src/op/op.cpp | 8 +- src/core/src/op/parameter.cpp | 38 ++-- src/core/src/op/prelu.cpp | 2 +- src/core/src/op/psroi_pooling.cpp | 22 +- src/core/src/op/rdft.cpp | 9 +- src/core/src/op/reduce_logical_and.cpp | 4 +- src/core/src/op/reduce_logical_or.cpp | 4 +- src/core/src/op/reduce_max.cpp | 4 +- src/core/src/op/reduce_mean.cpp | 4 +- src/core/src/op/reduce_min.cpp | 4 +- src/core/src/op/reduce_prod.cpp | 4 +- src/core/src/op/reduce_sum.cpp | 4 +- src/core/src/op/relu.cpp | 2 +- src/core/src/op/reshape.cpp | 12 +- src/core/src/op/reverse.cpp | 2 +- src/core/src/op/reverse_sequence.cpp | 36 ++-- src/core/src/op/rnn_cell.cpp | 65 +++--- src/core/src/op/rnn_sequence.cpp | 36 ++-- src/core/src/op/roi_pooling.cpp | 8 +- src/core/src/op/scatter_nd_update.cpp | 6 +- src/core/src/op/scatter_update.cpp | 2 +- src/core/src/op/select.cpp | 4 +- src/core/src/op/selu.cpp | 15 +- src/core/src/op/shape_of.cpp | 26 +-- src/core/src/op/sigmoid.cpp | 2 +- src/core/src/op/sign.cpp | 2 +- src/core/src/op/sink.cpp | 6 +- src/core/src/op/softmax.cpp | 16 +- src/core/src/op/softplus.cpp | 2 +- src/core/src/op/softsign.cpp | 6 +- src/core/src/op/squared_difference.cpp | 8 +- src/core/src/op/squeeze.cpp | 4 +- src/core/src/op/strided_slice.cpp | 8 +- src/core/src/op/tensor_iterator.cpp | 16 +- src/core/src/op/util/recurrent_sequence.cpp | 27 ++- src/core/src/op/util/variable_value.cpp | 2 +- src/core/src/op/variadic_split.cpp | 7 +- src/core/src/op/xor.cpp | 1 + src/core/src/runtime/itensor.cpp | 2 +- src/core/src/runtime/ov_tensor.cpp | 2 +- src/core/src/shape_util.cpp | 2 +- src/core/src/tensor_conversion_util.cpp | 2 +- src/plugins/intel_cpu/src/nodes/reference.cpp | 12 +- .../custom_op_internal_dyn.cpp | 6 +- .../src/custom_op_insert_convert_i64.cpp | 6 +- .../template/backend/int_executable.cpp | 2 +- src/plugins/template/backend/ops/if.cpp | 2 +- 125 files changed, 877 insertions(+), 994 deletions(-) rename src/core/dev_api/{ => openvino/core}/shape_util.hpp (100%) create mode 100644 src/core/include/openvino/op/util/recurrent_sequence.hpp diff --git a/src/core/dev_api/shape_util.hpp b/src/core/dev_api/openvino/core/shape_util.hpp similarity index 100% rename from src/core/dev_api/shape_util.hpp rename to src/core/dev_api/openvino/core/shape_util.hpp diff --git a/src/core/include/ngraph/op/util/recurrent_sequence.hpp b/src/core/include/ngraph/op/util/recurrent_sequence.hpp index 1cf9cc95ea8627..f283947fa154b6 100644 --- a/src/core/include/ngraph/op/util/recurrent_sequence.hpp +++ b/src/core/include/ngraph/op/util/recurrent_sequence.hpp @@ -18,20 +18,12 @@ #include "ngraph/deprecated.hpp" #include "ngraph/node.hpp" +#include "openvino/op/util/recurrent_sequence.hpp" namespace ngraph { namespace op { namespace util { -/// -/// \brief Validates static rank and dimension for provided input parameters. -/// Additionally input_size dimension is checked for X and W inputs. -/// Applies to LSTM, GRU and RNN Sequences. -/// -/// -/// \param[in] input Vector with RNNSequence-like op inputs in following order: -/// X, initial_hidden_state, sequence_lengths, W, R and B. -/// -NGRAPH_API_DEPRECATED void validate_seq_input_rank_dimension(const std::vector& input); +using ov::op::util::validate_seq_input_rank_dimension; } // namespace util } // namespace op } // namespace ngraph diff --git a/src/core/include/openvino/op/convert_like.hpp b/src/core/include/openvino/op/convert_like.hpp index 2621a1ce860131..b852a6fde68519 100644 --- a/src/core/include/openvino/op/convert_like.hpp +++ b/src/core/include/openvino/op/convert_like.hpp @@ -23,7 +23,6 @@ class OPENVINO_API ConvertLike : public Op { ConvertLike(const Output& data, const Output& like); void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; diff --git a/src/core/include/openvino/op/dft.hpp b/src/core/include/openvino/op/dft.hpp index b87262fd78b919..3783123e4090ea 100644 --- a/src/core/include/openvino/op/dft.hpp +++ b/src/core/include/openvino/op/dft.hpp @@ -45,8 +45,6 @@ class OPENVINO_API DFT : public util::FFTBase { /// \param signal_size Signal sizes for 'axes' DFT(const Output& data, const Output& axes, const Output& signal_size); - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v7 diff --git a/src/core/include/openvino/op/gather.hpp b/src/core/include/openvino/op/gather.hpp index e752259271cfb4..dcc53a465bf718 100644 --- a/src/core/include/openvino/op/gather.hpp +++ b/src/core/include/openvino/op/gather.hpp @@ -21,7 +21,6 @@ class OPENVINO_API Gather : public op::util::GatherBase { /// \param axis The tensor is a dimension index to gather data from Gather(const Output& params, const Output& indices, const Output& axis); - bool visit_attributes(AttributeVisitor& visitor) override; int64_t get_axis() const override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; diff --git a/src/core/include/openvino/op/gather_tree.hpp b/src/core/include/openvino/op/gather_tree.hpp index bc2169019a8cea..b89503ba648efd 100644 --- a/src/core/include/openvino/op/gather_tree.hpp +++ b/src/core/include/openvino/op/gather_tree.hpp @@ -29,7 +29,6 @@ class OPENVINO_API GatherTree : public Op { const Output& max_seq_len, const Output& end_token); - bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; diff --git a/src/core/include/openvino/op/hard_sigmoid.hpp b/src/core/include/openvino/op/hard_sigmoid.hpp index e6760c71b7edce..fb77a2bdede711 100644 --- a/src/core/include/openvino/op/hard_sigmoid.hpp +++ b/src/core/include/openvino/op/hard_sigmoid.hpp @@ -27,7 +27,6 @@ class OPENVINO_API HardSigmoid : public Op { /// HardSigmoid(const Output& data, const Output& alpha, const Output& beta); - bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; diff --git a/src/core/include/openvino/op/idft.hpp b/src/core/include/openvino/op/idft.hpp index 1fd0948bc9c8a2..f5198e3c6fd71f 100644 --- a/src/core/include/openvino/op/idft.hpp +++ b/src/core/include/openvino/op/idft.hpp @@ -33,8 +33,6 @@ class OPENVINO_API IDFT : public util::FFTBase { /// \param signal_size Signal sizes for 'axes' IDFT(const Output& data, const Output& axes, const Output& signal_size); - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v7 diff --git a/src/core/include/openvino/op/irdft.hpp b/src/core/include/openvino/op/irdft.hpp index 02cc5d7006cf9c..3b76e2988cbe7b 100644 --- a/src/core/include/openvino/op/irdft.hpp +++ b/src/core/include/openvino/op/irdft.hpp @@ -30,7 +30,6 @@ class OPENVINO_API IRDFT : public util::FFTBase { IRDFT(const Output& data, const Output& axes, const Output& signal_size); void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; diff --git a/src/core/include/openvino/op/rdft.hpp b/src/core/include/openvino/op/rdft.hpp index 42830fceedd7a2..d37fd78a5fc7a4 100644 --- a/src/core/include/openvino/op/rdft.hpp +++ b/src/core/include/openvino/op/rdft.hpp @@ -30,7 +30,6 @@ class OPENVINO_API RDFT : public util::FFTBase { RDFT(const Output& data, const Output& axes, const Output& signal_size); void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; diff --git a/src/core/include/openvino/op/selu.hpp b/src/core/include/openvino/op/selu.hpp index d81fd8ac1f3432..df75b71466c0c4 100644 --- a/src/core/include/openvino/op/selu.hpp +++ b/src/core/include/openvino/op/selu.hpp @@ -25,8 +25,6 @@ class OPENVINO_API Selu : public Op { void validate_and_infer_types() override; - bool visit_attributes(AttributeVisitor& visitor) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; }; } // namespace v0 diff --git a/src/core/include/openvino/op/util/recurrent_sequence.hpp b/src/core/include/openvino/op/util/recurrent_sequence.hpp new file mode 100644 index 00000000000000..452c415057610d --- /dev/null +++ b/src/core/include/openvino/op/util/recurrent_sequence.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "openvino/core/partial_shape.hpp" + +namespace ov { +namespace op { +namespace util { +/// +/// \brief Validates static rank and dimension for provided input parameters. +/// Additionally input_size dimension is checked for X and W inputs. +/// Applies to LSTM, GRU and RNN Sequences. +/// +/// +/// \param[in] input Vector with RNNSequence-like op inputs in following order: +/// X, initial_hidden_state, sequence_lengths, W, R and B. +/// +OPENVINO_API void validate_seq_input_rank_dimension(const std::vector& input); +} // namespace util +} // namespace op +} // namespace ov diff --git a/src/core/reference/include/openvino/reference/reduce_l1.hpp b/src/core/reference/include/openvino/reference/reduce_l1.hpp index a6c41f20a0f16f..50228962f334cf 100644 --- a/src/core/reference/include/openvino/reference/reduce_l1.hpp +++ b/src/core/reference/include/openvino/reference/reduce_l1.hpp @@ -7,10 +7,10 @@ #include #include +#include "openvino/core/shape_util.hpp" #include "openvino/reference/abs.hpp" #include "openvino/reference/sum.hpp" #include "openvino/reference/utils/type_util.hpp" -#include "shape_util.hpp" namespace ov { namespace reference { diff --git a/src/core/reference/include/openvino/reference/reduce_l2.hpp b/src/core/reference/include/openvino/reference/reduce_l2.hpp index 55bba7b7cd4e42..a7b9375cfc9c06 100644 --- a/src/core/reference/include/openvino/reference/reduce_l2.hpp +++ b/src/core/reference/include/openvino/reference/reduce_l2.hpp @@ -8,8 +8,8 @@ #include #include +#include "openvino/core/shape_util.hpp" #include "openvino/reference/utils/coordinate_transform.hpp" -#include "shape_util.hpp" namespace ov { namespace reference { diff --git a/src/core/reference/src/op/function.cpp b/src/core/reference/src/op/function.cpp index a0bedfa1241728..ebf706e3f03c0d 100644 --- a/src/core/reference/src/op/function.cpp +++ b/src/core/reference/src/op/function.cpp @@ -10,8 +10,8 @@ #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/tensor.hpp" #include "openvino/core/deprecated.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/reference/concat.hpp" -#include "shape_util.hpp" namespace ov { namespace reference { diff --git a/src/core/src/bound_evaluate.cpp b/src/core/src/bound_evaluate.cpp index 38d09dbcdf6fe4..cf3dc5bf21e3da 100644 --- a/src/core/src/bound_evaluate.cpp +++ b/src/core/src/bound_evaluate.cpp @@ -7,9 +7,9 @@ #include "ngraph/validation_util.hpp" #include "openvino/core/dimension_tracker.hpp" #include "openvino/core/rt_info.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/op/util/symbolic_info.hpp" #include "openvino/opsets/opset10.hpp" -#include "shape_util.hpp" #include "tensor_conversion_util.hpp" #include "transformations/rt_info/decompression.hpp" #include "transformations/rt_info/is_shape_subgraph.hpp" diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index 7f20ce4b991b6c..1610d7b2fda4da 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -15,9 +15,9 @@ #include "ngraph/graph_util.hpp" #include "openvino/core/descriptor/input.hpp" #include "openvino/core/rt_info.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/pass/constant_folding.hpp" #include "openvino/pass/pattern/matcher.hpp" -#include "shape_util.hpp" #include "shape_validation.hpp" #include "shared_node_info.hpp" #include "tensor_conversion_util.hpp" diff --git a/src/core/src/op/adaptive_avg_pool.cpp b/src/core/src/op/adaptive_avg_pool.cpp index b49d2d68f21e12..bf8f1601fc9d65 100644 --- a/src/core/src/op/adaptive_avg_pool.cpp +++ b/src/core/src/op/adaptive_avg_pool.cpp @@ -7,8 +7,6 @@ #include "adaptive_avg_pool_shape_inference.hpp" #include "itt.hpp" -using namespace std; - namespace ov { op::v8::AdaptiveAvgPool::AdaptiveAvgPool(const Output& data, const Output& output_shape) @@ -25,10 +23,10 @@ void op::v8::AdaptiveAvgPool::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shape); } -shared_ptr op::v8::AdaptiveAvgPool::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v8::AdaptiveAvgPool::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v8_AdaptiveAvgPool_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1)); + return std::make_shared(new_args.at(0), new_args.at(1)); } } // namespace ov diff --git a/src/core/src/op/adaptive_max_pool.cpp b/src/core/src/op/adaptive_max_pool.cpp index ecc55b9ca838fb..db67855d54f24a 100644 --- a/src/core/src/op/adaptive_max_pool.cpp +++ b/src/core/src/op/adaptive_max_pool.cpp @@ -7,7 +7,6 @@ #include "adaptive_max_pool_shape_inference.hpp" #include "itt.hpp" -using namespace std; namespace ov { op::v8::AdaptiveMaxPool::AdaptiveMaxPool(const Output& data, @@ -39,10 +38,10 @@ void op::v8::AdaptiveMaxPool::validate_and_infer_types() { set_output_type(1, m_index_element_type, output_shapes[1]); } -shared_ptr op::v8::AdaptiveMaxPool::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v8::AdaptiveMaxPool::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v8_AdaptiveMaxPool_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_index_element_type); + return std::make_shared(new_args.at(0), new_args.at(1), m_index_element_type); } void op::v8::AdaptiveMaxPool::set_index_element_type(const element::Type& type) { diff --git a/src/core/src/op/avg_pool.cpp b/src/core/src/op/avg_pool.cpp index 007ad910bb752e..c7e5477715d831 100644 --- a/src/core/src/op/avg_pool.cpp +++ b/src/core/src/op/avg_pool.cpp @@ -2,15 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/avg_pool.hpp" +#include "openvino/op/avg_pool.hpp" #include "avg_pool_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; +#include "openvino/core/attribute_visitor.hpp" // *** AvgPool OP SET 1 *** ov::op::v1::AvgPool::AvgPool(const Output& arg, @@ -109,15 +105,15 @@ void ov::op::v1::AvgPool::set_rounding_type(op::RoundingType rounding_type) { m_rounding_type = rounding_type; } -shared_ptr ov::op::v1::AvgPool::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v1::AvgPool::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_AvgPool_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - m_strides, - m_pads_begin, - m_pads_end, - m_kernel, - m_exclude_pad, - m_rounding_type, - m_auto_pad); + return std::make_shared(new_args.at(0), + m_strides, + m_pads_begin, + m_pads_end, + m_kernel, + m_exclude_pad, + m_rounding_type, + m_auto_pad); } diff --git a/src/core/src/op/batch_norm.cpp b/src/core/src/op/batch_norm.cpp index 129e1bc54f7743..409fa6d4638a14 100644 --- a/src/core/src/op/batch_norm.cpp +++ b/src/core/src/op/batch_norm.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/batch_norm.hpp" +#include "openvino/op/batch_norm.hpp" #include #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" #include "ngraph/validation_util.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/validation_util.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v0::BatchNormInference::BatchNormInference(const Output& input, const Output& gamma, @@ -44,17 +44,17 @@ void op::v0::BatchNormInference::validate_and_infer_types() { set_output_size(1); OPENVINO_SUPPRESS_DEPRECATED_START std::tie(result_et, result_batch_shape, result_channel_shape) = - infer_batch_norm_forward(this, - get_input_element_type(INPUT_DATA), - get_input_element_type(INPUT_GAMMA), - get_input_element_type(INPUT_BETA), - get_input_element_type(INPUT_MEAN), - get_input_element_type(INPUT_VARIANCE), - get_input_partial_shape(INPUT_DATA), - get_input_partial_shape(INPUT_GAMMA), - get_input_partial_shape(INPUT_BETA), - get_input_partial_shape(INPUT_MEAN), - get_input_partial_shape(INPUT_VARIANCE)); + ngraph::infer_batch_norm_forward(this, + get_input_element_type(INPUT_DATA), + get_input_element_type(INPUT_GAMMA), + get_input_element_type(INPUT_BETA), + get_input_element_type(INPUT_MEAN), + get_input_element_type(INPUT_VARIANCE), + get_input_partial_shape(INPUT_DATA), + get_input_partial_shape(INPUT_GAMMA), + get_input_partial_shape(INPUT_BETA), + get_input_partial_shape(INPUT_MEAN), + get_input_partial_shape(INPUT_VARIANCE)); OPENVINO_SUPPRESS_DEPRECATED_END set_output_type(0, result_et, result_batch_shape); } @@ -101,17 +101,17 @@ void op::v5::BatchNormInference::validate_and_infer_types() { set_output_size(1); OPENVINO_SUPPRESS_DEPRECATED_START std::tie(result_et, result_batch_shape, result_channel_shape) = - infer_batch_norm_forward(this, - get_input_element_type(INPUT_DATA), - get_input_element_type(INPUT_GAMMA), - get_input_element_type(INPUT_BETA), - get_input_element_type(INPUT_MEAN), - get_input_element_type(INPUT_VARIANCE), - get_input_partial_shape(INPUT_DATA), - get_input_partial_shape(INPUT_GAMMA), - get_input_partial_shape(INPUT_BETA), - get_input_partial_shape(INPUT_MEAN), - get_input_partial_shape(INPUT_VARIANCE)); + ngraph::infer_batch_norm_forward(this, + get_input_element_type(INPUT_DATA), + get_input_element_type(INPUT_GAMMA), + get_input_element_type(INPUT_BETA), + get_input_element_type(INPUT_MEAN), + get_input_element_type(INPUT_VARIANCE), + get_input_partial_shape(INPUT_DATA), + get_input_partial_shape(INPUT_GAMMA), + get_input_partial_shape(INPUT_BETA), + get_input_partial_shape(INPUT_MEAN), + get_input_partial_shape(INPUT_VARIANCE)); OPENVINO_SUPPRESS_DEPRECATED_END set_output_type(0, result_et, result_batch_shape); } @@ -126,3 +126,4 @@ std::shared_ptr op::v5::BatchNormInference::clone_with_new_inputs(const Ou new_args.at(4), m_epsilon); } +} // namespace ov diff --git a/src/core/src/op/batch_to_space.cpp b/src/core/src/op/batch_to_space.cpp index c7ae3d7580a02c..e9c4acb2253e69 100644 --- a/src/core/src/op/batch_to_space.cpp +++ b/src/core/src/op/batch_to_space.cpp @@ -177,8 +177,8 @@ bool batch_to_space_evaluate(const HostTensorVector& outputs, const HostTensorVe bool ngraph::op::v1::BatchToSpace::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_BatchToSpace_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 4)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 4)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END if (outputs[0]->get_partial_shape().is_dynamic()) { diff --git a/src/core/src/op/binary_convolution.cpp b/src/core/src/op/binary_convolution.cpp index ca89c851ba9cf6..d045818aa48c01 100644 --- a/src/core/src/op/binary_convolution.cpp +++ b/src/core/src/op/binary_convolution.cpp @@ -11,8 +11,6 @@ #include "openvino/core/axis_vector.hpp" #include "openvino/core/coordinate_diff.hpp" -using namespace std; - ov::op::v1::BinaryConvolution::BinaryConvolution(const Output& data, const Output& kernel, const Strides& strides, @@ -67,18 +65,18 @@ void ov::op::v1::BinaryConvolution::validate_and_infer_types() { set_output_type(0, data_batch_et, output_shapes[0]); } -shared_ptr ov::op::v1::BinaryConvolution::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v1::BinaryConvolution::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_BinaryConvolution_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_mode, - m_pad_value, - m_auto_pad); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_strides, + m_pads_begin, + m_pads_end, + m_dilations, + m_mode, + m_pad_value, + m_auto_pad); } bool ov::op::v1::BinaryConvolution::visit_attributes(AttributeVisitor& visitor) { diff --git a/src/core/src/op/broadcast.cpp b/src/core/src/op/broadcast.cpp index 8113b728ba285e..23661efdfd5ab9 100644 --- a/src/core/src/op/broadcast.cpp +++ b/src/core/src/op/broadcast.cpp @@ -39,7 +39,7 @@ std::pair get_broadcast_axes_bidirectional(const ov::Shape& arg_s AxisSet broadcast_axes; bool axes_known = false; const auto start_axis = static_cast(result_shape.size()) - static_cast(arg_shape.size()); - NGRAPH_CHECK(start_axis >= 0); + OPENVINO_ASSERT(start_axis >= 0); for (size_t i = 0; i < result_shape.size(); i++) { if (i < static_cast(start_axis) || result_shape[i] != arg_shape[i - start_axis]) { broadcast_axes.insert(i); diff --git a/src/core/src/op/bucketize.cpp b/src/core/src/op/bucketize.cpp index d75710e926957b..b4885b58c7e354 100644 --- a/src/core/src/op/bucketize.cpp +++ b/src/core/src/op/bucketize.cpp @@ -9,8 +9,6 @@ #include "itt.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; - namespace ov { op::v3::Bucketize::Bucketize(const Output& data, const Output& buckets, @@ -58,10 +56,10 @@ void op::v3::Bucketize::validate_and_infer_types() { set_output_type(0, m_output_type, output_shapes[0]); } -shared_ptr op::v3::Bucketize::clone_with_new_inputs(const OutputVector& inputs) const { +std::shared_ptr op::v3::Bucketize::clone_with_new_inputs(const OutputVector& inputs) const { OV_OP_SCOPE(v3_Bucketize_clone_with_new_inputs); check_new_args_count(this, inputs); - return make_shared(inputs.at(0), inputs.at(1), m_output_type, m_with_right_bound); + return std::make_shared(inputs.at(0), inputs.at(1), m_output_type, m_with_right_bound); } } // namespace ov diff --git a/src/core/src/op/clamp.cpp b/src/core/src/op/clamp.cpp index b7f7f408905299..91caa3f3fdb48b 100644 --- a/src/core/src/op/clamp.cpp +++ b/src/core/src/op/clamp.cpp @@ -79,7 +79,7 @@ bool evaluate_clamp(const HostTensorPtr& arg, const HostTensorPtr& out, double m bool op::v0::Clamp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Clamp_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return clamp::evaluate_clamp(inputs[0], outputs[0], get_min(), get_max()); } diff --git a/src/core/src/op/concat.cpp b/src/core/src/op/concat.cpp index 7c0595d02566c2..05d868b1096acb 100644 --- a/src/core/src/op/concat.cpp +++ b/src/core/src/op/concat.cpp @@ -103,9 +103,9 @@ bool evaluate_concat(const HostTensorVector& args, const HostTensorPtr& out, int bool op::Concat::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Concat_evaluate); - NGRAPH_CHECK(!inputs.empty()); - NGRAPH_CHECK(validate_host_tensor_vector(inputs, inputs.size())); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(!inputs.empty()); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, inputs.size())); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); auto concat_axis = get_axis() < 0 ? get_axis() + inputs[0]->get_shape().size() : get_axis(); return evaluate_concat(inputs, outputs[0], concat_axis); } @@ -170,7 +170,7 @@ bool op::Concat::evaluate_label(TensorLabelVector& output_labels) const { if (input_label.empty()) { const auto& shape = input.get_partial_shape(); // sanity check. at this point value propagation was successful - NGRAPH_CHECK(shape.is_static()); + OPENVINO_ASSERT(shape.is_static()); const auto& num_elements = shape_size(shape.to_shape()); input_label.resize(num_elements, no_label); } diff --git a/src/core/src/op/constant.cpp b/src/core/src/op/constant.cpp index e06d44467b1f3b..44211151fa2826 100644 --- a/src/core/src/op/constant.cpp +++ b/src/core/src/op/constant.cpp @@ -227,9 +227,9 @@ ov::op::v0::Constant::Constant(const Constant& other) { } ov::op::v0::Constant::Constant(const Constant& other, const ov::Shape& new_shape) { - NGRAPH_CHECK(shape_size(other.m_shape) == shape_size(new_shape), - "ov::Shape size " + std::to_string(shape_size(new_shape)) + " is not equal to " + - std::to_string(shape_size(other.m_shape))); + OPENVINO_ASSERT(shape_size(other.m_shape) == shape_size(new_shape), + "ov::Shape size " + std::to_string(shape_size(new_shape)) + " is not equal to " + + std::to_string(shape_size(other.m_shape))); m_element_type = other.m_element_type; m_shape = new_shape; m_data = other.m_data; @@ -403,7 +403,7 @@ vector ov::op::v0::Constant::get_value_strings() const { } ov::Shape ov::op::v0::Constant::get_shape_val() const { - NGRAPH_CHECK(m_element_type.is_integral_number()); + OPENVINO_ASSERT(m_element_type.is_integral_number()); std::vector out_shape = cast_vector(); ov::Shape output_shape(shape_size(m_shape)); std::transform(out_shape.begin(), out_shape.end(), output_shape.begin(), [&](const int64_t& v) { @@ -413,7 +413,7 @@ ov::Shape ov::op::v0::Constant::get_shape_val() const { } ov::Strides ov::op::v0::Constant::get_strides_val() const { - NGRAPH_CHECK(m_element_type == element::i64); + OPENVINO_ASSERT(m_element_type == element::i64); std::vector out_strides = cast_vector(); Strides output_strides(shape_size(m_shape)); std::transform(out_strides.begin(), out_strides.end(), output_strides.begin(), [&](const int64_t& v) { @@ -423,7 +423,7 @@ ov::Strides ov::op::v0::Constant::get_strides_val() const { } ov::Coordinate ov::op::v0::Constant::get_coordinate_val() const { - NGRAPH_CHECK(m_element_type == element::i64); + OPENVINO_ASSERT(m_element_type == element::i64); std::vector out_coordinate = cast_vector(); Coordinate output_coordinate(shape_size(m_shape)); std::transform(out_coordinate.begin(), out_coordinate.end(), output_coordinate.begin(), [&](const int64_t& v) { @@ -433,7 +433,7 @@ ov::Coordinate ov::op::v0::Constant::get_coordinate_val() const { } ov::CoordinateDiff ov::op::v0::Constant::get_coordinate_diff_val() const { - NGRAPH_CHECK(m_element_type == element::i64); + OPENVINO_ASSERT(m_element_type == element::i64); std::vector out_coordinate_diff = cast_vector(); CoordinateDiff output_coordinate_diff(shape_size(m_shape)); std::transform(out_coordinate_diff.begin(), @@ -446,7 +446,7 @@ ov::CoordinateDiff ov::op::v0::Constant::get_coordinate_diff_val() const { } ov::AxisVector ov::op::v0::Constant::get_axis_vector_val() const { - NGRAPH_CHECK(m_element_type.is_integral_number()); + OPENVINO_ASSERT(m_element_type.is_integral_number()); std::vector out_axis_vector = cast_vector(); AxisVector output_axis_vector(shape_size(m_shape)); std::transform(out_axis_vector.begin(), out_axis_vector.end(), output_axis_vector.begin(), [&](const int64_t& v) { @@ -456,7 +456,7 @@ ov::AxisVector ov::op::v0::Constant::get_axis_vector_val() const { } ov::AxisSet ov::op::v0::Constant::get_axis_set_val() const { - NGRAPH_CHECK(m_element_type.is_integral_number()); + OPENVINO_ASSERT(m_element_type.is_integral_number()); std::vector out_axis_set = cast_vector(); AxisSet output_axis_set; for (auto& axis : out_axis_set) { diff --git a/src/core/src/op/convert.cpp b/src/core/src/op/convert.cpp index d6a34741fa3b5f..b36b8c6ef44449 100644 --- a/src/core/src/op/convert.cpp +++ b/src/core/src/op/convert.cpp @@ -125,7 +125,7 @@ bool evaluate_convert(const HostTensorPtr& arg, const HostTensorPtr& out) { } bool evaluate_bound(const Node* node, ov::TensorVector& output_values, bool is_upper) { - NGRAPH_CHECK(node, output_values.size() == 1); + OPENVINO_ASSERT(node, output_values.size() == 1); const auto& input = node->input_value(0); if (const auto& value = is_upper ? input.get_tensor().get_upper_value() : input.get_tensor().get_lower_value()) { if (is_vector(value.get_shape()) && (value.get_shape().front() == 0)) { @@ -175,8 +175,8 @@ bool evaluate_bound(const Node* node, ov::TensorVector& output_values, bool is_u bool op::v0::Convert::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { OV_OP_SCOPE(v0_Convert_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 1)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return convert::evaluate_convert(input_values[0], output_values[0]); } diff --git a/src/core/src/op/convert_like.cpp b/src/core/src/op/convert_like.cpp index 4ab83d29c85a98..a83ed49516c19c 100644 --- a/src/core/src/op/convert_like.cpp +++ b/src/core/src/op/convert_like.cpp @@ -2,46 +2,46 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/convert_like.hpp" +#include "openvino/op/convert_like.hpp" #include #include "itt.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/convert.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace v1 { -op::v1::ConvertLike::ConvertLike(const Output& data, const Output& like) : Op({data, like}) { +ConvertLike::ConvertLike(const Output& data, const Output& like) : Op({data, like}) { constructor_validate_and_infer_types(); } -void op::v1::ConvertLike::validate_and_infer_types() { +void ConvertLike::validate_and_infer_types() { OV_OP_SCOPE(v1_ConvertLike_validate_and_infer_types); set_output_type(0, get_input_element_type(1), get_input_partial_shape(0)); } -bool op::v1::ConvertLike::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_ConvertLike_visit_attributes); - return true; -} - -shared_ptr op::v1::ConvertLike::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ConvertLike::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_ConvertLike_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1)); + return std::make_shared(new_args.at(0), new_args.at(1)); } -bool op::v1::ConvertLike::constant_fold(OutputVector& output_values, const OutputVector& input_values) { +bool ConvertLike::constant_fold(OutputVector& output_values, const OutputVector& input_values) { OV_OP_SCOPE(v1_ConvertLike_constant_fold); if (is_const_fold_disabled()) { return false; } if (auto data_const = std::dynamic_pointer_cast(input_values[0].get_node_shared_ptr())) { - auto convert = make_shared(input_values[0], input_values[1].get_element_type()); + auto convert = std::make_shared(input_values[0], input_values[1].get_element_type()); return convert->constant_fold(output_values, OutputVector{data_const}); } return false; } + +} // namespace v1 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/ctc_greedy_decoder.cpp b/src/core/src/op/ctc_greedy_decoder.cpp index fe436fbea3e416..0e41c01aaf3b48 100644 --- a/src/core/src/op/ctc_greedy_decoder.cpp +++ b/src/core/src/op/ctc_greedy_decoder.cpp @@ -2,24 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/ctc_greedy_decoder.hpp" - -#include +#include "openvino/op/ctc_greedy_decoder.hpp" +#include "ctc_greedy_decoder_shape_inference.hpp" #include "itt.hpp" -using namespace std; -using namespace ngraph; - -op::CTCGreedyDecoder::CTCGreedyDecoder(const Output& input, - const Output& seq_len, - const bool ctc_merge_repeated) +namespace ov { +namespace op { +namespace v0 { +CTCGreedyDecoder::CTCGreedyDecoder(const Output& input, + const Output& seq_len, + const bool ctc_merge_repeated) : Op({input, seq_len}), m_ctc_merge_repeated(ctc_merge_repeated) { constructor_validate_and_infer_types(); } -void op::CTCGreedyDecoder::validate_and_infer_types() { +void CTCGreedyDecoder::validate_and_infer_types() { OV_OP_SCOPE(v0_CTCGreedyDecoder_validate_and_infer_types); const auto& logits_pshape = get_input_partial_shape(0); const auto& seq_mask_pshape = get_input_partial_shape(1); @@ -30,14 +29,17 @@ void op::CTCGreedyDecoder::validate_and_infer_types() { set_output_type(0, input_et, output_shapes[0]); } -bool op::CTCGreedyDecoder::visit_attributes(AttributeVisitor& visitor) { +bool CTCGreedyDecoder::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_CTCGreedyDecoder_visit_attributes); visitor.on_attribute("ctc_merge_repeated", m_ctc_merge_repeated); return true; } -shared_ptr op::CTCGreedyDecoder::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr CTCGreedyDecoder::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_CTCGreedyDecoder_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_ctc_merge_repeated); + return std::make_shared(new_args.at(0), new_args.at(1), m_ctc_merge_repeated); } +} // namespace v0 +} // namespace op +} // namespace ov diff --git a/src/core/src/op/ctc_greedy_decoder_seq_len.cpp b/src/core/src/op/ctc_greedy_decoder_seq_len.cpp index e852bc73a380d1..24049ed0b910aa 100644 --- a/src/core/src/op/ctc_greedy_decoder_seq_len.cpp +++ b/src/core/src/op/ctc_greedy_decoder_seq_len.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/ctc_greedy_decoder_seq_len.hpp" - -#include +#include "openvino/op/ctc_greedy_decoder_seq_len.hpp" +#include "ctc_greedy_decoder_seq_len_shape_inference.hpp" #include "itt.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v6::CTCGreedyDecoderSeqLen::CTCGreedyDecoderSeqLen(const Output& input, const Output& seq_len, @@ -65,25 +63,26 @@ bool op::v6::CTCGreedyDecoderSeqLen::visit_attributes(AttributeVisitor& visitor) return true; } -shared_ptr op::v6::CTCGreedyDecoderSeqLen::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v6::CTCGreedyDecoderSeqLen::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v6_CTCGreedyDecoderSeqLen_clone_with_new_inputs); check_new_args_count(this, new_args); size_t args_size = new_args.size(); if (args_size == 2) { - return make_shared(new_args.at(0), - new_args.at(1), - m_merge_repeated, - m_classes_index_type, - m_sequence_length_type); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_merge_repeated, + m_classes_index_type, + m_sequence_length_type); } else if (args_size == 3) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_merge_repeated, - m_classes_index_type, - m_sequence_length_type); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + m_merge_repeated, + m_classes_index_type, + m_sequence_length_type); } else { OPENVINO_THROW("Incorrect number of arguments"); } } +} // namespace ov diff --git a/src/core/src/op/ctc_loss.cpp b/src/core/src/op/ctc_loss.cpp index a6ce8b6bb8f7a2..62aeb33939993b 100644 --- a/src/core/src/op/ctc_loss.cpp +++ b/src/core/src/op/ctc_loss.cpp @@ -8,8 +8,6 @@ #include "itt.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; - namespace ov { op::v4::CTCLoss::CTCLoss(const Output& logits, const Output& logit_length, @@ -76,26 +74,26 @@ bool op::v4::CTCLoss::visit_attributes(AttributeVisitor& visitor) { return true; } -shared_ptr op::v4::CTCLoss::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v4::CTCLoss::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v4_CTCLoss_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 4) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - preprocess_collapse_repeated_, - ctc_merge_repeated_, - unique_); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + preprocess_collapse_repeated_, + ctc_merge_repeated_, + unique_); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - preprocess_collapse_repeated_, - ctc_merge_repeated_, - unique_); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + preprocess_collapse_repeated_, + ctc_merge_repeated_, + unique_); } else { OPENVINO_THROW("Incorrect number of arguments"); } diff --git a/src/core/src/op/deformable_convolution.cpp b/src/core/src/op/deformable_convolution.cpp index ba9552759716a8..25db7f5fa07559 100644 --- a/src/core/src/op/deformable_convolution.cpp +++ b/src/core/src/op/deformable_convolution.cpp @@ -7,7 +7,6 @@ #include "deformable_convolution_shape_inference.hpp" #include "itt.hpp" -using namespace std; namespace ov { op::v8::DeformableConvolution::DeformableConvolution(const Output& arg, const Output& offsets, diff --git a/src/core/src/op/deformable_psroi_pooling.cpp b/src/core/src/op/deformable_psroi_pooling.cpp index a6a5db8f5c9835..8de8b81109044e 100644 --- a/src/core/src/op/deformable_psroi_pooling.cpp +++ b/src/core/src/op/deformable_psroi_pooling.cpp @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/deformable_psroi_pooling.hpp" +#include "openvino/op/deformable_psroi_pooling.hpp" #include "deformable_psroi_pooling_shape_inference.hpp" #include "itt.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v1::DeformablePSROIPooling::DeformablePSROIPooling(const Output& input, const Output& coords, @@ -78,32 +77,32 @@ void op::v1::DeformablePSROIPooling::validate_and_infer_types() { set_output_type(0, input_et, shape_infer(this, input_shapes)[0]); } -shared_ptr op::v1::DeformablePSROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v1::DeformablePSROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_DeformablePSROIPooling_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 3) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_output_dim, - m_spatial_scale, - m_group_size, - m_mode, - m_spatial_bins_x, - m_spatial_bins_y, - m_trans_std, - m_part_size); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + m_output_dim, + m_spatial_scale, + m_group_size, + m_mode, + m_spatial_bins_x, + m_spatial_bins_y, + m_trans_std, + m_part_size); } else if (new_args.size() == 2) { - return make_shared(new_args.at(0), - new_args.at(1), - m_output_dim, - m_spatial_scale, - m_group_size, - m_mode, - m_spatial_bins_x, - m_spatial_bins_y, - m_trans_std, - m_part_size); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_output_dim, + m_spatial_scale, + m_group_size, + m_mode, + m_spatial_bins_x, + m_spatial_bins_y, + m_trans_std, + m_part_size); } else { OPENVINO_THROW("Not supported number of DeformablePSROIPooling args"); } @@ -116,3 +115,4 @@ void op::v1::DeformablePSROIPooling::set_output_dim(int64_t output_dim) { void op::v1::DeformablePSROIPooling::set_group_size(int64_t group_size) { m_group_size = group_size; } +} // namespace ov diff --git a/src/core/src/op/detection_output.cpp b/src/core/src/op/detection_output.cpp index 76b1eb624cecd8..6f13e090c06b2f 100644 --- a/src/core/src/op/detection_output.cpp +++ b/src/core/src/op/detection_output.cpp @@ -8,8 +8,6 @@ #include "itt.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; - // ------------------------------ V0 ------------------------------ ov::op::v0::DetectionOutput::DetectionOutput(const Output& box_logits, const Output& class_preds, @@ -43,7 +41,7 @@ void ov::op::v0::DetectionOutput::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes[0]); } -shared_ptr ov::op::v0::DetectionOutput::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v0::DetectionOutput::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_DetectionOutput_clone_with_new_inputs); check_new_args_count(this, new_args); @@ -52,14 +50,14 @@ shared_ptr ov::op::v0::DetectionOutput::clone_with_new_inputs(const Ou NODE_VALIDATION_CHECK(this, num_args == 3 || num_args == 5, "DetectionOutput accepts 3 or 5 inputs."); if (num_args == 3) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); } else { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_attrs); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + m_attrs); } } @@ -102,7 +100,7 @@ void ov::op::v8::DetectionOutput::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes[0]); } -shared_ptr ov::op::v8::DetectionOutput::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v8::DetectionOutput::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_DetectionOutput_clone_with_new_inputs); check_new_args_count(this, new_args); @@ -111,14 +109,14 @@ shared_ptr ov::op::v8::DetectionOutput::clone_with_new_inputs(const Ou NODE_VALIDATION_CHECK(this, num_args == 3 || num_args == 5, "DetectionOutput accepts 3 or 5 inputs."); if (num_args == 3) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); } else { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - m_attrs); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + m_attrs); } } diff --git a/src/core/src/op/dft.cpp b/src/core/src/op/dft.cpp index ae02d24dbee8a5..b70c8c742fe328 100644 --- a/src/core/src/op/dft.cpp +++ b/src/core/src/op/dft.cpp @@ -14,23 +14,14 @@ // limitations under the License. //***************************************************************************** -#include "ngraph/op/dft.hpp" +#include "openvino/op/dft.hpp" #include #include -#include #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/axis_set.hpp" -#include "ngraph/axis_vector.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/util/op_types.hpp" -#include "ngraph/runtime/host_tensor.hpp" - -using namespace std; -using namespace ngraph; +namespace ov { op::v7::DFT::DFT(const Output& data, const Output& axes) : FFTBase(data, axes) { constructor_validate_and_infer_types(); } @@ -40,11 +31,6 @@ op::v7::DFT::DFT(const Output& data, const Output& axes, const Outpu constructor_validate_and_infer_types(); } -bool op::v7::DFT::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v7_DFT_visit_attributes); - return true; -} - std::shared_ptr op::v7::DFT::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v7_DFT_clone_with_new_inputs); check_new_args_count(this, new_args); @@ -56,3 +42,4 @@ std::shared_ptr op::v7::DFT::clone_with_new_inputs(const OutputVector& new return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } +} // namespace ov diff --git a/src/core/src/op/divide.cpp b/src/core/src/op/divide.cpp index 8ab229a9a742df..c2da6a9c05d00a 100644 --- a/src/core/src/op/divide.cpp +++ b/src/core/src/op/divide.cpp @@ -15,8 +15,8 @@ #include "ngraph/op/or.hpp" #include "ngraph/op/select.hpp" #include "ngraph/runtime/host_tensor.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/reference/divide.hpp" -#include "shape_util.hpp" using namespace std; using namespace ngraph; @@ -87,14 +87,14 @@ bool evaluate_bound(const Node* node, ov::TensorVector& output_values, bool is_u // for positive arg2 divide will have limits [low/up , up/low] // for negative arg2 limits for divide will be [up/low, low/up] // for arg2 range with both positive and negative values, divide can give any result [-inf, inf] - NGRAPH_CHECK(node, output_values.size() == 1); + OPENVINO_ASSERT(node, output_values.size() == 1); const auto& input1 = node->input_value(0); const auto& input2 = node->input_value(1); // broadcast shapes to allocate tensors of correct size for operations with both inputs PartialShape input_shape = input1.get_partial_shape(); - NGRAPH_CHECK(PartialShape::broadcast_merge_into(input_shape, input2.get_partial_shape(), node->get_autob()), - "Argument shapes in divide operation are inconsistent."); + OPENVINO_ASSERT(PartialShape::broadcast_merge_into(input_shape, input2.get_partial_shape(), node->get_autob()), + "Argument shapes in divide operation are inconsistent."); auto input1_low = ov::evaluate_lower_bound(input1); if (!input1_low) diff --git a/src/core/src/op/einsum.cpp b/src/core/src/op/einsum.cpp index 2d752899038244..d8fd3ddd45cff2 100644 --- a/src/core/src/op/einsum.cpp +++ b/src/core/src/op/einsum.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/einsum.hpp" +#include "openvino/op/einsum.hpp" #include #include @@ -11,11 +11,9 @@ #include "einsum_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/validation_util.hpp" - -using namespace std; -using namespace ngraph; +#include "openvino/core/validation_util.hpp" +namespace ov { namespace { /// \brief Check that a subscript contains only alphabetic letters or @@ -108,9 +106,9 @@ void op::v7::Einsum::parse_equation(const std::string& equation, for (std::string input_subscript; std::getline(input, input_subscript, ',');) { bool local_is_ellipsis_met = false; // check that input subscript contains only alphabetic letter or ellipsis - NGRAPH_CHECK(is_subscript_correct(input_subscript, local_is_ellipsis_met), - "Input subscript of Einsum equation must consist of either only " - "alphabetic letters or alphabetic letters with one ellipsis."); + OPENVINO_ASSERT(is_subscript_correct(input_subscript, local_is_ellipsis_met), + "Input subscript of Einsum equation must consist of either only " + "alphabetic letters or alphabetic letters with one ellipsis."); // mark that ellipsis is met at least in one input subscript if (local_is_ellipsis_met) { @@ -139,14 +137,14 @@ void op::v7::Einsum::parse_equation(const std::string& equation, bool output_is_ellipsis_met = false; // check that the output subscript has the correct format - NGRAPH_CHECK(is_subscript_correct(output_subscript, output_is_ellipsis_met), - "Output subscript of Einsum equation must consist of either only " - "alphabetic letters or alphabetic letters with one ellipsis."); + OPENVINO_ASSERT(is_subscript_correct(output_subscript, output_is_ellipsis_met), + "Output subscript of Einsum equation must consist of either only " + "alphabetic letters or alphabetic letters with one ellipsis."); // if the ellipsis is met in input subscripts, one ellipsis must be in the output subscript - NGRAPH_CHECK(is_ellipsis_met == output_is_ellipsis_met, - "Output subscript of Einsum equation must contain one ellipsis if " - "ellipsis is met in any input subscript."); + OPENVINO_ASSERT(is_ellipsis_met == output_is_ellipsis_met, + "Output subscript of Einsum equation must contain one ellipsis if " + "ellipsis is met in any input subscript."); } } @@ -164,7 +162,7 @@ std::vector op::v7::Einsum::extract_labels(const std::string& subsc // make additional increment since ellipsis consists of three dots. ch_idx += 2; } else { - NGRAPH_CHECK(false, "Einsum equation has invalid label."); + OPENVINO_ASSERT(false, "Einsum equation has invalid label."); } } @@ -205,13 +203,14 @@ bool op::v7::Einsum::visit_attributes(AttributeVisitor& visitor) { return true; } -shared_ptr op::v7::Einsum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v7::Einsum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v7_Einsum_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args, m_equation); + return std::make_shared(new_args, m_equation); } void op::v7::Einsum::set_equation(std::string equation) { remove_whitespaces(equation); m_equation = std::move(equation); } +} // namespace ov diff --git a/src/core/src/op/embedding_segments_sum.cpp b/src/core/src/op/embedding_segments_sum.cpp index b7dc0df1fcadd3..c368e6f748fc27 100644 --- a/src/core/src/op/embedding_segments_sum.cpp +++ b/src/core/src/op/embedding_segments_sum.cpp @@ -2,18 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/embedding_segments_sum.hpp" +#include "openvino/op/embedding_segments_sum.hpp" #include #include "embedding_segments_sum_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/opsets/opset3.hpp" - -using namespace std; -using namespace ngraph; +namespace ov { op::v3::EmbeddingSegmentsSum::EmbeddingSegmentsSum(const Output& emb_table, const Output& indices, const Output& segment_ids, @@ -110,28 +106,29 @@ void op::v3::EmbeddingSegmentsSum::validate_and_infer_types() { set_output_type(0, result_et, result_shapes[0]); } -shared_ptr op::v3::EmbeddingSegmentsSum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v3::EmbeddingSegmentsSum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v3_EmbeddingSegmentsSum_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 4) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3)); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3)); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4)); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4)); } else if (new_args.size() == 6) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5)); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5)); } else { OPENVINO_THROW("Incorrect number of arguments"); } } +} // namespace ov diff --git a/src/core/src/op/embeddingbag_offsets_sum.cpp b/src/core/src/op/embeddingbag_offsets_sum.cpp index f510e380de82ab..fa2e222386bf99 100644 --- a/src/core/src/op/embeddingbag_offsets_sum.cpp +++ b/src/core/src/op/embeddingbag_offsets_sum.cpp @@ -2,13 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/embeddingbag_offsets_sum.hpp" +#include "openvino/op/embeddingbag_offsets_sum.hpp" #include "itt.hpp" -#include "ngraph/op/constant.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v3::EmbeddingBagOffsetsSum::EmbeddingBagOffsetsSum(const Output& emb_table, const Output& indices, @@ -28,23 +26,24 @@ op::v3::EmbeddingBagOffsetsSum::EmbeddingBagOffsetsSum(const Output& emb_t const Output& offsets) : util::EmbeddingBagOffsetsBase(emb_table, indices, offsets) {} -shared_ptr op::v3::EmbeddingBagOffsetsSum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v3::EmbeddingBagOffsetsSum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v3_EmbeddingBagOffsetsSum_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 3) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } else if (new_args.size() == 4) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3)); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3)); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4)); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4)); } else { OPENVINO_THROW("Incorrect number of arguments"); } } +} // namespace ov diff --git a/src/core/src/op/embeddingbag_packedsum.cpp b/src/core/src/op/embeddingbag_packedsum.cpp index 319f2569adabf9..59f47715c9c088 100644 --- a/src/core/src/op/embeddingbag_packedsum.cpp +++ b/src/core/src/op/embeddingbag_packedsum.cpp @@ -2,13 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/embeddingbag_packedsum.hpp" +#include "openvino/op/embeddingbag_packedsum.hpp" #include "itt.hpp" -#include "ngraph/op/constant.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v3::EmbeddingBagPackedSum::EmbeddingBagPackedSum(const Output& emb_table, const Output& indices, @@ -18,14 +16,15 @@ op::v3::EmbeddingBagPackedSum::EmbeddingBagPackedSum(const Output& emb_tab op::v3::EmbeddingBagPackedSum::EmbeddingBagPackedSum(const Output& emb_table, const Output& indices) : util::EmbeddingBagPackedBase(emb_table, indices) {} -shared_ptr op::v3::EmbeddingBagPackedSum::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v3::EmbeddingBagPackedSum::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v3_EmbeddingBagPackedSum_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 2) { - return make_shared(new_args.at(0), new_args.at(1)); + return std::make_shared(new_args.at(0), new_args.at(1)); } else if (new_args.size() == 3) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } else { OPENVINO_THROW("Incorrect number of arguments"); } } +} // namespace ov diff --git a/src/core/src/op/exp.cpp b/src/core/src/op/exp.cpp index d5076c963e4d66..8a8a5fa88d9cd2 100644 --- a/src/core/src/op/exp.cpp +++ b/src/core/src/op/exp.cpp @@ -62,7 +62,7 @@ bool evaluate_exp(const HostTensorPtr& arg0, const HostTensorPtr& out) { bool op::Exp::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Exp_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return expop::evaluate_exp(inputs[0], outputs[0]); } diff --git a/src/core/src/op/experimental_detectron_detection_output.cpp b/src/core/src/op/experimental_detectron_detection_output.cpp index 0b5d1c4005490e..27c17a3aba7fb0 100644 --- a/src/core/src/op/experimental_detectron_detection_output.cpp +++ b/src/core/src/op/experimental_detectron_detection_output.cpp @@ -11,8 +11,6 @@ #include "itt.hpp" #include "openvino/core/attribute_visitor.hpp" -using namespace std; - namespace ov { op::v6::ExperimentalDetectronDetectionOutput::ExperimentalDetectronDetectionOutput(const Output& input_rois, const Output& input_deltas, @@ -48,15 +46,15 @@ void op::v6::ExperimentalDetectronDetectionOutput::validate_and_infer_types() { set_output_type(2, shapes_and_type.second, output_shapes[2]); } -shared_ptr op::v6::ExperimentalDetectronDetectionOutput::clone_with_new_inputs( +std::shared_ptr op::v6::ExperimentalDetectronDetectionOutput::clone_with_new_inputs( const OutputVector& new_args) const { OV_OP_SCOPE(v6_ExperimentalDetectronDetectionOutput_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_attrs); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + m_attrs); } void op::v6::ExperimentalDetectronDetectionOutput::set_attrs(Attributes attrs) { diff --git a/src/core/src/op/experimental_detectron_generate_proposals.cpp b/src/core/src/op/experimental_detectron_generate_proposals.cpp index 9bf7e050c27a84..2f4067be7d62d6 100644 --- a/src/core/src/op/experimental_detectron_generate_proposals.cpp +++ b/src/core/src/op/experimental_detectron_generate_proposals.cpp @@ -9,7 +9,6 @@ #include "itt.hpp" #include "openvino/core/attribute_visitor.hpp" -using namespace std; namespace ov { namespace op { namespace v6 { @@ -25,15 +24,15 @@ ExperimentalDetectronGenerateProposalsSingleImage::ExperimentalDetectronGenerate constructor_validate_and_infer_types(); } -shared_ptr ExperimentalDetectronGenerateProposalsSingleImage::clone_with_new_inputs( +std::shared_ptr ExperimentalDetectronGenerateProposalsSingleImage::clone_with_new_inputs( const OutputVector& new_args) const { OV_OP_SCOPE(v6_ExperimentalDetectronGenerateProposalsSingleImage_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_attrs); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + m_attrs); } bool ExperimentalDetectronGenerateProposalsSingleImage::visit_attributes(AttributeVisitor& visitor) { diff --git a/src/core/src/op/experimental_detectron_roi_feature.cpp b/src/core/src/op/experimental_detectron_roi_feature.cpp index 5993475bdbf91f..7da0cc6a81c9cb 100644 --- a/src/core/src/op/experimental_detectron_roi_feature.cpp +++ b/src/core/src/op/experimental_detectron_roi_feature.cpp @@ -13,8 +13,6 @@ #include "itt.hpp" #include "openvino/core/attribute_visitor.hpp" -using namespace std; - namespace ov { op::v6::ExperimentalDetectronROIFeatureExtractor::ExperimentalDetectronROIFeatureExtractor(const OutputVector& args, const Attributes& attrs) @@ -46,11 +44,11 @@ void op::v6::ExperimentalDetectronROIFeatureExtractor::validate_and_infer_types( set_output_type(i, shapes_and_type.second, output_shapes[i]); } -shared_ptr op::v6::ExperimentalDetectronROIFeatureExtractor::clone_with_new_inputs( +std::shared_ptr op::v6::ExperimentalDetectronROIFeatureExtractor::clone_with_new_inputs( const OutputVector& new_args) const { OV_OP_SCOPE(v6_ExperimentalDetectronROIFeatureExtractor_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args, m_attrs); + return std::make_shared(new_args, m_attrs); } void op::v6::ExperimentalDetectronROIFeatureExtractor::set_attrs(Attributes attrs) { diff --git a/src/core/src/op/experimental_detectron_topkrois.cpp b/src/core/src/op/experimental_detectron_topkrois.cpp index f476929ed1967f..829a42f968d80b 100644 --- a/src/core/src/op/experimental_detectron_topkrois.cpp +++ b/src/core/src/op/experimental_detectron_topkrois.cpp @@ -9,7 +9,6 @@ #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; namespace ov { op::v6::ExperimentalDetectronTopKROIs::ExperimentalDetectronTopKROIs(const Output& input_rois, const Output& rois_probs, @@ -25,10 +24,10 @@ bool op::v6::ExperimentalDetectronTopKROIs::visit_attributes(AttributeVisitor& v return true; } -shared_ptr op::v6::ExperimentalDetectronTopKROIs::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v6::ExperimentalDetectronTopKROIs::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v6_ExperimentalDetectronTopKROIs_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_max_rois); + return std::make_shared(new_args.at(0), new_args.at(1), m_max_rois); } void op::v6::ExperimentalDetectronTopKROIs::validate_and_infer_types() { diff --git a/src/core/src/op/gather.cpp b/src/core/src/op/gather.cpp index a5e69144829704..2680d161a0ad94 100644 --- a/src/core/src/op/gather.cpp +++ b/src/core/src/op/gather.cpp @@ -2,22 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gather.hpp" - -#include +#include "openvino/op/gather.hpp" #include "itt.hpp" -#include "ngraph/shape.hpp" +#include "openvino/core/validation_util.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v1::Gather::Gather(const Output& params, const Output& indices, const Output& axes) : GatherBase(params, indices, axes) { constructor_validate_and_infer_types(); } -int64_t ngraph::op::v1::Gather::get_axis() const { +int64_t op::v1::Gather::get_axis() const { OPENVINO_SUPPRESS_DEPRECATED_START if (!get_constant_from_source(input_value(2))) { OPENVINO_SUPPRESS_DEPRECATED_END @@ -26,15 +23,10 @@ int64_t ngraph::op::v1::Gather::get_axis() const { return GatherBase::get_axis(); } -bool ngraph::op::v1::Gather::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_Gather_visit_attributes); - return true; -} - -shared_ptr op::v1::Gather::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v1::Gather::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_Gather_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } op::v7::Gather::Gather(const Output& data, @@ -65,16 +57,16 @@ int64_t op::v7::Gather::get_batch_dims() const { return m_batch_dims; } -bool ngraph::op::v7::Gather::visit_attributes(AttributeVisitor& visitor) { +bool op::v7::Gather::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v7_Gather_visit_attributes); visitor.on_attribute("batch_dims", m_batch_dims); return true; } -shared_ptr op::v7::Gather::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v7::Gather::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v7_Gather_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_batch_dims); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_batch_dims); } op::v8::Gather::Gather(const Output& data, @@ -105,14 +97,15 @@ int64_t op::v8::Gather::get_batch_dims() const { return m_batch_dims; } -bool ngraph::op::v8::Gather::visit_attributes(AttributeVisitor& visitor) { +bool op::v8::Gather::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v8_Gather_visit_attributes); visitor.on_attribute("batch_dims", m_batch_dims); return true; } -shared_ptr op::v8::Gather::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v8::Gather::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v8_Gather_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_batch_dims); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_batch_dims); } +} // namespace ov diff --git a/src/core/src/op/gather_elements.cpp b/src/core/src/op/gather_elements.cpp index f0bd0abc6c18f1..47d8ca67d5f726 100644 --- a/src/core/src/op/gather_elements.cpp +++ b/src/core/src/op/gather_elements.cpp @@ -2,16 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gather_elements.hpp" - -#include +#include "openvino/op/gather_elements.hpp" +#include "gather_elements_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/shape.hpp" - -using namespace std; -using namespace ngraph; +namespace ov { // ------------------------------ V6 ------------------------------ op::v6::GatherElements::GatherElements(const Output& data, const Output& indices, const int64_t axis) @@ -43,8 +39,9 @@ bool op::v6::GatherElements::visit_attributes(AttributeVisitor& visitor) { return true; } -shared_ptr op::v6::GatherElements::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v6::GatherElements::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v6_GatherElements_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_axis); + return std::make_shared(new_args.at(0), new_args.at(1), m_axis); } +} // namespace ov diff --git a/src/core/src/op/gather_nd.cpp b/src/core/src/op/gather_nd.cpp index 72c9e0c3ae6020..313eb84266a282 100644 --- a/src/core/src/op/gather_nd.cpp +++ b/src/core/src/op/gather_nd.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gather_nd.hpp" +#include "openvino/op/gather_nd.hpp" #include "gather_nd_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/shape.hpp" -using namespace std; -using namespace ngraph; +namespace ov { // ------------------------------ V5 ------------------------------ op::v5::GatherND::GatherND(const Output& data, const Output& indices, const size_t batch_dims) @@ -33,10 +31,10 @@ void op::v5::GatherND::validate_and_infer_types() { set_output_type(0, data_type, out_shapes[0]); } -shared_ptr op::v5::GatherND::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v5::GatherND::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v5_GatherND_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_batch_dims); + return std::make_shared(new_args.at(0), new_args.at(1), m_batch_dims); } // ------------------------------ V8 ------------------------------ @@ -60,8 +58,9 @@ void op::v8::GatherND::validate_and_infer_types() { set_output_type(0, data_type, ov::PartialShape(out_shapes[0])); } -shared_ptr op::v8::GatherND::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v8::GatherND::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v8_GatherND_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_batch_dims); + return std::make_shared(new_args.at(0), new_args.at(1), m_batch_dims); } +} // namespace ov diff --git a/src/core/src/op/gather_tree.cpp b/src/core/src/op/gather_tree.cpp index 67c41e792655c6..5b013546f9e3cd 100644 --- a/src/core/src/op/gather_tree.cpp +++ b/src/core/src/op/gather_tree.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gather_tree.hpp" +#include "openvino/op/gather_tree.hpp" #include "gather_tree_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/shape.hpp" #include "openvino/core/validation_util.hpp" -using namespace std; -using namespace ngraph; - +namespace ov { op::v1::GatherTree::GatherTree(const Output& step_ids, const Output& parent_idx, const Output& max_seq_len, @@ -20,15 +17,10 @@ op::v1::GatherTree::GatherTree(const Output& step_ids, constructor_validate_and_infer_types(); } -shared_ptr op::v1::GatherTree::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v1::GatherTree::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_GatherTree_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3)); -} - -bool ngraph::op::v1::GatherTree::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v1_GatherTree_visit_attributes); - return true; + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3)); } void op::v1::GatherTree::validate_and_infer_types() { @@ -64,3 +56,4 @@ void op::v1::GatherTree::validate_and_infer_types() { OPENVINO_SUPPRESS_DEPRECATED_END set_output_type(0, result_et, output_shape); } +} // namespace ov diff --git a/src/core/src/op/gelu.cpp b/src/core/src/op/gelu.cpp index c858cb1374ded1..752b83fe5cd5b3 100644 --- a/src/core/src/op/gelu.cpp +++ b/src/core/src/op/gelu.cpp @@ -134,7 +134,7 @@ bool evaluate_gelu(const HostTensorPtr& arg0, const HostTensorPtr& out, op::Gelu bool op::v7::Gelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v7_Gelu_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return gelu::evaluate_gelu(inputs[0], outputs[0], m_approximation_mode); } diff --git a/src/core/src/op/generate_proposals.cpp b/src/core/src/op/generate_proposals.cpp index 8dcd6c5e696010..48fd69ac2e5778 100644 --- a/src/core/src/op/generate_proposals.cpp +++ b/src/core/src/op/generate_proposals.cpp @@ -7,7 +7,6 @@ #include "generate_proposals_shape_inference.hpp" #include "itt.hpp" -using namespace std; namespace ov { op::v9::GenerateProposals::GenerateProposals(const Output& im_info, @@ -22,15 +21,15 @@ op::v9::GenerateProposals::GenerateProposals(const Output& im_info, constructor_validate_and_infer_types(); } -shared_ptr op::v9::GenerateProposals::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v9::GenerateProposals::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v9_GenerateProposals_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_attrs, - m_roi_num_type); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + m_attrs, + m_roi_num_type); } bool op::v9::GenerateProposals::visit_attributes(AttributeVisitor& visitor) { diff --git a/src/core/src/op/greater_eq.cpp b/src/core/src/op/greater_eq.cpp index 53d6e9a9e86632..64b761233dc0cc 100644 --- a/src/core/src/op/greater_eq.cpp +++ b/src/core/src/op/greater_eq.cpp @@ -70,7 +70,7 @@ shared_ptr op::v1::GreaterEqual::clone_with_new_inputs(const OutputVector& bool op::v1::GreaterEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_GreaterEqual_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); OPENVINO_SUPPRESS_DEPRECATED_END return greater_equalop::evaluate_greater_equal(inputs[0], inputs[1], outputs[0], get_autob()); } diff --git a/src/core/src/op/grn.cpp b/src/core/src/op/grn.cpp index ff95ade95da4d5..c5a5180e91dc97 100644 --- a/src/core/src/op/grn.cpp +++ b/src/core/src/op/grn.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/grn.hpp" +#include "openvino/op/grn.hpp" #include "itt.hpp" -#include "ngraph/axis_set.hpp" -#include "ngraph/shape.hpp" +#include "openvino/core/axis_set.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v0::GRN::GRN(const Output& data, float bias) : util::UnaryElementwiseArithmetic(data), m_bias(bias) { constructor_validate_and_infer_types(); @@ -37,10 +35,11 @@ void op::v0::GRN::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } -shared_ptr op::v0::GRN::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::GRN::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_GRN_clone_with_new_inputs); if (new_args.size() != 1) { OPENVINO_THROW("Incorrect number of new arguments"); } - return make_shared(new_args.at(0), m_bias); + return std::make_shared(new_args.at(0), m_bias); } +} // namespace ov diff --git a/src/core/src/op/group_conv.cpp b/src/core/src/op/group_conv.cpp index 3a7b28108307c0..148564ef401404 100644 --- a/src/core/src/op/group_conv.cpp +++ b/src/core/src/op/group_conv.cpp @@ -10,8 +10,6 @@ #include "itt.hpp" #include "openvino/op/util/precision_sensitive_attribute.hpp" -using namespace std; - //------------------------------------------------------------------------------ // v1::GroupConvolution //------------------------------------------------------------------------------ @@ -70,16 +68,16 @@ void op::v1::GroupConvolution::validate_and_infer_types() { set_num_spatial(num_spatial, input_shapes); } -shared_ptr op::v1::GroupConvolution::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v1::GroupConvolution::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_GroupConvolution_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_strides, + m_pads_begin, + m_pads_end, + m_dilations, + m_auto_pad); } //------------------------------------------------------------------------------ @@ -188,14 +186,14 @@ void op::v1::GroupConvolutionBackpropData::set_output_shape(const ov::Shape& sha } void op::v1::GroupConvolutionBackpropData::infer_conv_backprop_output_spatial_shape( - const vector& input_data_shape, - const vector& filters_shape, + const std::vector& input_data_shape, + const std::vector& filters_shape, const Strides& strides, const Strides& dilations, const CoordinateDiff& pads_begin, const CoordinateDiff& pads_end, const CoordinateDiff& output_padding, - vector& output_spatial_shape) { + std::vector& output_spatial_shape) { size_t num_spatial_dims = input_data_shape.size(); OPENVINO_ASSERT(filters_shape.size() == num_spatial_dims && strides.size() == num_spatial_dims && dilations.size() == num_spatial_dims && pads_begin.size() == num_spatial_dims && @@ -261,28 +259,28 @@ void op::v1::GroupConvolutionBackpropData::validate_and_infer_types() { set_input_is_relevant_to_shape(1); } -shared_ptr op::v1::GroupConvolutionBackpropData::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v1::GroupConvolutionBackpropData::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v1_GroupConvolutionBackpropData_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 3) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad, - m_output_padding); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + m_strides, + m_pads_begin, + m_pads_end, + m_dilations, + m_auto_pad, + m_output_padding); } else { - return make_shared(new_args.at(0), - new_args.at(1), - m_strides, - m_pads_begin, - m_pads_end, - m_dilations, - m_auto_pad, - m_output_padding); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_strides, + m_pads_begin, + m_pads_end, + m_dilations, + m_auto_pad, + m_output_padding); } } } // namespace ov diff --git a/src/core/src/op/gru_cell.cpp b/src/core/src/op/gru_cell.cpp index 10412d321d289e..4f040be807f558 100644 --- a/src/core/src/op/gru_cell.cpp +++ b/src/core/src/op/gru_cell.cpp @@ -2,18 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gru_cell.hpp" +#include "openvino/op/gru_cell.hpp" #include #include "gru_cell_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/shape.hpp" -#include "ngraph/type/element_type.hpp" +#include "openvino/core/type/element_type.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v3::GRUCell::GRUCell() : m_linear_before_reset(false) { m_activations = {"sigmoid", "tanh"}; @@ -31,9 +28,9 @@ op::v3::GRUCell::GRUCell(const Output& X, W, R, hidden_size, - vector{"sigmoid", "tanh"}, - vector{}, - vector{}, + std::vector{"sigmoid", "tanh"}, + std::vector{}, + std::vector{}, 0.f, false) {} @@ -42,9 +39,9 @@ op::v3::GRUCell::GRUCell(const Output& X, const Output& W, const Output& R, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip, bool linear_before_reset) : RNNCellBase({X, initial_hidden_state, W, R}, hidden_size, clip, activations, activations_alpha, activations_beta), @@ -61,9 +58,9 @@ op::v3::GRUCell::GRUCell(const Output& X, const Output& R, const Output& B, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip, bool linear_before_reset) : RNNCellBase({X, initial_hidden_state, W, R, B}, @@ -109,37 +106,38 @@ void op::v3::GRUCell::add_default_bias_input() { Output B = op::v0::Constant::create(get_input_element_type(0), ov::Shape{(s_gates_count + m_linear_before_reset) * get_hidden_size()}, - vector((s_gates_count + m_linear_before_reset) * get_hidden_size(), 0.f)); + std::vector((s_gates_count + m_linear_before_reset) * get_hidden_size(), 0.f)); set_argument(4, B); } -shared_ptr op::v3::GRUCell::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v3::GRUCell::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v3_GRUCell_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 4) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip(), - m_linear_before_reset); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip(), + m_linear_before_reset); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip(), - m_linear_before_reset); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip(), + m_linear_before_reset); } else { OPENVINO_THROW("Incorrect number of new arguments"); } } +} // namespace ov diff --git a/src/core/src/op/gru_sequence.cpp b/src/core/src/op/gru_sequence.cpp index 7f2e3541f34274..825520b1431fc4 100644 --- a/src/core/src/op/gru_sequence.cpp +++ b/src/core/src/op/gru_sequence.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/gru_sequence.hpp" +#include "openvino/op/gru_sequence.hpp" #include #include @@ -10,11 +10,9 @@ #include "gru_sequence_shape_inference.hpp" #include "itt.hpp" -#include "ngraph/op/util/recurrent_sequence.hpp" -#include "ngraph/opsets/opset4.hpp" +#include "openvino/op/util/recurrent_sequence.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v5::GRUSequence::GRUSequence() : m_direction(op::RecurrentSequenceDirection::FORWARD), @@ -75,20 +73,21 @@ bool op::v5::GRUSequence::visit_attributes(AttributeVisitor& visitor) { return op::util::RNNCellBase::visit_attributes(visitor); } -shared_ptr op::v5::GRUSequence::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v5::GRUSequence::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v5_GRUSequence_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - m_hidden_size, - m_direction, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip, - m_linear_before_reset); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + m_hidden_size, + m_direction, + m_activations, + m_activations_alpha, + m_activations_beta, + m_clip, + m_linear_before_reset); } +} // namespace ov diff --git a/src/core/src/op/hard_sigmoid.cpp b/src/core/src/op/hard_sigmoid.cpp index f4aa6c37de6a50..02c85eec1762bc 100644 --- a/src/core/src/op/hard_sigmoid.cpp +++ b/src/core/src/op/hard_sigmoid.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/hard_sigmoid.hpp" +#include "openvino/op/hard_sigmoid.hpp" #include #include "itt.hpp" -#include "ngraph/shape.hpp" - -using namespace std; -using namespace ngraph; +namespace ov { op::v0::HardSigmoid::HardSigmoid() : Op() {} op::v0::HardSigmoid::HardSigmoid(const Output& data, const Output& alpha, const Output& beta) @@ -19,11 +16,6 @@ op::v0::HardSigmoid::HardSigmoid(const Output& data, const Output& a constructor_validate_and_infer_types(); } -bool ngraph::op::v0::HardSigmoid::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v0_HardSigmoid_visit_attributes); - return true; -} - void op::v0::HardSigmoid::validate_and_infer_types() { OV_OP_SCOPE(v0_HardSigmoid_validate_and_infer_types); const auto& alpha_pshape = get_input_partial_shape(1); @@ -56,9 +48,10 @@ void op::v0::HardSigmoid::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), get_input_partial_shape(0)); } -shared_ptr op::v0::HardSigmoid::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::HardSigmoid::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_HardSigmoid_clone_with_new_inputs); check_new_args_count(this, new_args); return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } +} // namespace ov diff --git a/src/core/src/op/hsigmoid.cpp b/src/core/src/op/hsigmoid.cpp index af129217739fe5..94316792b20732 100644 --- a/src/core/src/op/hsigmoid.cpp +++ b/src/core/src/op/hsigmoid.cpp @@ -59,7 +59,7 @@ bool evaluate_hsigmoid(const HostTensorPtr& arg, const HostTensorPtr& out) { bool op::v5::HSigmoid::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v5_HSigmoid_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return evaluate_hsigmoid(inputs[0], outputs[0]); } diff --git a/src/core/src/op/hswish.cpp b/src/core/src/op/hswish.cpp index bd2791541c0df5..c5ab6c4a5562a5 100644 --- a/src/core/src/op/hswish.cpp +++ b/src/core/src/op/hswish.cpp @@ -60,7 +60,7 @@ bool evaluate_hswish(const HostTensorPtr& arg, const HostTensorPtr& out) { bool op::v4::HSwish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v4_HSwish_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return hswish::evaluate_hswish(inputs[0], outputs[0]); } diff --git a/src/core/src/op/idft.cpp b/src/core/src/op/idft.cpp index 0177d506e5fae7..a8bb171a5adb9e 100644 --- a/src/core/src/op/idft.cpp +++ b/src/core/src/op/idft.cpp @@ -2,21 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/idft.hpp" +#include "openvino/op/idft.hpp" #include #include -#include #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/axis_set.hpp" -#include "ngraph/axis_vector.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/util/op_types.hpp" -#include "ngraph/runtime/host_tensor.hpp" -using namespace ngraph; +namespace ov { op::v7::IDFT::IDFT(const Output& data, const Output& axes) : FFTBase(data, axes) { constructor_validate_and_infer_types(); @@ -27,11 +20,6 @@ op::v7::IDFT::IDFT(const Output& data, const Output& axes, const Out constructor_validate_and_infer_types(); } -bool op::v7::IDFT::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v7_IDFT_visit_attributes); - return true; -} - std::shared_ptr op::v7::IDFT::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v7_IDFT_clone_with_new_inputs); check_new_args_count(this, new_args); @@ -43,3 +31,4 @@ std::shared_ptr op::v7::IDFT::clone_with_new_inputs(const OutputVector& ne return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } +} // namespace ov diff --git a/src/core/src/op/if.cpp b/src/core/src/op/if.cpp index a8321d2e7ec45b..3bbb7613b0b39e 100644 --- a/src/core/src/op/if.cpp +++ b/src/core/src/op/if.cpp @@ -2,21 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/if.hpp" +#include "openvino/op/if.hpp" #include #include -#include #include "itt.hpp" -#include "ngraph/factory.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/op/util/multi_subgraph_base.hpp" -#include "ngraph/specialize_function.hpp" +#include "openvino/core/graph_util.hpp" +#include "openvino/core/validation_util.hpp" +#include "openvino/op/util/multi_subgraph_base.hpp" #include "openvino/reference/if.hpp" -using namespace std; - ov::op::v8::If::If() : MultiSubGraphOp(2) {} ov::op::v8::If::If(const Output& execution_condition) : If() { @@ -180,8 +176,13 @@ std::shared_ptr ov::op::v8::If::clone_with_new_inputs(const OutputVect OV_OP_SCOPE(v8_If_clone_with_new_inputs); check_new_args_count(this, new_args); - auto op = make_shared(); - NGRAPH_CHECK(op.get(), op != nullptr, "Cannot clone ", description(), " operation with name ", get_friendly_name()); + auto op = std::make_shared(); + OPENVINO_ASSERT(op.get(), + op != nullptr, + "Cannot clone ", + description(), + " operation with name ", + get_friendly_name()); op->set_arguments(new_args); op->set_output_size(m_output_descriptions[0].size()); @@ -204,30 +205,30 @@ std::shared_ptr ov::op::v8::If::clone_with_new_inputs(const OutputVect void ov::op::v8::If::set_input(const Output& value, const std::shared_ptr& then_parameter, const std::shared_ptr& else_parameter) { - NGRAPH_CHECK(then_parameter != nullptr || else_parameter != nullptr, - "Missing parameters! Both parameters are nullptr!"); + OPENVINO_ASSERT(then_parameter != nullptr || else_parameter != nullptr, + "Missing parameters! Both parameters are nullptr!"); auto then_param_index = m_bodies[THEN_BODY_INDEX]->get_parameter_index(then_parameter); auto else_param_index = m_bodies[ELSE_BODY_INDEX]->get_parameter_index(else_parameter); - NGRAPH_CHECK(then_parameter == nullptr || then_param_index != -1, - "Missing parameter ", - then_parameter->get_friendly_name(), - " for \'then_body\'!"); - NGRAPH_CHECK(else_parameter == nullptr || else_param_index != -1, - "Missing parameter ", - else_parameter->get_friendly_name(), - " for \'else_body\'!"); + OPENVINO_ASSERT(then_parameter == nullptr || then_param_index != -1, + "Missing parameter ", + then_parameter->get_friendly_name(), + " for \'then_body\'!"); + OPENVINO_ASSERT(else_parameter == nullptr || else_param_index != -1, + "Missing parameter ", + else_parameter->get_friendly_name(), + " for \'else_body\'!"); set_invariant_inputs(value, {then_parameter, else_parameter}); } ov::Output ov::op::v8::If::set_output(const std::shared_ptr& then_result, const std::shared_ptr& else_result) { - NGRAPH_CHECK(then_result != nullptr, "Incorrect result in \"then_body\"! Result cant be \'nullptr\'"); - NGRAPH_CHECK(else_result != nullptr, "Incorrect result in \"else_body\"! Result cant be \'nullptr\'"); + OPENVINO_ASSERT(then_result != nullptr, "Incorrect result in \"then_body\"! Result cant be \'nullptr\'"); + OPENVINO_ASSERT(else_result != nullptr, "Incorrect result in \"else_body\"! Result cant be \'nullptr\'"); auto then_result_id = m_bodies[THEN_BODY_INDEX]->get_result_index(then_result); auto else_result_id = m_bodies[ELSE_BODY_INDEX]->get_result_index(else_result); - NGRAPH_CHECK(then_result_id != -1, "Missing result ", then_result->get_friendly_name(), "in \'then_body\'!"); - NGRAPH_CHECK(else_result_id != -1, "Missing result ", else_result->get_friendly_name(), "in \'then_body\'!"); + OPENVINO_ASSERT(then_result_id != -1, "Missing result ", then_result->get_friendly_name(), "in \'then_body\'!"); + OPENVINO_ASSERT(else_result_id != -1, "Missing result ", else_result->get_friendly_name(), "in \'then_body\'!"); return set_body_outputs({then_result, else_result}); } diff --git a/src/core/src/op/interpolate.cpp b/src/core/src/op/interpolate.cpp index dff8920c91682c..d541cc9ed373bf 100644 --- a/src/core/src/op/interpolate.cpp +++ b/src/core/src/op/interpolate.cpp @@ -14,7 +14,6 @@ #include "openvino/op/interpolate.hpp" #include "openvino/op/util/precision_sensitive_attribute.hpp" -using namespace std; namespace ov { ov::op::v0::Interpolate::Interpolate(const Output& image, const Output& output_shape, @@ -51,10 +50,10 @@ void ov::op::v0::Interpolate::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes[0]); } -shared_ptr op::v0::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Interpolate_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), m_attrs); } std::ostream& operator<<(std::ostream& s, const op::v0::Interpolate::InterpolateMode& type) { @@ -134,17 +133,17 @@ void ov::op::v4::Interpolate::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), output_shapes[0]); } -shared_ptr ov::op::v4::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v4::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v4_Interpolate_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() <= 3) { - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); } - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - m_attrs); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + m_attrs); } namespace { @@ -320,13 +319,13 @@ op::v11::Interpolate::Interpolate(const Output& image, constructor_validate_and_infer_types(); } -shared_ptr op::v11::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v11::Interpolate::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v11_Interpolate_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 2) { - return make_shared(new_args.at(0), new_args.at(1), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), m_attrs); } - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2), m_attrs); } void op::v11::Interpolate::validate_and_infer_types() { diff --git a/src/core/src/op/irdft.cpp b/src/core/src/op/irdft.cpp index 2c75478832ff03..2f282e9ec5ca6e 100644 --- a/src/core/src/op/irdft.cpp +++ b/src/core/src/op/irdft.cpp @@ -2,15 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/irdft.hpp" +#include "openvino/op/irdft.hpp" #include #include "irdft_shape_inference.hpp" #include "itt.hpp" -using namespace std; - ov::op::v9::IRDFT::IRDFT(const Output& data, const Output& axes) : FFTBase(data, axes) { constructor_validate_and_infer_types(); } @@ -20,11 +18,6 @@ ov::op::v9::IRDFT::IRDFT(const Output& data, const Output& axes, con constructor_validate_and_infer_types(); } -bool ov::op::v9::IRDFT::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v9_IRDFT_visit_attributes); - return true; -} - std::shared_ptr ov::op::v9::IRDFT::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v9_IRDFT_clone_with_new_inputs); check_new_args_count(this, new_args); diff --git a/src/core/src/op/log_softmax.cpp b/src/core/src/op/log_softmax.cpp index 5c23b3006f9ec9..a16ac224f07b82 100644 --- a/src/core/src/op/log_softmax.cpp +++ b/src/core/src/op/log_softmax.cpp @@ -2,13 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/log_softmax.hpp" +#include "openvino/op/log_softmax.hpp" #include "itt.hpp" -#include "ngraph/util.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v5::LogSoftmax::LogSoftmax(const Output& arg, const int64_t axis) : Op({arg}), m_axis(axis) { constructor_validate_and_infer_types(); @@ -35,8 +33,9 @@ void op::v5::LogSoftmax::validate_and_infer_types() { set_output_type(0, get_input_element_type(0), input_shape); } -shared_ptr op::v5::LogSoftmax::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v5::LogSoftmax::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v5_LogSoftmax_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), m_axis); + return std::make_shared(new_args.at(0), m_axis); } +} // namespace ov diff --git a/src/core/src/op/logical_and.cpp b/src/core/src/op/logical_and.cpp index 6b1c87eb4b541a..ce935e4a188265 100644 --- a/src/core/src/op/logical_and.cpp +++ b/src/core/src/op/logical_and.cpp @@ -67,7 +67,7 @@ bool evaluate_logand(const HostTensorPtr& arg0, bool op::v1::LogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalAnd_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); OPENVINO_SUPPRESS_DEPRECATED_END return logand::evaluate_logand(inputs[0], inputs[1], outputs[0], get_autob()); } diff --git a/src/core/src/op/logical_not.cpp b/src/core/src/op/logical_not.cpp index da08f6260a332f..6870c07921fc0e 100644 --- a/src/core/src/op/logical_not.cpp +++ b/src/core/src/op/logical_not.cpp @@ -65,7 +65,7 @@ bool evaluate_not(const HostTensorPtr& arg0, const HostTensorPtr& out, const siz bool op::v1::LogicalNot::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalNot_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return notop::evaluate_not(inputs[0], outputs[0], inputs[0]->get_element_count()); } diff --git a/src/core/src/op/logical_or.cpp b/src/core/src/op/logical_or.cpp index fd4e35c0c5081b..c5cbc20c83b13d 100644 --- a/src/core/src/op/logical_or.cpp +++ b/src/core/src/op/logical_or.cpp @@ -61,7 +61,7 @@ bool evaluate_logor(const HostTensorPtr& arg0, bool op::v1::LogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_LogicalOr_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); OPENVINO_SUPPRESS_DEPRECATED_END return logor::evaluate_logor(inputs[0], inputs[1], outputs[0], get_autob()); } diff --git a/src/core/src/op/loop.cpp b/src/core/src/op/loop.cpp index ef623af65814b6..8bf7710861319f 100644 --- a/src/core/src/op/loop.cpp +++ b/src/core/src/op/loop.cpp @@ -330,7 +330,12 @@ std::shared_ptr op::v5::Loop::clone_with_new_inputs(const OutputVector& ne OV_OP_SCOPE(v5_Loop_clone_with_new_inputs); check_new_args_count(this, new_args); auto op = make_shared(); - NGRAPH_CHECK(op.get(), op != nullptr, "Cannot clone ", description(), " operation with name ", get_friendly_name()); + OPENVINO_ASSERT(op.get(), + op != nullptr, + "Cannot clone ", + description(), + " operation with name ", + get_friendly_name()); clone_to(*op, new_args); return op; } @@ -341,10 +346,10 @@ Output op::v5::Loop::get_concatenated_slices(const Output& value, int64_t part_size, int64_t end, int64_t axis) { - NGRAPH_CHECK(start == 0 && stride == 1 && part_size == 1 && end == -1, - "Invalid start, stride, part_size, or end attribute values in Loop op. " - "Supported values for start {0}, for stride and part_size {1}, for end " - "{-1}"); + OPENVINO_ASSERT(start == 0 && stride == 1 && part_size == 1 && end == -1, + "Invalid start, stride, part_size, or end attribute values in Loop op. " + "Supported values for start {0}, for stride and part_size {1}, for end " + "{-1}"); return SubGraphOp::get_concatenated_slices(value, start, stride, part_size, end, axis); } diff --git a/src/core/src/op/lrn.cpp b/src/core/src/op/lrn.cpp index 05b7ea406dae5c..f80cb91103ce7d 100644 --- a/src/core/src/op/lrn.cpp +++ b/src/core/src/op/lrn.cpp @@ -2,22 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/lrn.hpp" - -#include +#include "openvino/op/lrn.hpp" #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/op/multiply.hpp" - -using namespace std; -using namespace ngraph; +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/validation_util.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/multiply.hpp" -op::LRN::LRN(const Output& arg, double alpha, double beta, double bias, size_t size) +namespace ov { +op::v0::LRN::LRN(const Output& arg, double alpha, double beta, double bias, size_t size) : LRN(arg, op::v0::Constant::create(element::i64, ov::Shape{1}, {1}), alpha, beta, bias, size) {} -op::LRN::LRN(const Output& arg, const Output& axes, double alpha, double beta, double bias, size_t size) +op::v0::LRN::LRN(const Output& arg, const Output& axes, double alpha, double beta, double bias, size_t size) : Op({arg, axes}), m_alpha(alpha), m_beta(beta), @@ -26,7 +23,7 @@ op::LRN::LRN(const Output& arg, const Output& axes, double alpha, do constructor_validate_and_infer_types(); } -AxisSet op::LRN::get_reduction_axes() const { +AxisSet op::v0::LRN::get_reduction_axes() const { AxisSet axes{1}; // channel axis as default auto axes_input_node = input_value(1).get_node_shared_ptr(); OPENVINO_SUPPRESS_DEPRECATED_START @@ -37,7 +34,7 @@ AxisSet op::LRN::get_reduction_axes() const { return axes; } -void op::LRN::validate_and_infer_types() { +void op::v0::LRN::validate_and_infer_types() { OV_OP_SCOPE(v0_LRN_validate_and_infer_types); element::Type arg_type = get_input_element_type(0); ov::PartialShape arg_shape = get_input_partial_shape(0); @@ -89,7 +86,7 @@ void op::LRN::validate_and_infer_types() { ")."); } -bool ngraph::op::v0::LRN::visit_attributes(AttributeVisitor& visitor) { +bool op::v0::LRN::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_LRN_visit_attributes); visitor.on_attribute("alpha", m_alpha); visitor.on_attribute("beta", m_beta); @@ -98,8 +95,9 @@ bool ngraph::op::v0::LRN::visit_attributes(AttributeVisitor& visitor) { return true; } -shared_ptr op::LRN::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::LRN::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_LRN_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_alpha, m_beta, m_bias, m_size); + return std::make_shared(new_args.at(0), new_args.at(1), m_alpha, m_beta, m_bias, m_size); } +} // namespace ov diff --git a/src/core/src/op/lstm_cell.cpp b/src/core/src/op/lstm_cell.cpp index a2cdf536037c1e..49b6a93a0c71f1 100644 --- a/src/core/src/op/lstm_cell.cpp +++ b/src/core/src/op/lstm_cell.cpp @@ -2,21 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/lstm_cell.hpp" +#include "openvino/op/lstm_cell.hpp" #include #include #include "itt.hpp" #include "lstm_cell_shape_inference.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/op/concat.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/shape.hpp" -#include "ngraph/type/element_type.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/type/element_type.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v0::LSTMCell::LSTMCell() : m_input_forget(false), m_weights_format(LSTMWeightsFormat::IFCO) { m_activations = {"sigmoid", "tanh", "tanh"}; @@ -32,9 +30,9 @@ op::v0::LSTMCell::LSTMCell(const Output& X, const Output& R, size_t hidden_size, op::LSTMWeightsFormat weights_format, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip, bool input_forget) : RNNCellBase({X, initial_hidden_state, initial_cell_state, W, R}, @@ -61,9 +59,9 @@ op::v0::LSTMCell::LSTMCell(const Output& X, const Output& B, size_t hidden_size, op::LSTMWeightsFormat weights_format, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip, bool input_forget) : RNNCellBase({X, initial_hidden_state, initial_cell_state, W, R, B}, @@ -90,9 +88,9 @@ op::v0::LSTMCell::LSTMCell(const Output& X, const Output& P, size_t hidden_size, op::LSTMWeightsFormat weights_format, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip, bool input_forget) : RNNCellBase({X, initial_hidden_state, initial_cell_state, W, R, B, P}, @@ -109,7 +107,7 @@ op::v0::LSTMCell::LSTMCell(const Output& X, constructor_validate_and_infer_types(); } -bool ngraph::op::v0::LSTMCell::visit_attributes(AttributeVisitor& visitor) { +bool op::v0::LSTMCell::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_LSTMCell_visit_attributes); visitor.on_attribute("hidden_size", m_hidden_size); visitor.on_attribute("activations", m_activations); @@ -176,74 +174,73 @@ void op::v0::LSTMCell::validate_and_infer_types() { Output op::v0::LSTMCell::get_default_bias_input() const { return Output{op::v0::Constant::create(get_input_element_type(0), Shape{lstm_cell::gates_count * get_hidden_size()}, - vector{0.f})}; + std::vector{0.f})}; } Output op::v0::LSTMCell::get_default_peepholes_input() const { return Output{op::v0::Constant::create(get_input_element_type(0), Shape{lstm_cell::peepholes_count * get_hidden_size()}, - vector{0.f})}; + std::vector{0.f})}; } -shared_ptr op::v0::LSTMCell::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::LSTMCell::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_LSTMCell_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - get_hidden_size(), - get_weights_format(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip(), - m_input_forget); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + get_hidden_size(), + get_weights_format(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip(), + m_input_forget); } else if (new_args.size() == 6) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - get_hidden_size(), - get_weights_format(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip(), - m_input_forget); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + get_hidden_size(), + get_weights_format(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip(), + m_input_forget); } else if (new_args.size() == 7) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - new_args.at(6), - get_hidden_size(), - get_weights_format(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip(), - m_input_forget); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + new_args.at(6), + get_hidden_size(), + get_weights_format(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip(), + m_input_forget); } else { OPENVINO_THROW("Incorrect number of new arguments"); } } -namespace ov { template <> -NGRAPH_API EnumNames& EnumNames::get() { - static auto enum_names = EnumNames("op::LSTMWeightsFormat", - {{"fico", ngraph::op::LSTMWeightsFormat::FICO}, - {"icof", ngraph::op::LSTMWeightsFormat::ICOF}, - {"ifco", ngraph::op::LSTMWeightsFormat::IFCO}, - {"ifoc", ngraph::op::LSTMWeightsFormat::IFOC}, - {"iofc", ngraph::op::LSTMWeightsFormat::IOFC}}); +OPENVINO_API EnumNames& EnumNames::get() { + static auto enum_names = EnumNames("op::LSTMWeightsFormat", + {{"fico", op::LSTMWeightsFormat::FICO}, + {"icof", op::LSTMWeightsFormat::ICOF}, + {"ifco", op::LSTMWeightsFormat::IFCO}, + {"ifoc", op::LSTMWeightsFormat::IFOC}, + {"iofc", op::LSTMWeightsFormat::IOFC}}); return enum_names; } @@ -263,9 +260,8 @@ ov::op::util::LSTMWeightsFormat op::convert_lstm_weights_enums(op::LSTMWeightsFo OPENVINO_ASSERT(false, "Incorrect LSTM weights format"); } } -} // namespace ov -std::ostream& ov::operator<<(std::ostream& s, const op::LSTMWeightsFormat& type) { +std::ostream& operator<<(std::ostream& s, const op::LSTMWeightsFormat& type) { return s << as_string(type); } @@ -282,9 +278,9 @@ op::v4::LSTMCell::LSTMCell(const Output& X, const Output& W, const Output& R, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip) : RNNCellBase({X, initial_hidden_state, initial_cell_state, W, R}, hidden_size, @@ -306,9 +302,9 @@ op::v4::LSTMCell::LSTMCell(const Output& X, const Output& R, const Output& B, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip) : RNNCellBase({X, initial_hidden_state, initial_cell_state, W, R, B}, hidden_size, @@ -322,7 +318,7 @@ op::v4::LSTMCell::LSTMCell(const Output& X, constructor_validate_and_infer_types(); } -bool ngraph::op::v4::LSTMCell::visit_attributes(AttributeVisitor& visitor) { +bool op::v4::LSTMCell::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v4_LSTMCell_visit_attributes); return op::util::RNNCellBase::visit_attributes(visitor); } @@ -368,36 +364,37 @@ void op::v4::LSTMCell::validate_and_infer_types() { Output op::v4::LSTMCell::get_default_bias_input() const { return Output{op::v0::Constant::create(get_input_element_type(0), Shape{lstm_cell::gates_count * get_hidden_size()}, - vector{0.f})}; + std::vector{0.f})}; } -shared_ptr op::v4::LSTMCell::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v4::LSTMCell::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v4_LSTMCell_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip()); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip()); } else if (new_args.size() == 6) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip()); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip()); } else { OPENVINO_THROW("Incorrect number of new arguments"); } } +} // namespace ov diff --git a/src/core/src/op/lstm_sequence.cpp b/src/core/src/op/lstm_sequence.cpp index 169f10d07f9ca3..492f42d051d7da 100644 --- a/src/core/src/op/lstm_sequence.cpp +++ b/src/core/src/op/lstm_sequence.cpp @@ -2,21 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/lstm_sequence.hpp" +#include "openvino/op/lstm_sequence.hpp" #include "itt.hpp" #include "lstm_sequence_shape_inference.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/builder/autobroadcast.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/builder/split.hpp" -#include "ngraph/op/util/recurrent_sequence.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "ngraph/opsets/opset4.hpp" - -using namespace ngraph; -using namespace std; +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/op/util/recurrent_sequence.hpp" +namespace ov { op::v0::LSTMSequence::LSTMSequence(const Output& X, const Output& initial_hidden_state, const Output& initial_cell_state, @@ -95,42 +88,42 @@ bool op::v0::LSTMSequence::visit_attributes(AttributeVisitor& visitor) { return true; } -shared_ptr op::v0::LSTMSequence::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::LSTMSequence::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_LSTMSequence_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 8) { - return make_shared(new_args.at(0), // X - new_args.at(1), // initial_hidden_state - new_args.at(2), // initial_cell_state - new_args.at(3), // sequence_lengths - new_args.at(4), // W - new_args.at(5), // R - new_args.at(6), // B - new_args.at(7), // P - m_hidden_size, - m_direction, - m_weights_format, - m_activations_alpha, - m_activations_beta, - m_activations, - m_clip, - m_input_forget); + return std::make_shared(new_args.at(0), // X + new_args.at(1), // initial_hidden_state + new_args.at(2), // initial_cell_state + new_args.at(3), // sequence_lengths + new_args.at(4), // W + new_args.at(5), // R + new_args.at(6), // B + new_args.at(7), // P + m_hidden_size, + m_direction, + m_weights_format, + m_activations_alpha, + m_activations_beta, + m_activations, + m_clip, + m_input_forget); } else if (new_args.size() == 7) { - return make_shared(new_args.at(0), // X - new_args.at(1), // initial_hidden_state - new_args.at(2), // initial_cell_state - new_args.at(3), // sequence_lengths - new_args.at(4), // W - new_args.at(5), // R - new_args.at(6), // B - m_hidden_size, - m_direction, - m_weights_format, - m_activations_alpha, - m_activations_beta, - m_activations, - m_clip, - m_input_forget); + return std::make_shared(new_args.at(0), // X + new_args.at(1), // initial_hidden_state + new_args.at(2), // initial_cell_state + new_args.at(3), // sequence_lengths + new_args.at(4), // W + new_args.at(5), // R + new_args.at(6), // B + m_hidden_size, + m_direction, + m_weights_format, + m_activations_alpha, + m_activations_beta, + m_activations, + m_clip, + m_input_forget); } else { OPENVINO_THROW("Incorrect number of new arguments"); } @@ -166,29 +159,29 @@ void op::v0::LSTMSequence::validate_and_infer_types() { set_output_type(2, result_et, output_shapes[2]); } -bool ngraph::op::v5::LSTMSequence::visit_attributes(AttributeVisitor& visitor) { +bool op::v5::LSTMSequence::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v5_LSTMSequence_visit_attributes); visitor.on_attribute("direction", m_direction); return op::util::RNNCellBase::visit_attributes(visitor); } -shared_ptr op::v5::LSTMSequence::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v5::LSTMSequence::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v5_LSTMSequence_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 7) { - return make_shared(new_args.at(0), // X - new_args.at(1), // initial_hidden_state - new_args.at(2), // initial_cell_state - new_args.at(3), // sequence_lengths - new_args.at(4), // W - new_args.at(5), // R - new_args.at(6), // B - m_hidden_size, - m_direction, - m_activations_alpha, - m_activations_beta, - m_activations, - m_clip); + return std::make_shared(new_args.at(0), // X + new_args.at(1), // initial_hidden_state + new_args.at(2), // initial_cell_state + new_args.at(3), // sequence_lengths + new_args.at(4), // W + new_args.at(5), // R + new_args.at(6), // B + m_hidden_size, + m_direction, + m_activations_alpha, + m_activations_beta, + m_activations, + m_clip); } else { OPENVINO_THROW("Incorrect number of new arguments"); } @@ -224,3 +217,4 @@ void op::v5::LSTMSequence::validate_and_infer_types() { set_output_type(1, result_et, output_shapes[1]); set_output_type(2, result_et, output_shapes[2]); } +} // namespace ov diff --git a/src/core/src/op/mish.cpp b/src/core/src/op/mish.cpp index fc39df6e999c7d..1974e683029a6b 100644 --- a/src/core/src/op/mish.cpp +++ b/src/core/src/op/mish.cpp @@ -73,7 +73,7 @@ bool evaluate_mish(const HostTensorPtr& arg0, const HostTensorPtr& out) { bool op::v4::Mish::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v4_Mish_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return mish::evaluate_mish(inputs[0], outputs[0]); } diff --git a/src/core/src/op/mod.cpp b/src/core/src/op/mod.cpp index 6bb45da04004cb..e8aa1a8a009cc2 100644 --- a/src/core/src/op/mod.cpp +++ b/src/core/src/op/mod.cpp @@ -6,6 +6,7 @@ #include "element_visitor.hpp" #include "itt.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/reference/mod.hpp" #include "utils.hpp" diff --git a/src/core/src/op/negative.cpp b/src/core/src/op/negative.cpp index 3feadeb1c7505e..5b86e98e6ad2a1 100644 --- a/src/core/src/op/negative.cpp +++ b/src/core/src/op/negative.cpp @@ -59,8 +59,8 @@ bool evaluate_negative(const HostTensorPtr& arg0, const HostTensorPtr& out, cons bool op::Negative::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Negative_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 1)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return negativeop::evaluate_negative(inputs[0], outputs[0], shape_size(inputs[0]->get_shape())); } diff --git a/src/core/src/op/not_equal.cpp b/src/core/src/op/not_equal.cpp index 89018aec9bcdb0..80c77cfa58f1c1 100644 --- a/src/core/src/op/not_equal.cpp +++ b/src/core/src/op/not_equal.cpp @@ -67,7 +67,7 @@ shared_ptr op::v1::NotEqual::clone_with_new_inputs(const OutputVector& new bool op::v1::NotEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_NotEqual_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); OPENVINO_SUPPRESS_DEPRECATED_END return not_equalop::evaluate_not_equal(inputs[0], inputs[1], outputs[0], get_autob()); } diff --git a/src/core/src/op/one_hot.cpp b/src/core/src/op/one_hot.cpp index 963b4980f02b9c..81186f506e10dd 100644 --- a/src/core/src/op/one_hot.cpp +++ b/src/core/src/op/one_hot.cpp @@ -107,21 +107,21 @@ bool evaluate_onehot(const HostTensorVector& output_values, const HostTensorVect bool op::v1::OneHot::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { OV_OP_SCOPE(v1_OneHot_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 4)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 4)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END const auto& ind_Pshape = input_values[0]->get_partial_shape(); const auto& out_Pshape = output_values[0]->get_partial_shape(); - NGRAPH_CHECK(ind_Pshape.is_static() && out_Pshape.is_static(), "Only static input/output shapes are supported"); + OPENVINO_ASSERT(ind_Pshape.is_static() && out_Pshape.is_static(), "Only static input/output shapes are supported"); const auto out_shape = out_Pshape.get_shape(); const int64_t axis = get_axis(); - NGRAPH_CHECK(axis >= 0 && static_cast(axis) < out_shape.size(), "Invalid axis value."); + OPENVINO_ASSERT(axis >= 0 && static_cast(axis) < out_shape.size(), "Invalid axis value."); const auto depth = std::make_shared(input_values[1])->cast_vector()[0]; const auto ind_shape = ind_Pshape.get_shape(); - NGRAPH_CHECK(shape_size(ind_shape) * depth == shape_size(out_shape), - "Incompatible I/O shapes or wrong depth value."); - NGRAPH_CHECK(static_cast(out_shape[axis]) == depth, "Incompatible axis and depth values."); + OPENVINO_ASSERT(shape_size(ind_shape) * depth == shape_size(out_shape), + "Incompatible I/O shapes or wrong depth value."); + OPENVINO_ASSERT(static_cast(out_shape[axis]) == depth, "Incompatible axis and depth values."); return one_hot::evaluate_onehot(output_values, input_values, axis); } diff --git a/src/core/src/op/op.cpp b/src/core/src/op/op.cpp index 0dce762c0f5ccc..383de812c94d14 100644 --- a/src/core/src/op/op.cpp +++ b/src/core/src/op/op.cpp @@ -2,15 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/op.hpp" +#include "openvino/op/op.hpp" #include #include #include -#include "ngraph/node.hpp" -#include "ngraph/type/element_type.hpp" - -using namespace std; +#include "openvino/core/node.hpp" +#include "openvino/core/type/element_type.hpp" ov::op::Op::Op(const ov::OutputVector& args) : Node(args) {} diff --git a/src/core/src/op/parameter.cpp b/src/core/src/op/parameter.cpp index 7d9fd67bd9cad2..a7e598a7e89177 100644 --- a/src/core/src/op/parameter.cpp +++ b/src/core/src/op/parameter.cpp @@ -2,60 +2,59 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/parameter.hpp" +#include "openvino/op/parameter.hpp" #include #include "itt.hpp" #include "layout_utils.hpp" -#include "ngraph/attribute_visitor.hpp" +#include "openvino/core/attribute_visitor.hpp" -using namespace std; -using namespace ngraph; +namespace ov { -op::Parameter::Parameter(const element::Type& element_type, const ov::PartialShape& pshape) +op::v0::Parameter::Parameter(const element::Type& element_type, const ov::PartialShape& pshape) : m_partial_shape(pshape), m_element_type(element_type), m_is_relevant_to_shapes(false) { constructor_validate_and_infer_types(); } -bool op::Parameter::visit_attributes(AttributeVisitor& visitor) { +bool op::v0::Parameter::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_Parameter_visit_attributes); visitor.on_attribute("shape", m_partial_shape); visitor.on_attribute("element_type", m_element_type); return true; } -void op::Parameter::validate_and_infer_types() { +void op::v0::Parameter::validate_and_infer_types() { OV_OP_SCOPE(v0_Parameter_validate_and_infer_types); Op::validate_and_infer_types(); set_output_type(0, m_element_type, m_partial_shape); } -shared_ptr op::Parameter::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::Parameter::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Parameter_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(m_element_type, m_partial_shape); + return std::make_shared(m_element_type, m_partial_shape); } -bool op::Parameter::is_relevant_to_shapes() const { +bool op::v0::Parameter::is_relevant_to_shapes() const { return m_is_relevant_to_shapes; } -void op::Parameter::set_is_relevant_to_shapes(bool is_relevant) { +void op::v0::Parameter::set_is_relevant_to_shapes(bool is_relevant) { m_is_relevant_to_shapes = is_relevant; } -ov::Layout op::Parameter::get_layout() const { +ov::Layout op::v0::Parameter::get_layout() const { return ov::layout::get_layout(output(0)); } -void op::Parameter::set_layout(const ov::Layout& layout) { +void op::v0::Parameter::set_layout(const ov::Layout& layout) { ov::layout::set_layout(output(0), layout); } -void op::Parameter::set_partial_shape(const PartialShape& partial_shape) { +void op::v0::Parameter::set_partial_shape(const PartialShape& partial_shape) { OPENVINO_ASSERT(ov::layout::utils::is_compatible(get_layout(), partial_shape), "Can't set partial shape ", partial_shape, @@ -67,26 +66,27 @@ void op::Parameter::set_partial_shape(const PartialShape& partial_shape) { m_partial_shape = partial_shape; } -ov::AttributeAdapter::AttributeAdapter(ParameterVector& ref) : m_ref(ref) {} +AttributeAdapter::AttributeAdapter(ParameterVector& ref) : m_ref(ref) {} -bool ov::AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { +bool AttributeAdapter::visit_attributes(AttributeVisitor& visitor) { size_t size = m_ref.size(); visitor.on_attribute("size", size); if (size != m_ref.size()) { m_ref.resize(size); } - ostringstream index; + std::ostringstream index; for (size_t i = 0; i < size; i++) { index.str(""); index << i; - string id; + std::string id; if (m_ref[i]) { id = visitor.get_registered_node_id(m_ref[i]); } visitor.on_attribute(index.str(), id); if (!m_ref[i]) { - m_ref[i] = ov::as_type_ptr(visitor.get_registered_node(id)); + m_ref[i] = ov::as_type_ptr(visitor.get_registered_node(id)); } } return true; } +} // namespace ov diff --git a/src/core/src/op/prelu.cpp b/src/core/src/op/prelu.cpp index 2bc9380e6d4ab8..782ca120733722 100644 --- a/src/core/src/op/prelu.cpp +++ b/src/core/src/op/prelu.cpp @@ -66,7 +66,7 @@ bool evaluate_prelu(const ngraph::HostTensorPtr& arg, bool ov::op::v0::PRelu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_PRelu_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(ngraph::validate_host_tensor_vector(outputs, 1) && ngraph::validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(outputs, 1) && ngraph::validate_host_tensor_vector(inputs, 2)); OPENVINO_SUPPRESS_DEPRECATED_END return prelu::evaluate_prelu(inputs[0], inputs[1], outputs[0]); } diff --git a/src/core/src/op/psroi_pooling.cpp b/src/core/src/op/psroi_pooling.cpp index d45999b87c5b81..b45d9c0943fa29 100644 --- a/src/core/src/op/psroi_pooling.cpp +++ b/src/core/src/op/psroi_pooling.cpp @@ -9,8 +9,6 @@ #include "openvino/core/validation_util.hpp" #include "psroi_pooling_shape_inference.hpp" -using namespace std; - namespace ov { namespace op { namespace v0 { @@ -22,7 +20,7 @@ PSROIPooling::PSROIPooling(const Output& input, const float spatial_scale, int spatial_bins_x, int spatial_bins_y, - const string& mode) + const std::string& mode) : Op({input, coords}), m_output_dim(output_dim), m_group_size(group_size), @@ -61,17 +59,17 @@ void PSROIPooling::validate_and_infer_types() { set_output_type(0, feat_maps_et, output_shapes[0]); } -shared_ptr PSROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr PSROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_PSROIPooling_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - m_output_dim, - m_group_size, - m_spatial_scale, - m_spatial_bins_x, - m_spatial_bins_y, - m_mode); + return std::make_shared(new_args.at(0), + new_args.at(1), + m_output_dim, + m_group_size, + m_spatial_scale, + m_spatial_bins_x, + m_spatial_bins_y, + m_mode); } void PSROIPooling::set_output_dim(size_t output_dim) { diff --git a/src/core/src/op/rdft.cpp b/src/core/src/op/rdft.cpp index 9aa7babae1581a..2627a2245c2fb3 100644 --- a/src/core/src/op/rdft.cpp +++ b/src/core/src/op/rdft.cpp @@ -2,15 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/rdft.hpp" +#include "openvino/op/rdft.hpp" #include #include "itt.hpp" #include "rdft_shape_inference.hpp" -using namespace std; - ov::op::v9::RDFT::RDFT(const Output& data, const Output& axes) : FFTBase(data, axes) { constructor_validate_and_infer_types(); } @@ -20,11 +18,6 @@ ov::op::v9::RDFT::RDFT(const Output& data, const Output& axes, const constructor_validate_and_infer_types(); } -bool ov::op::v9::RDFT::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v9_RDFT_visit_attributes); - return true; -} - std::shared_ptr ov::op::v9::RDFT::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v9_RDFT_clone_with_new_inputs); check_new_args_count(this, new_args); diff --git a/src/core/src/op/reduce_logical_and.cpp b/src/core/src/op/reduce_logical_and.cpp index 59a33cb8716655..6ca1444fd90c08 100644 --- a/src/core/src/op/reduce_logical_and.cpp +++ b/src/core/src/op/reduce_logical_and.cpp @@ -56,8 +56,8 @@ bool evaluate_reduce_logical_and(const HostTensorPtr& data, bool op::v1::ReduceLogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceLogicalAnd_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto& data = inputs[0]; const auto& axes = inputs[1]; diff --git a/src/core/src/op/reduce_logical_or.cpp b/src/core/src/op/reduce_logical_or.cpp index a167d44a884258..dce03e81e40ce0 100644 --- a/src/core/src/op/reduce_logical_or.cpp +++ b/src/core/src/op/reduce_logical_or.cpp @@ -56,8 +56,8 @@ bool evaluate_reduce_logical_or(const HostTensorPtr& data, bool op::v1::ReduceLogicalOr::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceLogicalOr_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto& data = inputs[0]; const auto& axes = inputs[1]; diff --git a/src/core/src/op/reduce_max.cpp b/src/core/src/op/reduce_max.cpp index e7e33b5221c3a1..35f2216bac8bfc 100644 --- a/src/core/src/op/reduce_max.cpp +++ b/src/core/src/op/reduce_max.cpp @@ -62,8 +62,8 @@ shared_ptr op::v1::ReduceMax::clone_with_new_inputs(const OutputVector& ne bool op::v1::ReduceMax::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMax_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto reduction_axes = get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); diff --git a/src/core/src/op/reduce_mean.cpp b/src/core/src/op/reduce_mean.cpp index 734efc4d814048..bc425fa0c2095c 100644 --- a/src/core/src/op/reduce_mean.cpp +++ b/src/core/src/op/reduce_mean.cpp @@ -61,8 +61,8 @@ bool evaluate_mean(const HostTensorPtr& arg, const HostTensorPtr& out, const Axi bool op::v1::ReduceMean::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMean_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto reduction_axes = get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); diff --git a/src/core/src/op/reduce_min.cpp b/src/core/src/op/reduce_min.cpp index f77e5236b51064..7f6e927748bb56 100644 --- a/src/core/src/op/reduce_min.cpp +++ b/src/core/src/op/reduce_min.cpp @@ -61,8 +61,8 @@ shared_ptr op::v1::ReduceMin::clone_with_new_inputs(const OutputVector& ne bool op::v1::ReduceMin::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceMin_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto reduction_axes = get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); diff --git a/src/core/src/op/reduce_prod.cpp b/src/core/src/op/reduce_prod.cpp index 14747e9b5d6413..dd915427b2415d 100644 --- a/src/core/src/op/reduce_prod.cpp +++ b/src/core/src/op/reduce_prod.cpp @@ -59,8 +59,8 @@ bool evaluate_product(const HostTensorPtr& arg, const HostTensorPtr& out, const bool op::v1::ReduceProd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceProd_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto reduction_axes = get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); diff --git a/src/core/src/op/reduce_sum.cpp b/src/core/src/op/reduce_sum.cpp index 47da7ee137bcf6..54797693251ae1 100644 --- a/src/core/src/op/reduce_sum.cpp +++ b/src/core/src/op/reduce_sum.cpp @@ -62,8 +62,8 @@ bool evaluate_sum(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis bool op::v1::ReduceSum::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_ReduceSum_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); const auto reduction_axes = get_normalized_axes_from_tensor(inputs[1], inputs[0]->get_partial_shape().rank(), get_friendly_name()); diff --git a/src/core/src/op/relu.cpp b/src/core/src/op/relu.cpp index cbaa57030bae99..d0795cb646e9b9 100644 --- a/src/core/src/op/relu.cpp +++ b/src/core/src/op/relu.cpp @@ -58,7 +58,7 @@ bool evaluate_relu(const HostTensorPtr& arg0, const HostTensorPtr& out) { bool op::Relu::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Relu_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return relu::evaluate_relu(inputs[0], outputs[0]); } diff --git a/src/core/src/op/reshape.cpp b/src/core/src/op/reshape.cpp index 058dff135c0484..52b78bfbf8a37e 100644 --- a/src/core/src/op/reshape.cpp +++ b/src/core/src/op/reshape.cpp @@ -96,9 +96,9 @@ void op::v1::Reshape::validate_and_infer_types() { auto upper_bound = std::make_shared(ub.get_element_type(), ub.get_shape(), ub.data()) ->cast_vector(); shape_can_be_calculated = true; - NGRAPH_CHECK(lower_bound.size() == upper_bound.size()); + OPENVINO_ASSERT(lower_bound.size() == upper_bound.size()); const TensorLabel& labels = get_input_source_output(1).get_tensor().get_value_label(); - NGRAPH_CHECK(labels.empty() || lower_bound.size() == labels.size()); + OPENVINO_ASSERT(labels.empty() || lower_bound.size() == labels.size()); for (size_t i = 0; i < lower_bound.size(); ++i) { NODE_VALIDATION_CHECK(this, @@ -125,7 +125,7 @@ void op::v1::Reshape::validate_and_infer_types() { // or equal to 1 if (output_rank.is_static() && output_rank.get_length() == 0 && !lower_bound.empty()) { reshape_pattern.clear(); - NGRAPH_CHECK(lower_bound.size() == 1); + OPENVINO_ASSERT(lower_bound.size() == 1); NODE_VALIDATION_CHECK(this, lower_bound[0] == 1 && upper_bound[0] == 1, "The value of scalar shape pattern should be equal to 1!"); @@ -182,7 +182,7 @@ bool op::v1::Reshape::evaluate_reshape(const HostTensorVector& outputs, const Ho std::vector output_shape(out_shape_val.size()); calculate_output_shape(reshape_pattern, minus_one_idx, inputs[0]->get_partial_shape(), output_shape); - NGRAPH_CHECK(ov::PartialShape(output_shape).is_static()); + OPENVINO_ASSERT(ov::PartialShape(output_shape).is_static()); outputs[0]->set_shape(ov::PartialShape(output_shape).to_shape()); OPENVINO_SUPPRESS_DEPRECATED_START @@ -194,8 +194,8 @@ bool op::v1::Reshape::evaluate_reshape(const HostTensorVector& outputs, const Ho bool op::v1::Reshape::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_Reshape_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 2)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return evaluate_reshape(outputs, inputs); } diff --git a/src/core/src/op/reverse.cpp b/src/core/src/op/reverse.cpp index 4caaa2fb01f4d9..7b2f386cb5661a 100644 --- a/src/core/src/op/reverse.cpp +++ b/src/core/src/op/reverse.cpp @@ -99,7 +99,7 @@ bool op::v1::Reverse::evaluate_reverse(const HostTensorVector& outputs, const Ho GET_AXES(u32, axes, inputs[1]); GET_AXES(u64, axes, inputs[1]); default: - NGRAPH_CHECK(false, "Not supported axes type", inputs[1]->get_element_type()); + OPENVINO_ASSERT(false, "Not supported axes type", inputs[1]->get_element_type()); } } else // Mode::MASK { diff --git a/src/core/src/op/reverse_sequence.cpp b/src/core/src/op/reverse_sequence.cpp index af6ab100e627fc..814a87451a09cd 100644 --- a/src/core/src/op/reverse_sequence.cpp +++ b/src/core/src/op/reverse_sequence.cpp @@ -2,38 +2,35 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/reverse_sequence.hpp" +#include "openvino/op/reverse_sequence.hpp" #include #include -#include #include "itt.hpp" -#include "ngraph/attribute_visitor.hpp" -#include "ngraph/node.hpp" -#include "ngraph/validation_util.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/validation_util.hpp" +#include "reverse_sequence_shape_inference.hpp" -using namespace std; -using namespace ngraph; - -op::ReverseSequence::ReverseSequence(const Output& arg, - const Output& seq_indices, - int64_t batch_axis, - int64_t seq_axis) +namespace ov { +op::v0::ReverseSequence::ReverseSequence(const Output& arg, + const Output& seq_indices, + int64_t batch_axis, + int64_t seq_axis) : Op({arg, seq_indices}), m_batch_axis(batch_axis), m_seq_axis(seq_axis) { constructor_validate_and_infer_types(); } -bool ngraph::op::v0::ReverseSequence::visit_attributes(AttributeVisitor& visitor) { +bool op::v0::ReverseSequence::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_ReverseSequence_visit_attributes); visitor.on_attribute("batch_axis", m_batch_axis); visitor.on_attribute("seq_axis", m_seq_axis); return true; } -void op::ReverseSequence::validate_and_infer_types() { +void op::v0::ReverseSequence::validate_and_infer_types() { OV_OP_SCOPE(v0_ReverseSequence_validate_and_infer_types); const auto& seq_lengths_et = get_input_element_type(1); NODE_VALIDATION_CHECK(this, @@ -51,26 +48,27 @@ void op::ReverseSequence::validate_and_infer_types() { OPENVINO_SUPPRESS_DEPRECATED_END } -shared_ptr op::ReverseSequence::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::ReverseSequence::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_ReverseSequence_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_batch_axis, m_seq_axis); + return std::make_shared(new_args.at(0), new_args.at(1), m_batch_axis, m_seq_axis); } -void op::ReverseSequence::set_batch_axis(int64_t batch_axis) { +void op::v0::ReverseSequence::set_batch_axis(int64_t batch_axis) { m_batch_axis = batch_axis; } -size_t op::ReverseSequence::get_batch_axis() const { +size_t op::v0::ReverseSequence::get_batch_axis() const { const auto& data_rank = get_input_partial_shape(0).rank(); OPENVINO_SUPPRESS_DEPRECATED_START return static_cast(ov::normalize_axis(this, m_batch_axis, data_rank)); OPENVINO_SUPPRESS_DEPRECATED_END } -void op::ReverseSequence::set_sequence_axis(int64_t sequence_axis) { +void op::v0::ReverseSequence::set_sequence_axis(int64_t sequence_axis) { m_seq_axis = sequence_axis; OPENVINO_SUPPRESS_DEPRECATED_START m_normalized_seq_axis = ov::normalize_axis(this, m_seq_axis, get_input_partial_shape(0).rank()); OPENVINO_SUPPRESS_DEPRECATED_END } +} // namespace ov diff --git a/src/core/src/op/rnn_cell.cpp b/src/core/src/op/rnn_cell.cpp index 02a85c34faafbf..56c6a41664d89c 100644 --- a/src/core/src/op/rnn_cell.cpp +++ b/src/core/src/op/rnn_cell.cpp @@ -2,19 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/rnn_cell.hpp" +#include "openvino/op/rnn_cell.hpp" #include #include "itt.hpp" -#include "ngraph/builder/reshape.hpp" -#include "ngraph/op/constant.hpp" -#include "ngraph/shape.hpp" -#include "ngraph/type/element_type.hpp" +#include "openvino/core/type/element_type.hpp" #include "rnn_cell_shape_inference.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v0::RNNCell::RNNCell() { m_activations = {"tanh"}; @@ -26,9 +22,9 @@ op::v0::RNNCell::RNNCell(const Output& X, const Output& W, const Output& R, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip) : RNNCellBase({X, initial_hidden_state, W, R}, hidden_size, clip, activations, activations_alpha, activations_beta), m_activation_f{get_activation_function(0)} { @@ -42,9 +38,9 @@ op::v0::RNNCell::RNNCell(const Output& X, const Output& R, const Output& B, size_t hidden_size, - const vector& activations, - const vector& activations_alpha, - const vector& activations_beta, + const std::vector& activations, + const std::vector& activations_alpha, + const std::vector& activations_beta, float clip) : RNNCellBase({X, initial_hidden_state, W, R, B}, hidden_size, @@ -88,34 +84,35 @@ void op::v0::RNNCell::validate_and_infer_types() { Output op::v0::RNNCell::get_default_bias_input() const { return Output{op::v0::Constant::create(get_input_element_type(0), ov::Shape{s_gates_count * get_hidden_size()}, - vector(s_gates_count * get_hidden_size(), 0.f))}; + std::vector(s_gates_count * get_hidden_size(), 0.f))}; } -shared_ptr op::v0::RNNCell::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::RNNCell::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_RNNCell_clone_with_new_inputs); check_new_args_count(this, new_args); if (new_args.size() == 4) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip()); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip()); } else if (new_args.size() == 5) { - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - get_hidden_size(), - get_activations(), - get_activations_alpha(), - get_activations_beta(), - get_clip()); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + get_hidden_size(), + get_activations(), + get_activations_alpha(), + get_activations_beta(), + get_clip()); } else { OPENVINO_THROW("Incorrect number of new arguments"); } } +} // namespace ov diff --git a/src/core/src/op/rnn_sequence.cpp b/src/core/src/op/rnn_sequence.cpp index 8e33461510e2bb..3e599bd75b21f1 100644 --- a/src/core/src/op/rnn_sequence.cpp +++ b/src/core/src/op/rnn_sequence.cpp @@ -2,20 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/rnn_sequence.hpp" +#include "openvino/op/rnn_sequence.hpp" #include #include #include #include "itt.hpp" -#include "ngraph/op/util/recurrent_sequence.hpp" -#include "ngraph/opsets/opset4.hpp" +#include "openvino/op/util/recurrent_sequence.hpp" #include "rnn_sequence_shape_inference.hpp" -using namespace std; -using namespace ngraph; - +namespace ov { op::v5::RNNSequence::RNNSequence() : m_direction(op::RecurrentSequenceDirection::FORWARD) {} op::v5::RNNSequence::RNNSequence(const Output& X, @@ -73,19 +70,20 @@ bool op::v5::RNNSequence::visit_attributes(AttributeVisitor& visitor) { return op::util::RNNCellBase::visit_attributes(visitor); } -shared_ptr op::v5::RNNSequence::clone_with_new_inputs(const ngraph::OutputVector& new_args) const { +std::shared_ptr op::v5::RNNSequence::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v5_RNNSequence_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), - new_args.at(1), - new_args.at(2), - new_args.at(3), - new_args.at(4), - new_args.at(5), - m_hidden_size, - m_direction, - m_activations, - m_activations_alpha, - m_activations_beta, - m_clip); + return std::make_shared(new_args.at(0), + new_args.at(1), + new_args.at(2), + new_args.at(3), + new_args.at(4), + new_args.at(5), + m_hidden_size, + m_direction, + m_activations, + m_activations_alpha, + m_activations_beta, + m_clip); } +} // namespace ov diff --git a/src/core/src/op/roi_pooling.cpp b/src/core/src/op/roi_pooling.cpp index 7b508e46a14338..678c58fe8221ca 100644 --- a/src/core/src/op/roi_pooling.cpp +++ b/src/core/src/op/roi_pooling.cpp @@ -8,8 +8,6 @@ #include "openvino/core/validation_util.hpp" #include "roi_pooling_shape_inference.hpp" -using namespace std; - namespace ov { namespace op { namespace v0 { @@ -17,7 +15,7 @@ ROIPooling::ROIPooling(const Output& input, const Output& coords, const ov::Shape& output_size, const float spatial_scale, - const string& method) + const std::string& method) : Op({input, coords}), m_output_size(output_size), m_spatial_scale(spatial_scale), @@ -64,10 +62,10 @@ void ROIPooling::validate_and_infer_types() { } } -shared_ptr ROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ROIPooling::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_ROIPooling_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_output_size, m_spatial_scale, m_method); + return std::make_shared(new_args.at(0), new_args.at(1), m_output_size, m_spatial_scale, m_method); } bool ROIPooling::visit_attributes(AttributeVisitor& visitor) { diff --git a/src/core/src/op/scatter_nd_update.cpp b/src/core/src/op/scatter_nd_update.cpp index 2d49046ea115cb..1195b76fa3f7dc 100644 --- a/src/core/src/op/scatter_nd_update.cpp +++ b/src/core/src/op/scatter_nd_update.cpp @@ -82,10 +82,10 @@ bool evaluate_scatter(const HostTensorPtr& arg0, bool op::v3::ScatterNDUpdate::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v3_ScatterNDUpdate_evaluate); - NGRAPH_CHECK(!inputs.empty()); + OPENVINO_ASSERT(!inputs.empty()); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, 3)); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, 3)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return scatter::evaluate_scatter(inputs[0], inputs[1], inputs[2], outputs[0]); diff --git a/src/core/src/op/scatter_update.cpp b/src/core/src/op/scatter_update.cpp index 32c15992c8b7c0..1f531b9a2a42a9 100644 --- a/src/core/src/op/scatter_update.cpp +++ b/src/core/src/op/scatter_update.cpp @@ -55,7 +55,7 @@ bool op::v3::ScatterUpdate::evaluate_scatter_update(const HostTensorVector& outp const auto elem_size = data->get_element_type().size(); out->set_shape(data->get_shape()); - NGRAPH_CHECK(axis->get_element_type().is_integral_number(), "axis element type is not integral data type"); + OPENVINO_ASSERT(axis->get_element_type().is_integral_number(), "axis element type is not integral data type"); OPENVINO_SUPPRESS_DEPRECATED_START int64_t axis_val = host_tensor_2_vector(axis)[0]; diff --git a/src/core/src/op/select.cpp b/src/core/src/op/select.cpp index 7a4668179bfdc8..5108aecdedd9b4 100644 --- a/src/core/src/op/select.cpp +++ b/src/core/src/op/select.cpp @@ -118,8 +118,8 @@ bool evaluate_select(const HostTensorVector& output_values, bool op::v1::Select::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { OV_OP_SCOPE(v1_Select_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 3)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 3)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END const auto autob = get_auto_broadcast(); return detail::evaluate_select(output_values, input_values, autob, output_values[0]->get_element_type()); diff --git a/src/core/src/op/selu.cpp b/src/core/src/op/selu.cpp index 76bae32ecb431d..7ec6bd6970ad9b 100644 --- a/src/core/src/op/selu.cpp +++ b/src/core/src/op/selu.cpp @@ -2,12 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/selu.hpp" +#include "openvino/op/selu.hpp" #include "itt.hpp" -using namespace std; -using namespace ngraph; +namespace ov { op::v0::Selu::Selu(const Output& data, const Output& alpha, const Output& lambda) : Op({data, alpha, lambda}) { @@ -40,13 +39,9 @@ void op::v0::Selu::validate_and_infer_types() { set_output_type(0, result_et, get_input_partial_shape(0)); } -bool op::v0::Selu::visit_attributes(AttributeVisitor& visitor) { - OV_OP_SCOPE(v0_Selu_visit_attributes); - return true; -} - -shared_ptr op::v0::Selu::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr op::v0::Selu::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_Selu_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); + return std::make_shared(new_args.at(0), new_args.at(1), new_args.at(2)); } +} // namespace ov diff --git a/src/core/src/op/shape_of.cpp b/src/core/src/op/shape_of.cpp index 673b6aa1abf22a..3fa225cea017fc 100644 --- a/src/core/src/op/shape_of.cpp +++ b/src/core/src/op/shape_of.cpp @@ -114,7 +114,7 @@ bool constant_fold_shape_of(Node* shape_of_node, Output& replacement, cons } bool evaluate_bound_shape(const Node* shape_of_node, ov::TensorVector& output_values, bool is_upper) { - NGRAPH_CHECK(shape_of_node, output_values.size() == 1); + OPENVINO_ASSERT(shape_of_node, output_values.size() == 1); const auto& input_partial_shape = shape_of_node->get_input_partial_shape(0); if (input_partial_shape.rank().is_dynamic()) return false; @@ -126,7 +126,7 @@ bool evaluate_bound_shape(const Node* shape_of_node, ov::TensorVector& output_va pshape_up[i] = Dimension(interval.get_max_val()).is_dynamic() ? Dimension(interval.get_max_val() - 1) : interval.get_max_val(); } - NGRAPH_CHECK(pshape_up.is_static() && pshape_low.is_static()); + OPENVINO_ASSERT(pshape_up.is_static() && pshape_low.is_static()); const auto output_et = output_values[0].get_element_type(); if (pshape_low.to_shape() == pshape_up.to_shape()) { @@ -156,7 +156,7 @@ bool evaluate_bound_shape(const Node* shape_of_node, ov::TensorVector& output_va bool evaluate_label(const Node* shape_of_node, TensorLabelVector& output_labels) { const auto& shape = shape_of_node->get_input_partial_shape(0); - NGRAPH_CHECK(shape.rank().is_static()); // sanity check. at this point value propagation was successful + OPENVINO_ASSERT(shape.rank().is_static()); // sanity check. at this point value propagation was successful output_labels[0].reserve(shape.size()); bool label_is_set = false; for (const auto& d : shape) { @@ -173,8 +173,8 @@ bool evaluate_label(const Node* shape_of_node, TensorLabelVector& output_labels) bool op::v3::ShapeOf::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { OV_OP_SCOPE(v3_ShapeOf_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 1)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return shape_of::evaluate_shape_of(output_values[0], input_values[0]); } @@ -241,20 +241,20 @@ shared_ptr op::v0::ShapeOf::clone_with_new_inputs(const OutputVector& new_ OV_OP_SCOPE(v0_ShapeOf_clone_with_new_inputs); check_new_args_count(this, new_args); auto new_shape_of = make_shared(new_args.at(0)); - NGRAPH_CHECK(new_shape_of.get(), - new_shape_of != nullptr, - "Cannot clone ", - description(), - " operation with name ", - get_friendly_name()); + OPENVINO_ASSERT(new_shape_of.get(), + new_shape_of != nullptr, + "Cannot clone ", + description(), + " operation with name ", + get_friendly_name()); return new_shape_of; } bool op::v0::ShapeOf::evaluate(const HostTensorVector& output_values, const HostTensorVector& input_values) const { OV_OP_SCOPE(v0_ShapeOf_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 1)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return shape_of::evaluate_shape_of(output_values[0], input_values[0]); } diff --git a/src/core/src/op/sigmoid.cpp b/src/core/src/op/sigmoid.cpp index 4eb8b4e02d6d48..c5c872ebc80bb7 100644 --- a/src/core/src/op/sigmoid.cpp +++ b/src/core/src/op/sigmoid.cpp @@ -59,7 +59,7 @@ bool evaluate_sigmoid(const HostTensorPtr& arg0, const HostTensorPtr& out) { bool ov::op::v0::Sigmoid::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Sigmoid_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return sigmoid::evaluate_sigmoid(inputs[0], outputs[0]); } diff --git a/src/core/src/op/sign.cpp b/src/core/src/op/sign.cpp index a9e9d51b946095..8044ffef21d6f6 100644 --- a/src/core/src/op/sign.cpp +++ b/src/core/src/op/sign.cpp @@ -60,7 +60,7 @@ bool evaluate_sign(const HostTensorPtr& arg0, const HostTensorPtr& out, const si bool op::Sign::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Sign_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return signop::evaluate_sign(inputs[0], outputs[0], shape_size(inputs[0]->get_shape())); } diff --git a/src/core/src/op/sink.cpp b/src/core/src/op/sink.cpp index 3ff50218b68f48..ae7bdc85245632 100644 --- a/src/core/src/op/sink.cpp +++ b/src/core/src/op/sink.cpp @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/sink.hpp" +#include "openvino/op/sink.hpp" -using namespace ngraph; - -op::Sink::~Sink() = default; +ov::op::Sink::~Sink() = default; diff --git a/src/core/src/op/softmax.cpp b/src/core/src/op/softmax.cpp index 975a83dd932f6a..126c6d82fc7252 100644 --- a/src/core/src/op/softmax.cpp +++ b/src/core/src/op/softmax.cpp @@ -76,7 +76,7 @@ shared_ptr op::v1::Softmax::clone_with_new_inputs(const OutputVector& new_ bool op::v1::Softmax::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v1_Softmax_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END outputs[0]->set_unary(inputs[0]); return evaluate_softmax(inputs[0], outputs[0], AxisSet{m_axis}); @@ -133,16 +133,16 @@ shared_ptr op::v8::Softmax::clone_with_new_inputs(const OutputVector& new_ bool op::v8::Softmax::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v8_Softmax_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END outputs[0]->set_unary(inputs[0]); auto rank = static_cast(inputs[0]->get_shape().size()); - NGRAPH_CHECK(-rank <= m_axis && m_axis < rank, - "Reduction axis (", - m_axis, - ") is out of bounds (argument shape: ", - inputs[0]->get_shape(), - ")."); + OPENVINO_ASSERT(-rank <= m_axis && m_axis < rank, + "Reduction axis (", + m_axis, + ") is out of bounds (argument shape: ", + inputs[0]->get_shape(), + ")."); OPENVINO_SUPPRESS_DEPRECATED_START size_t axis = static_cast(ov::normalize_axis(this->description(), m_axis, rank)); OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/src/core/src/op/softplus.cpp b/src/core/src/op/softplus.cpp index ee59d23623b8fa..70d1e63b17c1ee 100644 --- a/src/core/src/op/softplus.cpp +++ b/src/core/src/op/softplus.cpp @@ -73,7 +73,7 @@ bool evaluate_softplus(const HostTensorPtr& arg, const HostTensorPtr& out) { bool op::v4::SoftPlus::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v4_SoftPlus_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return softplus::evaluate_softplus(inputs[0], outputs[0]); } diff --git a/src/core/src/op/softsign.cpp b/src/core/src/op/softsign.cpp index 98e63984a8ff4c..9ec3e8038ea3f7 100644 --- a/src/core/src/op/softsign.cpp +++ b/src/core/src/op/softsign.cpp @@ -1,15 +1,15 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/reference/softsign.hpp" +#include "openvino/op/softsign.hpp" #include #include "itt.hpp" #include "openvino/core/attribute_visitor.hpp" -#include "openvino/op/softsign.hpp" +#include "openvino/core/shape_util.hpp" +#include "openvino/reference/softsign.hpp" #include "openvino/runtime/tensor.hpp" -#include "shape_util.hpp" namespace { template diff --git a/src/core/src/op/squared_difference.cpp b/src/core/src/op/squared_difference.cpp index 2c3c94dda99368..700e0a4a809d12 100644 --- a/src/core/src/op/squared_difference.cpp +++ b/src/core/src/op/squared_difference.cpp @@ -2,12 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/squared_difference.hpp" +#include "openvino/op/squared_difference.hpp" #include "itt.hpp" -using namespace std; - // ------------------------------ v0 ------------------------------------------- ov::op::v0::SquaredDifference::SquaredDifference(const Output& arg0, @@ -17,8 +15,8 @@ ov::op::v0::SquaredDifference::SquaredDifference(const Output& arg0, constructor_validate_and_infer_types(); } -shared_ptr ov::op::v0::SquaredDifference::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr ov::op::v0::SquaredDifference::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_SquaredDifference_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); + return std::make_shared(new_args.at(0), new_args.at(1), this->get_autob()); } diff --git a/src/core/src/op/squeeze.cpp b/src/core/src/op/squeeze.cpp index f96f628413acb1..50bf9af02d00a5 100644 --- a/src/core/src/op/squeeze.cpp +++ b/src/core/src/op/squeeze.cpp @@ -61,8 +61,8 @@ OPENVINO_SUPPRESS_DEPRECATED_START bool op::v0::Squeeze::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { OV_OP_SCOPE(v0_Squeeze_evaluate); OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(inputs, inputs.size())); - NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(inputs, inputs.size())); + OPENVINO_ASSERT(validate_host_tensor_vector(outputs, 1)); OPENVINO_SUPPRESS_DEPRECATED_END if (has_evaluate()) { diff --git a/src/core/src/op/strided_slice.cpp b/src/core/src/op/strided_slice.cpp index 79647177e654d3..f2e7493804957f 100644 --- a/src/core/src/op/strided_slice.cpp +++ b/src/core/src/op/strided_slice.cpp @@ -61,8 +61,8 @@ shared_ptr calculate_default_strides(const Output& begin, const Outp strides_length = end_pshape[0].get_length(); } else // dynamic case { - NGRAPH_CHECK(begin_pshape.rank().is_static() && begin_pshape.rank().get_length() == 1, - "Begin input must be 1D"); + OPENVINO_ASSERT(begin_pshape.rank().is_static() && begin_pshape.rank().get_length() == 1, + "Begin input must be 1D"); return std::make_shared(op::Constant::create(element::i64, {}, {1}), std::make_shared(begin)); } @@ -237,8 +237,8 @@ bool op::v1::StridedSlice::evaluate(const HostTensorVector& output_values, const OV_OP_SCOPE(v1_StridedSlice_evaluate); // FIXME: 4th input is optional, but it is required by the following code OPENVINO_SUPPRESS_DEPRECATED_START - NGRAPH_CHECK(validate_host_tensor_vector(input_values, 4)); - NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1)); + OPENVINO_ASSERT(validate_host_tensor_vector(input_values, 4)); + OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END return strided_slice::evaluate_strided_slice(input_values[0], input_values[1], diff --git a/src/core/src/op/tensor_iterator.cpp b/src/core/src/op/tensor_iterator.cpp index 1553b74fedd361..dbee0d02f976e7 100644 --- a/src/core/src/op/tensor_iterator.cpp +++ b/src/core/src/op/tensor_iterator.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/tensor_iterator.hpp" +#include "openvino/op/tensor_iterator.hpp" -#include "itt.hpp" -#include "ngraph/factory.hpp" -#include "ngraph/graph_util.hpp" -#include "ngraph/specialize_function.hpp" +#include -using namespace std; -using namespace ngraph; +#include "itt.hpp" +namespace ov { op::v0::TensorIterator::TensorIterator(const OutputVector& values) : op::util::SubGraphOp(values) {} bool op::v0::TensorIterator::visit_attributes(AttributeVisitor& visitor) { @@ -33,7 +30,7 @@ void op::v0::TensorIterator::revalidate_and_infer_types_for_body_ops() { while (nodes_to_do.size() > 0) { auto node = nodes_to_do.top(); if (nodes_done.count(node) == 0) { - NGRAPH_CHECK(ov::as_type_ptr(node) == nullptr, "No nested TensorIterator"); + OPENVINO_ASSERT(ov::as_type_ptr(node) == nullptr, "No nested TensorIterator"); bool can_add = true; size_t arg_count = node->get_input_size(); for (size_t i = 0; i < arg_count; ++i) { @@ -189,7 +186,7 @@ void op::v0::TensorIterator::try_to_set_num_iterations_if_no_slice_inputs() { std::shared_ptr op::v0::TensorIterator::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_TensorIterator_clone_with_new_inputs); - auto op = make_shared(); + auto op = std::make_shared(); op->set_arguments(new_args); op->set_output_size(m_output_descriptions.size()); @@ -205,3 +202,4 @@ std::shared_ptr op::v0::TensorIterator::clone_with_new_inputs(const Output op->validate_and_infer_types(); return op; } +} // namespace ov diff --git a/src/core/src/op/util/recurrent_sequence.cpp b/src/core/src/op/util/recurrent_sequence.cpp index fa126874fd9547..4bef269d4b599b 100644 --- a/src/core/src/op/util/recurrent_sequence.cpp +++ b/src/core/src/op/util/recurrent_sequence.cpp @@ -2,33 +2,32 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/util/recurrent_sequence.hpp" +#include "openvino/op/util/recurrent_sequence.hpp" -using namespace std; - -void ngraph::op::util::validate_seq_input_rank_dimension(const std::vector& input) { +void ov::op::util::validate_seq_input_rank_dimension(const std::vector& input) { enum { X, initial_hidden_state, sequence_lengths, W, R, B }; // Verify static ranks for all inputs for (size_t i = 0; i < input.size(); i++) { - NGRAPH_CHECK((input[i].rank().is_static()), "RNN Sequence supports only static rank for input tensors."); + OPENVINO_ASSERT((input[i].rank().is_static()), "RNN Sequence supports only static rank for input tensors."); } for (size_t i = 0; i < input.size(); i++) { if (i == B) { // verify B input dimension which is 2D - NGRAPH_CHECK((input[i].rank().get_length() == 2), "RNN Sequence B input tensor dimension is not correct."); + OPENVINO_ASSERT((input[i].rank().get_length() == 2), + "RNN Sequence B input tensor dimension is not correct."); } else if (i == sequence_lengths) { // verify sequence_length input dimension which is 1D - NGRAPH_CHECK((input[i].rank().get_length() == 1), - "RNN Sequence sequence_lengths input tensor dimension is not correct."); + OPENVINO_ASSERT((input[i].rank().get_length() == 1), + "RNN Sequence sequence_lengths input tensor dimension is not correct."); } else { // Verify all other input dimensions which are 3D tensor types - NGRAPH_CHECK((input[i].rank().get_length() == 3), - "RNN Sequence input tensor dimension is not correct for ", - i, - " input parameter. Current input length: ", - input[i].rank().get_length()); + OPENVINO_ASSERT((input[i].rank().get_length() == 3), + "RNN Sequence input tensor dimension is not correct for ", + i, + " input parameter. Current input length: ", + input[i].rank().get_length()); } } @@ -36,5 +35,5 @@ void ngraph::op::util::validate_seq_input_rank_dimension(const std::vectorget_element_type().is_integral_number(), "axis element type is not integral data type"); - NGRAPH_CHECK(split_lengths_tensor->get_element_type().is_integral_number(), - "split_lengths element type is not integral data type"); + OPENVINO_ASSERT(axis_tensor->get_element_type().is_integral_number(), + "axis element type is not integral data type"); + OPENVINO_ASSERT(split_lengths_tensor->get_element_type().is_integral_number(), + "split_lengths element type is not integral data type"); OPENVINO_SUPPRESS_DEPRECATED_START int64_t axis = host_tensor_2_vector(axis_tensor)[0]; diff --git a/src/core/src/op/xor.cpp b/src/core/src/op/xor.cpp index a571e47618e9d1..eafe1fe465e315 100644 --- a/src/core/src/op/xor.cpp +++ b/src/core/src/op/xor.cpp @@ -6,6 +6,7 @@ #include "element_visitor.hpp" #include "itt.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/op/logical_xor.hpp" #include "openvino/reference/xor.hpp" #include "utils.hpp" diff --git a/src/core/src/runtime/itensor.cpp b/src/core/src/runtime/itensor.cpp index 9149e3cb5c9bf2..6d966566c65610 100644 --- a/src/core/src/runtime/itensor.cpp +++ b/src/core/src/runtime/itensor.cpp @@ -7,10 +7,10 @@ #include #include "openvino/core/except.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/runtime/allocator.hpp" #include "openvino/runtime/iremote_tensor.hpp" #include "openvino/runtime/properties.hpp" -#include "shape_util.hpp" namespace ov { diff --git a/src/core/src/runtime/ov_tensor.cpp b/src/core/src/runtime/ov_tensor.cpp index ab9c9eebe443f7..f9182f5ea6b770 100644 --- a/src/core/src/runtime/ov_tensor.cpp +++ b/src/core/src/runtime/ov_tensor.cpp @@ -7,12 +7,12 @@ #include "openvino/core/except.hpp" #include "openvino/core/node_output.hpp" #include "openvino/core/shape.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/core/strides.hpp" #include "openvino/runtime/itensor.hpp" #include "openvino/runtime/make_tensor.hpp" #include "openvino/runtime/remote_tensor.hpp" #include "openvino/runtime/tensor.hpp" -#include "shape_util.hpp" namespace ov { diff --git a/src/core/src/shape_util.cpp b/src/core/src/shape_util.cpp index 411adb7ba5b6a5..9ce8512d7a7797 100644 --- a/src/core/src/shape_util.cpp +++ b/src/core/src/shape_util.cpp @@ -7,7 +7,7 @@ #include #include "openvino/core/partial_shape.hpp" -#include "shape_util.hpp" +#include "openvino/core/shape_util.hpp" using namespace ngraph; diff --git a/src/core/src/tensor_conversion_util.cpp b/src/core/src/tensor_conversion_util.cpp index 4804ea96109a19..4e0c40d3f21aa2 100644 --- a/src/core/src/tensor_conversion_util.cpp +++ b/src/core/src/tensor_conversion_util.cpp @@ -4,7 +4,7 @@ #include "tensor_conversion_util.hpp" -#include "shape_util.hpp" +#include "openvino/core/shape_util.hpp" namespace ov { namespace util { diff --git a/src/plugins/intel_cpu/src/nodes/reference.cpp b/src/plugins/intel_cpu/src/nodes/reference.cpp index 1d830ff0728e82..b42dc99b390fb4 100644 --- a/src/plugins/intel_cpu/src/nodes/reference.cpp +++ b/src/plugins/intel_cpu/src/nodes/reference.cpp @@ -2,14 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "reference.h" -#include -#include #include -#include "openvino/runtime/tensor.hpp" -#include "common/blocked_desc_creator.h" + +#include #include + +#include "common/blocked_desc_creator.h" #include "common/cpu_memcpy.h" +#include "openvino/core/shape_util.hpp" +#include "openvino/runtime/tensor.hpp" +#include "reference.h" using namespace dnnl; using namespace InferenceEngine; diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/custom_op_internal_dyn.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/custom_op_internal_dyn.cpp index eee10595ef4cd7..fb5ce680f5ff63 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/custom_op_internal_dyn.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/custom_op_internal_dyn.cpp @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include #include -#include #include -#include -#include + #include "ngraph_functions/utils/ngraph_helpers.hpp" using namespace ov::test; diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/custom_op_insert_convert_i64.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/custom_op_insert_convert_i64.cpp index 0e75077664e49c..c04b079b19445b 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/custom_op_insert_convert_i64.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/custom_op_insert_convert_i64.cpp @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // +#include +#include #include -#include #include -#include -#include + #include "test_utils/cpu_test_utils.hpp" using namespace ov::test; diff --git a/src/plugins/template/backend/int_executable.cpp b/src/plugins/template/backend/int_executable.cpp index f866d77b6528b6..7bf130cad87b83 100644 --- a/src/plugins/template/backend/int_executable.cpp +++ b/src/plugins/template/backend/int_executable.cpp @@ -9,12 +9,12 @@ #include "evaluates_map.hpp" #include "openvino/core/except.hpp" +#include "openvino/core/shape_util.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/result.hpp" #include "openvino/op/util/op_types.hpp" #include "openvino/op/util/variable_context.hpp" #include "perf_counter.hpp" -#include "shape_util.hpp" class TemporaryOverrideOutputs { std::shared_ptr model; diff --git a/src/plugins/template/backend/ops/if.cpp b/src/plugins/template/backend/ops/if.cpp index 6a64bcd1da1eac..dc3a8074996f16 100644 --- a/src/plugins/template/backend/ops/if.cpp +++ b/src/plugins/template/backend/ops/if.cpp @@ -6,7 +6,7 @@ #include "evaluate_node.hpp" #include "evaluates_map.hpp" -#include "shape_util.hpp" +#include "openvino/core/shape_util.hpp" namespace if_op { bool call(ov::TensorVector& func_outputs, From 0dd54c8a0ec401f99d39f01fcfa45f5fbd7f6774 Mon Sep 17 00:00:00 2001 From: Sofya Balandina Date: Mon, 25 Sep 2023 13:27:23 +0100 Subject: [PATCH 39/43] [apiConformance] Change test for ov::hint::inference_precision RW property (#19977) --- .../src/behavior/ov_plugin/properties.cpp | 6 +++ .../behavior/ov_plugin/properties_tests.hpp | 1 + .../behavior/ov_plugin/properties_tests.cpp | 54 ++++++++++++++----- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/properties.cpp b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/properties.cpp index 268f14e567c7f4..e2ca8e79edaf10 100644 --- a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/properties.cpp +++ b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/properties.cpp @@ -83,6 +83,12 @@ INSTANTIATE_TEST_SUITE_P(ov_plugin_mandatory, OVCheckChangePropComplieModleGetPr ::testing::Values(ov::AnyMap({}))), OVCheckChangePropComplieModleGetPropTests_DEVICE_ID::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(ov_plugin_mandatory, OVCheckChangePropComplieModleGetPropTests_InferencePrecision, + ::testing::Combine( + ::testing::ValuesIn(return_all_possible_device_combination()), + ::testing::Values(ov::AnyMap({}))), + OVCheckChangePropComplieModleGetPropTests_InferencePrecision::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(ov_plugin, OVCheckMetricsPropsTests_ModelDependceProps, ::testing::Combine( ::testing::ValuesIn(return_all_possible_device_combination()), diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp index 45f9125abe683f..edfcc5920b07a0 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/properties_tests.hpp @@ -80,6 +80,7 @@ class OVPropertiesTestsWithCompileModelProps : public testing::WithParamInterfac using OVCheckSetSupportedRWMetricsPropsTests = OVPropertiesTestsWithCompileModelProps; using OVCheckGetSupportedROMetricsPropsTests = OVPropertiesTestsWithCompileModelProps; using OVCheckChangePropComplieModleGetPropTests_DEVICE_ID = OVPropertiesTestsWithCompileModelProps; +using OVCheckChangePropComplieModleGetPropTests_InferencePrecision = OVPropertiesTestsWithCompileModelProps; using OVCheckMetricsPropsTests_ModelDependceProps = OVPropertiesTestsWithCompileModelProps; class OVClassSetDefaultDeviceIDPropTest : public OVPluginTestBase, diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp index 349016b3fd0bed..ac66fea4559951 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp @@ -240,18 +240,6 @@ std::vector OVPropertiesTestsWithCompileModelProps::configurePropert std::vector OVPropertiesTestsWithCompileModelProps::getRWMandatoryPropertiesValues(std::vector props) { std::vector res; - if (props.empty() || std::find(props.begin(), props.end(), ov::hint::inference_precision.name()) != props.end()) { - const std::vector ovElemTypes = { - ov::element::f64, ov::element::f32, ov::element::f16, ov::element::bf16, - ov::element::i64, ov::element::i32, ov::element::i16, ov::element::i8, ov::element::i4, - ov::element::u64, ov::element::u32, ov::element::u16, ov::element::u8, ov::element::u4, ov::element::u1, - ov::element::boolean, ov::element::undefined, ov::element::dynamic - }; - for (auto &precision : ovElemTypes) { - res.push_back({{ov::hint::inference_precision(precision)}}); - } - } - if (props.empty() || std::find(props.begin(), props.end(), ov::hint::performance_mode.name()) != props.end()) { ov::hint::PerformanceMode performance_modes[] = {ov::hint::PerformanceMode::LATENCY, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT}; @@ -401,6 +389,48 @@ TEST_P(OVCheckChangePropComplieModleGetPropTests_DEVICE_ID, ChangeCorrectDeviceP } } +TEST_P(OVCheckChangePropComplieModleGetPropTests_InferencePrecision, ChangeCorrectProperties) { + std::vector supported_properties; + OV_ASSERT_NO_THROW(supported_properties = core->get_property(target_device, ov::supported_properties)); + auto supported = util::contains(supported_properties, ov::hint::inference_precision); + ASSERT_TRUE(supported) << "property is not supported: " << ov::hint::inference_precision; + + ov::Any default_property; + OV_ASSERT_NO_THROW(default_property = core->get_property(target_device, ov::hint::inference_precision)); + ASSERT_FALSE(default_property.empty()); + + const std::vector ovElemTypes = { + ov::element::f64, ov::element::f32, ov::element::f16, ov::element::bf16, + ov::element::i64, ov::element::i32, ov::element::i16, ov::element::i8, ov::element::i4, + ov::element::u64, ov::element::u32, ov::element::u16, ov::element::u8, ov::element::u4, ov::element::u1, + ov::element::boolean, ov::element::undefined, ov::element::dynamic + }; + + bool any_supported = false; + for (ov::element::Type type : ovElemTypes) { + try { + core->set_property(target_device, ov::hint::inference_precision(type)); + core->compile_model(model, target_device, compileModelProperties); + } catch (const Exception& ex) { + std::string err_msg(ex.what()); + ASSERT_TRUE(err_msg.find("Unsupported precision") != std::string::npos) << + "Fail to set and compile_model with precision: " << type << std::endl; + continue; + } + + ov::Any actual_property_value; + OV_ASSERT_NO_THROW(actual_property_value = core->get_property(target_device, ov::hint::inference_precision)); + ASSERT_FALSE(actual_property_value.empty()); + + ov::element::Type actual_value = actual_property_value.as(); + ASSERT_EQ(actual_value, type) << "Peoperty is changed in wrong way"; + + std::cout << "Supported precision: " << type << std::endl; + any_supported = true; + } + ASSERT_TRUE(any_supported) << "No one supported precision is found"; +} + std::vector OVPropertiesTestsWithCompileModelProps::getModelDependcePropertiesValues() { std::vector res; // Read Only From 39f6cbf259ada7e3a6858dfc48de9bafba108a28 Mon Sep 17 00:00:00 2001 From: Mahimai Raja J Date: Mon, 25 Sep 2023 18:02:22 +0530 Subject: [PATCH 40/43] Refactored with single dispatch generic function implementation (#19958) * Refactored with single dispatch generic function implementation * Resolved mypy linting warnings * Update src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py * Update src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py --------- Co-authored-by: Przemyslaw Wysocki --- .../torchvision/torchvision_preprocessing.py | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py b/src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py index 60fef4d22b9d8b..503984ee67a671 100644 --- a/src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py +++ b/src/bindings/python/src/openvino/preprocess/torchvision/torchvision_preprocessing.py @@ -10,6 +10,7 @@ import numpy as np from typing import List, Dict from abc import ABCMeta, abstractmethod +from functools import singledispatch from typing import Callable, Any, Union, Tuple from typing import Sequence as SequenceType from collections.abc import Sequence @@ -46,15 +47,22 @@ } +@singledispatch def _setup_size(size: Any, error_msg: str) -> SequenceType[int]: - # TODO: refactor into @singledispatch once Python 3.7 support is dropped - if isinstance(size, numbers.Number): - return int(size), int(size) # type: ignore - if isinstance(size, Sequence): - if len(size) == 1: - return size[0], size[0] - elif len(size) == 2: - return size + raise ValueError(error_msg) + + +@_setup_size.register +def _setup_size_number(size: numbers.Number, error_msg: str) -> SequenceType[int]: + return int(size), int(size) # type: ignore + + +@_setup_size.register +def _setup_size_sequence(size: Sequence, error_msg: str) -> SequenceType[int]: + if len(size) == 1: + return size[0], size[0] + elif len(size) == 2: + return size raise ValueError(error_msg) @@ -66,14 +74,19 @@ def _NHWC_to_NCHW(input_shape: List) -> List: # noqa N802 return new_shape +@singledispatch def _to_list(transform: Callable) -> List: - # TODO: refactor into @singledispatch once Python 3.7 support is dropped - if isinstance(transform, torch.nn.Sequential): - return list(transform) - elif isinstance(transform, transforms.Compose): - return transform.transforms - else: - raise TypeError(f"Unsupported transform type: {type(transform)}") + raise TypeError(f"Unsupported transform type: {type(transform)}") + + +@_to_list.register +def _to_list_torch_sequential(transform: torch.nn.Sequential) -> List: + return list(transform) + + +@_to_list.register +def _to_list_transforms_compose(transform: transforms.Compose) -> List: + return transform.transforms def _get_shape_layout_from_data(input_example: Union[torch.Tensor, np.ndarray, Image.Image]) -> Tuple[List, Layout]: From 6d3f94762edd18e139ec4ad5ec79a39540eeba62 Mon Sep 17 00:00:00 2001 From: Andrey Kashchikhin Date: Mon, 25 Sep 2023 13:44:14 +0100 Subject: [PATCH 41/43] fix (#20037) --- .github/workflows/mo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mo.yml b/.github/workflows/mo.yml index edb2b222e894da..69be4df6bf8fbc 100644 --- a/.github/workflows/mo.yml +++ b/.github/workflows/mo.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Clone OpenVINO - - uses: actions/checkout@v4 + uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 From 85145cd60c81d0015b4811c21454cbe1e1219226 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Mon, 25 Sep 2023 17:00:30 +0400 Subject: [PATCH 42/43] Refactored Linix GHA pipeline (#20021) * Refactored Linix GHA pipeline * Move ONNX tests to Unit * Install tests together with openvino * Added checks for GNA usage in docs python snippets * Install openssl for working pip * Disabled onnx_dyn_shapes_expand_1_dyn_shape ONNX test * exclude dyn shapes from onnx * Migrated samples tests * Fixed ONNX tests * caches for PT tests dependencies * Build Contrib separately from main OpenVINO * More fixes * Added python install for samples stage * Installed manifests for ONNX FE tests * Try to avoid libgl1 dependency in tests * Clean-up * Fixed issue with manifests in ONNX tests --- .github/workflows/linux.yml | 441 ++++++++---------- .github/workflows/linux_debian.yml | 2 +- CMakeLists.txt | 10 +- cmake/test_model_zoo.cmake | 12 +- docs/snippets/gna/configure.py | 21 +- docs/snippets/gna/import_export.py | 32 +- docs/snippets/gna/set_batch.py | 37 +- docs/snippets/ov_caching.py | 2 +- src/frontends/onnx/tests/CMakeLists.txt | 28 +- src/frontends/onnx/tests/onnx_editor.cpp | 2 +- .../tests/onnx_editor_topological_sort.cpp | 2 +- src/frontends/onnx/tests/onnx_import.in.cpp | 2 +- .../tests/onnx_import_com_microsoft.in.cpp | 2 +- .../tests/onnx_import_const_folding.in.cpp | 2 +- .../onnx/tests/onnx_import_controlflow.in.cpp | 2 +- .../onnx/tests/onnx_import_convpool.in.cpp | 2 +- .../onnx/tests/onnx_import_deprecated.in.cpp | 2 +- .../onnx/tests/onnx_import_dyn_shapes.in.cpp | 2 +- .../onnx/tests/onnx_import_library.cpp | 4 +- .../tests/onnx_import_org_openvino.in.cpp | 2 +- .../onnx/tests/onnx_import_org_pytorch.in.cpp | 2 +- .../onnx/tests/onnx_import_quant.in.cpp | 2 +- .../onnx/tests/onnx_import_reshape.in.cpp | 2 +- .../onnx/tests/onnx_import_rnn.in.cpp | 2 +- .../onnx/tests/onnx_import_signal.in.cpp | 2 +- .../onnx/tests/onnx_import_with_editor.in.cpp | 2 +- .../onnx/tests/onnx_ops_registration.cpp | 2 +- .../onnx/tests/onnx_tensor_names.cpp | 2 +- .../onnx/tests/onnx_test_utils.in.cpp | 2 +- .../onnx/tests/onnx_transformations.cpp | 2 +- .../shared/gtest_main_manifest/main.cpp | 11 +- tests/CMakeLists.txt | 7 + .../smoke_tests/requirements.txt | 2 +- 33 files changed, 326 insertions(+), 323 deletions(-) create mode 100644 tests/CMakeLists.txt diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index b3d4bbb764c200..7443e66166a901 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -40,20 +40,16 @@ jobs: env: DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input CMAKE_BUILD_TYPE: 'Release' - CMAKE_GENERATOR: 'Ninja' + CMAKE_GENERATOR: 'Ninja Multi-Config' CMAKE_CXX_COMPILER_LAUNCHER: ccache CMAKE_C_COMPILER_LAUNCHER: ccache GITHUB_WORKSPACE: '/__w/openvino/openvino' OPENVINO_REPO: /__w/openvino/openvino/openvino OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib - INSTALL_DIR: /__w/openvino/openvino/install - INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests - SAMPLES_INSTALL_DIR: /__w/openvino/openvino/install/samples - LAYER_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/layer_tests - MODEL_HUB_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/model_hub_tests - BUILD_DIR: /__w/openvino/openvino/build - OV_TEMP: /__w/openvino/openvino/openvino_temp - PYTHON_STATIC_ARGS: -m "not dynamic_library" + INSTALL_DIR: /__w/openvino/openvino/openvino_install + INSTALL_TEST_DIR: /__w/openvino/openvino/tests_install + BUILD_DIR: /__w/openvino/openvino/openvino_build + OPENVINO_CONTRIB_BUILD_DIR: /__w/openvino/openvino/openvino_contrib_build CCACHE_DIR: /mount/caches/ccache/ubuntu20_x86_64_Release CCACHE_TEMPDIR: /__w/openvino/openvino/ccache_temp CCACHE_MAXSIZE: 50G @@ -61,7 +57,7 @@ jobs: - name: Install git run: | apt-get update - apt-get install -y git git-lfs + apt-get install --assume-yes --no-install-recommends git ca-certificates - name: Clone OpenVINO uses: actions/checkout@v4 @@ -83,10 +79,12 @@ jobs: - name: Install build dependencies run: | bash ${OPENVINO_REPO}/install_build_dependencies.sh - apt update - apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers + # openjdk-11-jdk - Java API + # libssl1.1 - 'python3 -m pip' in self-hosted runner + # unzip - to download ninja + apt install --assume-yes --no-install-recommends openjdk-11-jdk libssl1.1 unzip - wget https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip + wget https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip unzip ninja-linux.zip cp -v ninja /usr/local/bin/ @@ -96,14 +94,9 @@ jobs: - name: Install python dependencies run: | - # For Python API - python3 -m pip install --upgrade pip - python3 -m pip install Scons + # For Python API: build and wheel packaging python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements.txt - python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements_test.txt - - # For running Python API tests python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt # For running ONNX frontend unit tests @@ -112,18 +105,12 @@ jobs: # For running TensorFlow frontend unit tests python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow/tests/requirements.txt + # For running TensorFlow Lite frontend unit tests + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow_lite/tests/requirements.txt + # For running Paddle frontend unit tests python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt - - name: Install MO dependencies - run: | - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt - # # Build # @@ -132,99 +119,157 @@ jobs: run: | mkdir -p $CCACHE_DIR - - name: Get number of CPU cores - uses: SimenB/github-actions-cpu-cores@v2 - id: cpu-cores - - - name: CMake configure + - name: CMake configure - OpenVINO run: | cmake \ - -GNinja \ + -G "${{ env.CMAKE_GENERATOR }}" \ -DENABLE_CPPLINT=OFF \ -DENABLE_NCC_STYLE=OFF \ -DENABLE_TESTS=ON \ - -DENABLE_PYTHON=ON \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=ON \ - -DENABLE_ONEDNN_FOR_GPU=OFF \ - -DENABLE_OV_ONNX_FRONTEND=ON \ - -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \ -DENABLE_STRICT_DEPENDENCIES=OFF \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DENABLE_SYSTEM_SNAPPY=ON \ -DENABLE_SYSTEM_TBB=ON \ + -DENABLE_SYSTEM_OPENCL=ON \ + -DENABLE_SYSTEM_PUGIXML=ON \ -DBUILD_nvidia_plugin=OFF \ - -DENABLE_DEBUG_CAPS=ON \ -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" \ -DOPENVINO_EXTRA_MODULES=${OPENVINO_CONTRIB_REPO}/modules \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ + -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CMAKE_CXX_COMPILER_LAUNCHER }} \ + -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CMAKE_C_COMPILER_LAUNCHER }} \ -S ${OPENVINO_REPO} \ -B ${BUILD_DIR} - name: Clean ccache stats run: ccache --zero-stats --show-config - - name: Build - run: cmake --build ${BUILD_DIR} --parallel ${{ steps.cpu-cores.outputs.count }} --config Release + - name: Cmake build - OpenVINO + run: cmake --build ${BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} - - name: Show ccache stats - run: ccache --show-stats + - name: Cmake & Build - OpenVINO Contrib + if: ${{ 'false' }} + run: | + cmake \ + -G "${{ env.CMAKE_GENERATOR }}" \ + -DBUILD_nvidia_plugin=OFF \ + -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" \ + -DOpenVINODeveloperPackage_DIR=${BUILD_DIR} \ + -S ${OPENVINO_CONTRIB_REPO}/modules \ + -B ${OPENVINO_CONTRIB_BUILD_DIR} - - name: Cmake Layer Tests - run: cmake -GNinja -S ${OPENVINO_REPO}/tests/layer_tests -B ${BUILD_DIR}/layer_tests + cmake --build ${OPENVINO_CONTRIB_BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} - - name: Cmake Model Hub Tests - run: cmake -GNinja -S ${OPENVINO_REPO}/tests/model_hub_tests -B ${BUILD_DIR}/model_hub_tests + - name: Show ccache stats + run: ccache --show-stats - - name: Build Layer Tests - run: cmake --build ${BUILD_DIR}/layer_tests --parallel --config Release + - name: Cmake install - OpenVINO + run: | + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} -DCOMPONENT=tests -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DCOMPONENT=python_wheels -P ${BUILD_DIR}/cmake_install.cmake - - name: Build Model Hub Tests - run: cmake --build ${BUILD_DIR}/model_hub_tests --parallel --config Release + - name: Pack Artifacts + run: | + pushd ${INSTALL_DIR} + tar -czvf ${BUILD_DIR}/openvino_package.tar.gz * + popd - - name: Install wheel packages - run: cmake -DCOMPONENT=python_wheels -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake + pushd ${INSTALL_TEST_DIR} + tar -czvf ${BUILD_DIR}/openvino_tests.tar.gz * + popd - - name: Install Layer Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/layer_tests/cmake_install.cmake + # + # Upload build artifacts + # - - name: Install Model Hub Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/model_hub_tests/cmake_install.cmake + - name: Upload openvino package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_package + path: ${{ env.BUILD_DIR }}/openvino_package.tar.gz + if-no-files-found: 'error' - - name: Install python wheels - run: python3 -m pip install openvino-dev --find-links=${INSTALL_DIR}/tools + - name: Upload openvino tests package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_tests + path: ${{ env.BUILD_DIR }}/openvino_tests.tar.gz + if-no-files-found: 'error' - - name: Install tests - run: cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DCOMPONENT=tests -P ${BUILD_DIR}/cmake_install.cmake + Samples: + needs: Build + defaults: + run: + shell: bash + runs-on: ubuntu-20.04 + container: + image: ubuntu:20.04 + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + BUILD_DIR: /__w/openvino/openvino/build - - name: Install OpenVINO - run: cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake + steps: + - name: Create Directories + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} - - name: CMake Samples Tests - run: cmake -GNinja -S ${OPENVINO_REPO}/tests/samples_tests -B ${BUILD_DIR}/samples_tests + # + # Initialize OpenVINO + # - - name: Build Samples Tests - run: cmake --build ${BUILD_DIR}/samples_tests --config Release + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} - - name: Install Samples Tests - run: cmake -DCOMPONENT=tests -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/samples_tests/cmake_install.cmake + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} - - name: Pack Artifacts + - name: Extract OpenVINO packages run: | pushd ${INSTALL_DIR} - tar -czvf ${BUILD_DIR}/openvino_package.tar.gz --exclude=tests * + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} && rm openvino_package.tar.gz || exit 1 popd - - pushd ${INSTALL_DIR} - tar -czvf ${BUILD_DIR}/openvino_tests.tar.gz tests/ + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd - - name: Build cpp samples - run: ${SAMPLES_INSTALL_DIR}/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples + - name: Install 'actions/setup-python@v4' dependencies + run: apt-get update && apt-get install -y libssl1.1 + + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install OpenVINO dependencies + run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y + + - name: Build cpp samples - GCC + run: ${INSTALL_DIR}/samples/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + + - name: Build cpp samples - Clang + run: | + apt-get install -y clang + ${INSTALL_DIR}/samples/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples_clang + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + CC: clang + CXX: clang++ - name: Build c samples - run: ${SAMPLES_INSTALL_DIR}/c/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/c_samples + run: ${INSTALL_DIR}/samples/c/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/c_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' # # Tests @@ -246,31 +291,12 @@ jobs: --env_conf ${INSTALL_TEST_DIR}/smoke_tests/env_config.yml \ --junitxml=${INSTALL_TEST_DIR}/TEST-SamplesSmokeTests.xml - # Present in the "Build" job due to the fact that these tests require build directory - - name: ONNX frontend tests - run: | - source ${INSTALL_DIR}/setupvars.sh - ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ - --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml - - # - # Upload build artifacts - # - - - name: Upload openvino package - if: ${{ always() }} + - name: Upload Test Results uses: actions/upload-artifact@v3 - with: - name: openvino_package - path: ${{ env.BUILD_DIR }}/openvino_package.tar.gz - if-no-files-found: 'error' - - - name: Upload openvino tests package if: ${{ always() }} - uses: actions/upload-artifact@v3 with: - name: openvino_tests - path: ${{ env.BUILD_DIR }}/openvino_tests.tar.gz + name: test-results-cpp + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml if-no-files-found: 'error' CXX_Unit_Tests: @@ -281,27 +307,18 @@ jobs: runs-on: aks-linux-4-cores container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 - volumes: - - /mount/caches:/mount/caches env: - DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input INSTALL_DIR: /__w/openvino/openvino/install INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests steps: - name: Create Directories - run: | - mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} # - # Dependencies + # Initialize OpenVINO # - - name: Install dependencies - run: | - apt update - apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - - name: Download OpenVINO package uses: actions/download-artifact@v3 with: @@ -323,6 +340,9 @@ jobs: tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd + - name: Install OpenVINO dependencies + run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=gpu -y + # # Tests # @@ -370,14 +390,14 @@ jobs: # ${INSTALL_TEST_DIR}/paddle_tests --gtest_print_time=1 --gtest_filter=*smoke* \ # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-PaddleTests.xml - # Present in the "Build" job as these tests require build directory - # - name: ONNX frontend tests - # run: | - # source ${INSTALL_DIR}/setupvars.sh - # ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ - # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml + - name: ONNX frontend tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 \ + --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml - - name: TensorFlow Common tests + - name: TensorFlow Common frontend tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_tensorflow_common_tests --gtest_print_time=1 \ @@ -395,7 +415,7 @@ jobs: ${INSTALL_TEST_DIR}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowLiteFrontend.xml - - name: Transformations Tests + - name: Transformations func tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_transformations_tests --gtest_print_time=1 \ @@ -419,20 +439,13 @@ jobs: ${INSTALL_TEST_DIR}/ov_cpu_unit_tests --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CPUUnitTests.xml - # Disabled in Azure: https://github.com/openvinotoolkit/openvino/blob/master/.ci/azure/linux.yml#L409 - # - name: GNA plugin unit tests - # run: | - # source ${INSTALL_DIR}/setupvars.sh - # ${INSTALL_TEST_DIR}/ov_gna_unit_tests --gtest_print_time=1 \ - # --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-GNAUnitTests.xml - - - name: AUTO UT + - name: AUTO unit tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_auto_unit_tests --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_unit_tests.xml - - name: Template plugin tests + - name: Template plugin func tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_template_func_tests --gtest_print_time=1 \ @@ -451,22 +464,22 @@ jobs: ${INSTALL_TEST_DIR}/ov_capi_test --gtest_print_time=1 \ --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OpenVINOCAPITests.xml - - name: AutoBatch FuncTests + - name: AutoBatch func tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_auto_batch_func_tests --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_batch_func_tests.xml - - name: Proxy Plugin Tests + - name: Proxy Plugin func tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVProxyTests.xml - - name: Hetero Unit Tests + - name: Hetero unit tests run: | source ${{ env.INSTALL_DIR }}/setupvars.sh ${{ env.INSTALL_TEST_DIR }}/ov_hetero_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVHeteroUnitTests.xml - - name: Hetero Func Tests + - name: Hetero func tests run: | source ${INSTALL_DIR}/setupvars.sh ${INSTALL_TEST_DIR}/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVHeteroFuncTests.xml @@ -487,29 +500,20 @@ jobs: runs-on: aks-linux-4-cores container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 - volumes: - - /mount/caches:/mount/caches env: - DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input OPENVINO_REPO: /__w/openvino/openvino/openvino - OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib INSTALL_DIR: /__w/openvino/openvino/install INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests - SAMPLES_INSTALL_DIR: /__w/openvino/openvino/install/samples LAYER_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/layer_tests - MODEL_HUB_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/model_hub_tests - OV_TEMP: /__w/openvino/openvino/openvino_temp - PYTHON_STATIC_ARGS: -m "not dynamic_library" steps: - name: Create Directories - run: | - mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} + run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} - name: Install git run: | apt update - apt --assume-yes install git git-lfs + apt install --assume-yes --no-install-recommends git ca-certificates - name: Clone OpenVINO uses: actions/checkout@v4 @@ -517,47 +521,19 @@ jobs: path: 'openvino' # - # Dependencies + # Initilaize OpenVINO # - - name: Install dependencies - run: | - apt update - apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - - uses: actions/setup-python@v4 with: python-version: '3.11' - - name: Install python dependencies + - name: Install Python API tests dependencies run: | - # For Python API - python3 -m pip install --upgrade pip - python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt - python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/requirements.txt - - # For running Python API tests - python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt - - # For running ONNX frontend unit tests - python3 -m pip install --force-reinstall -r ${OPENVINO_REPO}/src/frontends/onnx/tests/requirements.txt - - # For running TensorFlow frontend unit tests - python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow/tests/requirements.txt - - # For running Paddle frontend unit tests - python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt - # For torchvision to OpenVINO preprocessing converter python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/openvino/preprocess/torchvision/requirements.txt - - name: Install MO dependencies - run: | - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt + # TODO: replace with Python API tests requirements python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt - name: Download OpenVINO package @@ -582,53 +558,46 @@ jobs: tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd - - name: Install Python wheels - run: | - python3 -m pip install openvino-dev --find-links=${INSTALL_DIR}/tools + - name: Install OpenVINO Python wheels + run: python3 -m pip install openvino-dev[mxnet,caffe,kaldi,onnx,tensorflow2] --find-links=${INSTALL_DIR}/tools + + # + # Tests + # - name: nGraph and IE Python Bindings Tests run: | - source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest -s ${INSTALL_TEST_DIR}/pyngraph ${{ env.PYTHON_STATIC_ARGS }} \ + python3 -m pytest -s ${INSTALL_TEST_DIR}/pyngraph \ --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ --ignore=${INSTALL_TEST_DIR}/pyngraph/tests/test_onnx/test_zoo_models.py \ --ignore=${INSTALL_TEST_DIR}/pyngraph/tests/test_onnx/test_backend.py - name: Python API 2.0 Tests run: | - # For python imports to import pybind_mock_frontend + # For python imports to import 'pybind_mock_frontend' export PYTHONPATH=${INSTALL_TEST_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh + # for 'template' extension export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH - python3 -m pytest -sv ${INSTALL_TEST_DIR}/pyopenvino ${{ env.PYTHON_STATIC_ARGS }} \ + python3 -m pytest -sv ${INSTALL_TEST_DIR}/pyopenvino \ --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_utils/test_utils.py \ --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_onnx/test_zoo_models.py \ --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_onnx/test_backend.py - - name: Python API snippets + - name: Docs Python snippets run: | - source ${INSTALL_DIR}/setupvars.sh - export PYTHONPATH=${INSTALL_TEST_DIR}:${OPENVINO_REPO}/docs/:$PYTHONPATH + # to find 'snippets' module in docs + export PYTHONPATH=${OPENVINO_REPO}/docs/:$PYTHONPATH + # for 'template' extension export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH - python3 ${OPENVINO_REPO}/docs/snippets/main.py - - name: Model Optimizer UT + - name: Model Optimizer unit tests run: | - - export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:${INSTALL_TEST_DIR}:${INSTALL_DIR}/python/python3.11:$PYTHONPATH - - # TODO: figure out why they need to be reinstalled - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_mxnet.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_caffe.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_kaldi.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_onnx.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_tf2.txt - python3 -m pip install -r ${OPENVINO_REPO}/tools/mo/requirements_dev.txt - - source ${INSTALL_DIR}/setupvars.sh + export PYTHONPATH=${INSTALL_TEST_DIR}:$PYTHONPATH + # required for MxNet + apt-get install -y libgomp1 libquadmath0 python3 -m pytest -s ${INSTALL_TEST_DIR}/mo/unit_tests \ --junitxml=${INSTALL_TEST_DIR}/TEST-ModelOptimizer.xml @@ -636,8 +605,7 @@ jobs: - name: PyTorch Layer Tests run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt - export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh + export PYTHONPATH=${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml env: @@ -647,11 +615,8 @@ jobs: - name: TensorFlow 1 Layer Tests - TF FE run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt - export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf_fe.xml env: TEST_DEVICE: CPU @@ -662,8 +627,6 @@ jobs: python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml env: TEST_DEVICE: CPU @@ -674,8 +637,6 @@ jobs: python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh - python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/jax_tests/ -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-jax.xml env: TEST_DEVICE: CPU @@ -684,7 +645,6 @@ jobs: run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${INSTALL_TEST_DIR}/TEST-tf_Roll.xml @@ -692,7 +652,6 @@ jobs: run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/test_tf2_keras_activation.py \ --ir_version=11 --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_Activation.xml -k "sigmoid" @@ -704,7 +663,6 @@ jobs: run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_lite_tests/ --junitxml=${INSTALL_TEST_DIR}/TEST-tfl_fe.xml env: @@ -714,8 +672,10 @@ jobs: - name: MO Python API Tests run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt - export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + export PYTHONPATH=${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + # TODO: remove setupvars.sh from here; currently, it's used for 'test_utils' installed in '/python/openvino' source ${INSTALL_DIR}/setupvars.sh + bash ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -y python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/mo_python_api_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_mo_convert.xml env: @@ -726,15 +686,15 @@ jobs: run: | python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt export PYTHONPATH=${OPENVINO_REPO}/tools/mo/:${LAYER_TESTS_INSTALL_DIR}:$PYTHONPATH + # to allow 'libtest_builtin_extensions.so' to find 'libopenvino_onnx_frontend.so' source ${INSTALL_DIR}/setupvars.sh python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/py_frontend_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_py_fontend.xml - - name: Conversion UT + - name: OVC unit tests run: | - # For python imports to import pybind_mock_frontend + # For python imports to import 'pybind_mock_frontend' export PYTHONPATH=${INSTALL_TEST_DIR}:$PYTHONPATH - source ${INSTALL_DIR}/setupvars.sh python3 -m pytest -s ${OPENVINO_REPO}/tools/ovc/unit_tests --junitxml=${INSTALL_TEST_DIR}/TEST-OpenVinoConversion.xml @@ -756,10 +716,7 @@ jobs: runs-on: aks-linux-4-cores container: image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 - volumes: - - /mount/caches:/mount/caches env: - DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input INSTALL_DIR: /__w/openvino/openvino/install INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests PARALLEL_TEST_SCRIPT: /__w/openvino/openvino/install/tests/functional_test_utils/run_parallel.py @@ -769,11 +726,6 @@ jobs: - name: Create Directories run: mkdir -p ${INSTALL_DIR} ${INSTALL_TEST_DIR} - - name: Install dependencies - run: | - apt update - apt --assume-yes install openjdk-11-jdk libbz2-dev clang unzip libpugixml-dev libtbb-dev intel-opencl-icd ocl-icd-opencl-dev opencl-headers libsnappy-dev - - name: Download OpenVINO package uses: actions/download-artifact@v3 with: @@ -795,14 +747,18 @@ jobs: tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} && rm openvino_tests.tar.gz || exit 1 popd + - name: Install OpenVINO dependencies + run: bash ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -y + + - name: Install 'actions/setup-python@v4' dependencies + run: apt-get update && apt-get install -y libssl1.1 + - uses: actions/setup-python@v4 with: python-version: '3.11' - - name: Install python dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r ${INSTALL_TEST_DIR}/functional_test_utils/requirements.txt + - name: Install python dependencies for run_parallel.py + run: python3 -m pip install -r ${INSTALL_TEST_DIR}/functional_test_utils/requirements.txt - name: Restore tests execution time uses: actions/cache/restore@v3 @@ -852,8 +808,7 @@ jobs: steps: - name: Create Directories - run: | - mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} - uses: actions/setup-python@v4 with: @@ -881,16 +836,17 @@ jobs: tar -xzf openvino_tests.tar.gz -C ${{ env.INSTALL_DIR }} && rm openvino_tests.tar.gz || exit 1 popd - - name: Install Python wheels + - name: Install OpenVINO Python wheels run: | python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools - - name: TensorFlow Hub Tests - TF FE + - name: Install TF Hub tests requirements run: | python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/tf_hub_tests/requirements.txt + - name: TensorFlow Hub Tests - TF FE + run: | export PYTHONPATH=${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}:$PYTHONPATH - python3 -m pytest ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/tf_hub_tests/ -m ${{ env.TYPE }} --html=${{ env.INSTALL_TEST_DIR }}/TEST-tf_hub_tf_fe.html --self-contained-html env: TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} @@ -912,7 +868,6 @@ jobs: shell: bash runs-on: ${{ github.event_name == 'schedule' && 'ubuntu-20.04-8-cores' || 'ubuntu-20.04'}} env: - DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input INSTALL_DIR: ${{ github.workspace }}/install INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests @@ -925,9 +880,10 @@ jobs: sudo rm -rf /opt/ghc echo "Available storage:" df -h + - name: Create Directories - run: | - mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + run: mkdir -p ${{ env.INSTALL_DIR }} ${{ env.INSTALL_TEST_DIR }} + - uses: actions/setup-python@v4 with: python-version: '3.11' @@ -956,7 +912,7 @@ jobs: run: | python3 -m pip install openvino --find-links=${{ env.INSTALL_DIR }}/tools - - name: Install requirements + - name: Install PyTorch tests requirements run: | python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements.txt python3 -m pip install -r ${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}/torch_tests/requirements_secondary.txt @@ -964,6 +920,7 @@ jobs: echo "Available storage:" df -h du -h -d0 ~/.cache ~/* + - name: PyTorch Models Tests run: | export PYTHONPATH=${{ env.MODEL_HUB_TESTS_INSTALL_DIR }}:$PYTHONPATH @@ -973,7 +930,7 @@ jobs: TEST_DEVICE: CPU - name: Available storage after tests - run: | + run: | echo "Available storage:" df -h du -h -d0 ~/.cache ~/* diff --git a/.github/workflows/linux_debian.yml b/.github/workflows/linux_debian.yml index bff429be48c90a..85865962478304 100644 --- a/.github/workflows/linux_debian.yml +++ b/.github/workflows/linux_debian.yml @@ -263,7 +263,7 @@ jobs: - name: ONNX frontend tests run: | export LD_LIBRARY_PATH=${{ env.INSTALL_TEST_DIR }}:$LD_LIBRARY_PATH - ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU*:*FrontEndLoadFromTest.testLoadFromTwoStreams*:*FrontEndLoadFromTest.testLoadFromTwoFiles* \ + ${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml - name: TensorFlow frontend tests diff --git a/CMakeLists.txt b/CMakeLists.txt index e9d4760eb86916..b69df0194f186b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ function(openvino_developer_export_targets) endfunction() # add target with processed tests model zoo -if (ENABLE_TESTS) +if(ENABLE_TESTS) include(cmake/test_model_zoo.cmake) endif() @@ -135,15 +135,21 @@ if(ENABLE_SAMPLES OR ENABLE_TESTS) endif() # Enable interpreter backend for tests -if (ENABLE_TESTS OR ENABLE_TEMPLATE) +if(ENABLE_TESTS OR ENABLE_TEMPLATE) add_subdirectory(src/plugins/template/backend) endif() + include(cmake/extra_modules.cmake) add_subdirectory(docs) add_subdirectory(tools) add_subdirectory(scripts) add_subdirectory(licensing) +if(ENABLE_TESTS) + # layers and other more high-level / e2e tests + add_subdirectory(tests) +endif() + # # CPack # diff --git a/cmake/test_model_zoo.cmake b/cmake/test_model_zoo.cmake index 9a786ed069792f..ee6cd463fd764a 100644 --- a/cmake/test_model_zoo.cmake +++ b/cmake/test_model_zoo.cmake @@ -72,23 +72,23 @@ function(ov_model_convert SRC DST OUT) endfunction() if(OV_GENERATOR_MULTI_CONFIG AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20) - set(test_model_zoo_output_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/test_model_zoo") + set(TEST_MODEL_ZOO_OUTPUT_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/test_model_zoo" CACHE PATH "") else() - set(test_model_zoo_output_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_model_zoo") + set(TEST_MODEL_ZOO_OUTPUT_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_model_zoo" CACHE PATH "") endif() ov_model_convert("${CMAKE_CURRENT_SOURCE_DIR}/src/core/tests" - "${test_model_zoo_output_dir}/core" + "${TEST_MODEL_ZOO_OUTPUT_DIR}/core" core_tests_out_files) set(rel_path "src/tests/functional/plugin/shared/models") ov_model_convert("${OpenVINO_SOURCE_DIR}/${rel_path}" - "${test_model_zoo_output_dir}/func_tests/models" + "${TEST_MODEL_ZOO_OUTPUT_DIR}/func_tests/models" ft_out_files) set(rel_path "src/frontends/onnx/tests/models") ov_model_convert("${OpenVINO_SOURCE_DIR}/${rel_path}" - "${test_model_zoo_output_dir}/onnx" + "${TEST_MODEL_ZOO_OUTPUT_DIR}/onnx" onnx_fe_out_files) if(ENABLE_TESTS) @@ -101,7 +101,7 @@ if(ENABLE_TESTS) # add_dependencies(test_model_zoo paddle_test_models) #endif() - install(DIRECTORY "${test_model_zoo_output_dir}" + install(DIRECTORY "${TEST_MODEL_ZOO_OUTPUT_DIR}" DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) set(TEST_MODEL_ZOO "./test_model_zoo" CACHE PATH "Path to test model zoo") diff --git a/docs/snippets/gna/configure.py b/docs/snippets/gna/configure.py index ec94a54ae4110c..7f989a213fe099 100644 --- a/docs/snippets/gna/configure.py +++ b/docs/snippets/gna/configure.py @@ -7,12 +7,17 @@ from snippets import get_model -model = get_model() +def main(): + model = get_model() -# TODO: no GNA properties to replace strings -#! [ov_gna_exec_mode_hw_with_sw_fback] -core = ov.Core() -compiled_model = core.compile_model( - model, device_name="GNA", config={"GNA_DEVICE_MODE": "GNA_HW_WITH_SW_FBACK"} -) -#! [ov_gna_exec_mode_hw_with_sw_fback] + core = ov.Core() + if "GNA" not in core.available_devices: + return 0 + + # TODO: no GNA properties to replace strings + #! [ov_gna_exec_mode_hw_with_sw_fback] + core = ov.Core() + compiled_model = core.compile_model( + model, device_name="GNA", config={"GNA_DEVICE_MODE": "GNA_HW_WITH_SW_FBACK"} + ) + #! [ov_gna_exec_mode_hw_with_sw_fback] diff --git a/docs/snippets/gna/import_export.py b/docs/snippets/gna/import_export.py index 8aa6cd11267679..971e71ee5a7674 100644 --- a/docs/snippets/gna/import_export.py +++ b/docs/snippets/gna/import_export.py @@ -8,20 +8,24 @@ from snippets import get_model -model = get_model() -blob_path = "compiled_model.blob" +def main(): + model = get_model() + blob_path = "compiled_model.blob" -core = ov.Core() -compiled_model = core.compile_model(model, device_name="GNA") + core = ov.Core() + if "GNA" not in core.available_devices: + return 0 -#! [ov_gna_export] -user_stream = compiled_model.export_model() -with open(blob_path, "wb") as f: - f.write(user_stream) -#! [ov_gna_export] + compiled_model = core.compile_model(model, device_name="GNA") -# [ov_gna_import] -with open(blob_path, "rb") as f: - buf = BytesIO(f.read()) - compiled_model = core.import_model(buf, device_name="GNA") -# [ov_gna_import] + #! [ov_gna_export] + user_stream = compiled_model.export_model() + with open(blob_path, "wb") as f: + f.write(user_stream) + #! [ov_gna_export] + + # [ov_gna_import] + with open(blob_path, "rb") as f: + buf = BytesIO(f.read()) + compiled_model = core.import_model(buf, device_name="GNA") + # [ov_gna_import] diff --git a/docs/snippets/gna/set_batch.py b/docs/snippets/gna/set_batch.py index fac783923ca4e7..bd12991ce11994 100644 --- a/docs/snippets/gna/set_batch.py +++ b/docs/snippets/gna/set_batch.py @@ -7,22 +7,27 @@ from snippets import get_path_to_model -batch_size = 8 -model_path = get_path_to_model([1, 32]) +def main(): + batch_size = 8 + model_path = get_path_to_model([1, 32]) -#! [ov_gna_read_model] -core = ov.Core() -model = core.read_model(model=model_path) -#! [ov_gna_read_model] + core = ov.Core() + if "GNA" not in core.available_devices: + return 0 -#! [ov_gna_set_nc_layout] -ppp = ov.preprocess.PrePostProcessor(model) -for i in range(len(model.inputs)): - input_name = model.input(i).get_any_name() - ppp.input(i).model().set_layout("N?") -model = ppp.build() -#! [ov_gna_set_nc_layout] + #! [ov_gna_read_model] + core = ov.Core() + model = core.read_model(model=model_path) + #! [ov_gna_read_model] -#! [ov_gna_set_batch_size] -ov.set_batch(model, batch_size) -#! [ov_gna_set_batch_size] + #! [ov_gna_set_nc_layout] + ppp = ov.preprocess.PrePostProcessor(model) + for i in range(len(model.inputs)): + input_name = model.input(i).get_any_name() + ppp.input(i).model().set_layout("N?") + model = ppp.build() + #! [ov_gna_set_nc_layout] + + #! [ov_gna_set_batch_size] + ov.set_batch(model, batch_size) + #! [ov_gna_set_batch_size] diff --git a/docs/snippets/ov_caching.py b/docs/snippets/ov_caching.py index 87d9907a8b9106..a30ec968e7d2cf 100644 --- a/docs/snippets/ov_caching.py +++ b/docs/snippets/ov_caching.py @@ -7,7 +7,7 @@ import openvino.properties as props -device_name = 'GNA' +device_name = 'CPU' model_path = get_path_to_model() path_to_cache_dir = get_temp_dir() # ! [ov:caching:part0] diff --git a/src/frontends/onnx/tests/CMakeLists.txt b/src/frontends/onnx/tests/CMakeLists.txt index 5337060c29077c..3a971373d612e1 100644 --- a/src/frontends/onnx/tests/CMakeLists.txt +++ b/src/frontends/onnx/tests/CMakeLists.txt @@ -6,6 +6,8 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF) ov_try_use_gold_linker() +ov_deprecated_no_errors() + message(STATUS "ONNX frontend test enabled") add_compile_definitions( @@ -13,7 +15,7 @@ add_compile_definitions( ONNX_MODELS_DIR="${TEST_MODEL_ZOO}/onnx" ONNX_TEST_MODELS="${TEST_MODEL_ZOO}/onnx/" TEST_ONNX_MODELS_DIRNAME="${TEST_MODEL_ZOO}/onnx/" - MANIFEST="${CMAKE_CURRENT_SOURCE_DIR}/unit_test.manifest" + MANIFEST="${TEST_MODEL_ZOO}/onnx/unit_test.manifest" SERIALIZED_ZOO="${TEST_MODEL_ZOO}") list(APPEND ONNX_TESTS_DEPENDENCIES openvino_template_extension) @@ -102,12 +104,18 @@ foreach(src IN LISTS SRC MULTI_TEST_SRC) endforeach() ov_add_clang_format_target(ov_onnx_frontend_tests_clang FOR_SOURCES ${full_src_names}) -foreach(BACKEND_NAME ${ACTIVE_BACKEND_LIST}) +foreach(BACKEND_NAME IN LISTS ACTIVE_BACKEND_LIST) string(TOLOWER ${BACKEND_NAME} BACKEND_DIR) string(REGEX REPLACE "([a-z0-9]+):(.*)" "\\1" BACKEND_DIR ${BACKEND_DIR}) - set(MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/runtime/${BACKEND_DIR}/unit_test.manifest) + set(SRC_MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/runtime/${BACKEND_DIR}/unit_test.manifest) + set(MANIFEST_RENAME "${BACKEND_DIR}_unit_test.manifest") + set(MANIFEST "${TEST_MODEL_ZOO}/onnx/${MANIFEST_RENAME}") + + list(APPEND custom_commands + COMMAND ${CMAKE_COMMAND} -E copy "${SRC_MANIFEST}" + "${TEST_MODEL_ZOO_OUTPUT_DIR}/onnx/${MANIFEST_RENAME}") - foreach(TEST_SRC ${MULTI_TEST_SRC}) + foreach(TEST_SRC IN LISTS MULTI_TEST_SRC) string(REPLACE ":" "_" BACKEND_NAME ${BACKEND_NAME}) string(REPLACE ".in." "_${BACKEND_NAME}." TARGET_NAME ${TEST_SRC}) configure_file(${TEST_SRC} ${TARGET_NAME}) @@ -123,7 +131,7 @@ set_property(TEST ov_onnx_frontend_tests PROPERTY LABELS OV ONNX_FE) add_dependencies(ov_onnx_frontend_tests template_extension) -target_include_directories(ov_onnx_frontend_tests PRIVATE ".") +target_include_directories(ov_onnx_frontend_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_compile_definitions(ov_onnx_frontend_tests PRIVATE @@ -158,9 +166,13 @@ target_include_directories(ov_onnx_frontend_tests PRIVATE $) install(TARGETS ov_onnx_frontend_tests - RUNTIME DESTINATION tests - COMPONENT tests - EXCLUDE_FROM_ALL) + RUNTIME DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL) + +add_custom_command(TARGET ov_onnx_frontend_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/unit_test.manifest" + "${TEST_MODEL_ZOO_OUTPUT_DIR}/onnx/unit_test.manifest" + ${custom_commands} + COMMENT "Copy test manifest files to ${TEST_MODEL_ZOO}/onnx") # process models add_dependencies(ov_onnx_frontend_tests test_model_zoo) diff --git a/src/frontends/onnx/tests/onnx_editor.cpp b/src/frontends/onnx/tests/onnx_editor.cpp index dcffac211fbc29..4f55f231a8029b 100644 --- a/src/frontends/onnx/tests/onnx_editor.cpp +++ b/src/frontends/onnx/tests/onnx_editor.cpp @@ -23,7 +23,7 @@ using namespace ov; using namespace ov::onnx_editor; using namespace ngraph::test; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); namespace { using InputTypePred = std::function)>; diff --git a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp index 3ad1b9cc285fa4..47de95df993802 100644 --- a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp +++ b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp @@ -16,7 +16,7 @@ using namespace ov; using namespace ov::onnx_editor; using namespace ngraph::test; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); OPENVINO_TEST(onnx_editor, topological_sort_two_nodes_swap) { ONNXModelEditor editor{ov::util::path_join({ov::test::utils::getExecutableDirectory(), diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 70e40178d8a879..a442160ed2379c 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -47,7 +47,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), MANIFEST); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); using Inputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp index 75a71e94d88277..cace755ed4ab20 100644 --- a/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_com_microsoft.in.cpp @@ -25,7 +25,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); OPENVINO_TEST(${BACKEND_NAME}, onnx_model_bias_gelu) { diff --git a/src/frontends/onnx/tests/onnx_import_const_folding.in.cpp b/src/frontends/onnx/tests/onnx_import_const_folding.in.cpp index 013d39ab1a879b..a9a3afa5d6c816 100644 --- a/src/frontends/onnx/tests/onnx_import_const_folding.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_const_folding.in.cpp @@ -21,7 +21,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; using namespace ngraph::onnx_import; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); namespace { template diff --git a/src/frontends/onnx/tests/onnx_import_controlflow.in.cpp b/src/frontends/onnx/tests/onnx_import_controlflow.in.cpp index ca6c1e9dd45f87..f6a10af3d5af77 100644 --- a/src/frontends/onnx/tests/onnx_import_controlflow.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_controlflow.in.cpp @@ -20,7 +20,7 @@ using namespace ngraph::onnx_import; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); // ~~~~~~~~TERMINATION CONDITION/TRIP COUNT COMBINATIONS TESTS:~~~~~~~~ diff --git a/src/frontends/onnx/tests/onnx_import_convpool.in.cpp b/src/frontends/onnx/tests/onnx_import_convpool.in.cpp index 8dbdbfcf359baa..d2b84034c1d413 100644 --- a/src/frontends/onnx/tests/onnx_import_convpool.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_convpool.in.cpp @@ -29,7 +29,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); using Inputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp b/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp index be5fd6aaa0523e..70df93755ab2c9 100644 --- a/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp @@ -29,7 +29,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); OPENVINO_TEST(${BACKEND_NAME}, onnx_model_affine) { diff --git a/src/frontends/onnx/tests/onnx_import_dyn_shapes.in.cpp b/src/frontends/onnx/tests/onnx_import_dyn_shapes.in.cpp index 5589582166676f..d9a3b81507f99f 100644 --- a/src/frontends/onnx/tests/onnx_import_dyn_shapes.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_dyn_shapes.in.cpp @@ -31,7 +31,7 @@ using namespace ngraph::onnx_import; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); OPENVINO_TEST(${BACKEND_NAME}, onnx_dyn_shapes_onnx_dynamic_dims_to_ngraph_dynamic_dims) { diff --git a/src/frontends/onnx/tests/onnx_import_library.cpp b/src/frontends/onnx/tests/onnx_import_library.cpp index 22583eed8ce2e0..f1523bc971e78b 100644 --- a/src/frontends/onnx/tests/onnx_import_library.cpp +++ b/src/frontends/onnx/tests/onnx_import_library.cpp @@ -4,10 +4,12 @@ #include +#include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_control.hpp" #include "gtest/gtest.h" +#include "ngraph/file_util.hpp" -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); OPENVINO_TEST(onnx, check_ir_version_support) { // It appears you've changed the ONNX library version used by nGraph. Please update the value diff --git a/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp b/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp index 29cea1750c6d25..25f3f88a56060b 100644 --- a/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp @@ -44,7 +44,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); using Inputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_import_org_pytorch.in.cpp b/src/frontends/onnx/tests/onnx_import_org_pytorch.in.cpp index 846219aa32acba..da55566c38bf8e 100644 --- a/src/frontends/onnx/tests/onnx_import_org_pytorch.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_org_pytorch.in.cpp @@ -25,7 +25,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); OPENVINO_TEST(${BACKEND_NAME}, onnx_model_adaptive_avg_pooling2d_nchw) { diff --git a/src/frontends/onnx/tests/onnx_import_quant.in.cpp b/src/frontends/onnx/tests/onnx_import_quant.in.cpp index 1c5b8baf62d151..ea13274d1b8804 100644 --- a/src/frontends/onnx/tests/onnx_import_quant.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_quant.in.cpp @@ -29,7 +29,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); using Inputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_import_reshape.in.cpp b/src/frontends/onnx/tests/onnx_import_reshape.in.cpp index 773a9df618a2e9..c26f6fb5ad720b 100644 --- a/src/frontends/onnx/tests/onnx_import_reshape.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_reshape.in.cpp @@ -28,7 +28,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); using Inputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_import_rnn.in.cpp b/src/frontends/onnx/tests/onnx_import_rnn.in.cpp index c7be2262ea90fb..f79e96f8fbbb08 100644 --- a/src/frontends/onnx/tests/onnx_import_rnn.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_rnn.in.cpp @@ -29,7 +29,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); // ONNX LSTM tests (implemented by nGraph LSTMCell and LSTMSequence) diff --git a/src/frontends/onnx/tests/onnx_import_signal.in.cpp b/src/frontends/onnx/tests/onnx_import_signal.in.cpp index e8e2bb5e9f4a77..4b409891077f6e 100644 --- a/src/frontends/onnx/tests/onnx_import_signal.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_signal.in.cpp @@ -26,7 +26,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); OPENVINO_TEST(${BACKEND_NAME}, onnx_model_dft) { diff --git a/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp b/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp index 8660c59e47f717..f3b5f64ed13947 100644 --- a/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp +++ b/src/frontends/onnx/tests/onnx_import_with_editor.in.cpp @@ -23,7 +23,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); // ############################################################################ CORE TESTS diff --git a/src/frontends/onnx/tests/onnx_ops_registration.cpp b/src/frontends/onnx/tests/onnx_ops_registration.cpp index a465d449748ee4..dbb8c18f181fbe 100644 --- a/src/frontends/onnx/tests/onnx_ops_registration.cpp +++ b/src/frontends/onnx/tests/onnx_ops_registration.cpp @@ -19,7 +19,7 @@ using namespace ov; using namespace ov::onnx_editor; using namespace ngraph::test; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); OPENVINO_TEST(ops_registration, check_importing_abs_in_all_opset_versions) { ONNXModelEditor editor{ diff --git a/src/frontends/onnx/tests/onnx_tensor_names.cpp b/src/frontends/onnx/tests/onnx_tensor_names.cpp index 9e4de0cd78e115..53d55b1ebd1fa9 100644 --- a/src/frontends/onnx/tests/onnx_tensor_names.cpp +++ b/src/frontends/onnx/tests/onnx_tensor_names.cpp @@ -15,7 +15,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START using namespace ngraph; -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); using Inputs = std::vector>; using Outputs = std::vector>; diff --git a/src/frontends/onnx/tests/onnx_test_utils.in.cpp b/src/frontends/onnx/tests/onnx_test_utils.in.cpp index 996717caa97675..6290310a7a4a8f 100644 --- a/src/frontends/onnx/tests/onnx_test_utils.in.cpp +++ b/src/frontends/onnx/tests/onnx_test_utils.in.cpp @@ -21,7 +21,7 @@ using namespace ngraph; OPENVINO_SUPPRESS_DEPRECATED_START -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); static std::string s_device = backend_name_to_device("${BACKEND_NAME}"); // is there any benefit of running below tests on different backends? diff --git a/src/frontends/onnx/tests/onnx_transformations.cpp b/src/frontends/onnx/tests/onnx_transformations.cpp index 8e35bf77718177..124877b2097b72 100644 --- a/src/frontends/onnx/tests/onnx_transformations.cpp +++ b/src/frontends/onnx/tests/onnx_transformations.cpp @@ -9,7 +9,7 @@ #include "ngraph/file_util.hpp" #include "onnx_test_util.hpp" -static std::string s_manifest = "${MANIFEST}"; +static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); NGRAPH_SUPPRESS_DEPRECATED_START diff --git a/src/frontends/tests/frontend/shared/gtest_main_manifest/main.cpp b/src/frontends/tests/frontend/shared/gtest_main_manifest/main.cpp index 6782ef3ac0dc21..fdcd57534575f3 100644 --- a/src/frontends/tests/frontend/shared/gtest_main_manifest/main.cpp +++ b/src/frontends/tests/frontend/shared/gtest_main_manifest/main.cpp @@ -6,14 +6,19 @@ #include "gtest/gtest.h" #include "utils.hpp" +#include "common_test_utils/file_utils.hpp" -static const std::string manifest{ +#include "ngraph/file_util.hpp" + +OPENVINO_SUPPRESS_DEPRECATED_START +static const std::string s_manifest{ #ifdef MANIFEST - MANIFEST + ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), MANIFEST) #endif }; +OPENVINO_SUPPRESS_DEPRECATED_END int main(int argc, char** argv) { printf("Running main() from %s:%d\n", __FILE__, __LINE__); - return FrontEndTestUtils::run_tests(argc, argv, manifest); + return FrontEndTestUtils::run_tests(argc, argv, s_manifest); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000000000..12102199edd77c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +add_subdirectory(layer_tests) +add_subdirectory(model_hub_tests) +add_subdirectory(samples_tests) diff --git a/tests/samples_tests/smoke_tests/requirements.txt b/tests/samples_tests/smoke_tests/requirements.txt index 2181461187efa3..f7e62115a301c9 100644 --- a/tests/samples_tests/smoke_tests/requirements.txt +++ b/tests/samples_tests/smoke_tests/requirements.txt @@ -7,7 +7,7 @@ numpy pytest py scikit-build -opencv-python +opencv-python-headless progress nibabel scipy \ No newline at end of file From bf7fcb08e77c824b3e76c2ea09b9bb478720edd4 Mon Sep 17 00:00:00 2001 From: "Wang, Yang" Date: Mon, 25 Sep 2023 21:43:21 +0800 Subject: [PATCH 43/43] No exception throws when getting version from unregistered plugin (#19722) * Updated the behavior of core.get_version() and added corresponding test cases. * Remove the prompt message. * Update src/inference/src/dev/core_impl_ie.cpp Co-authored-by: Ilya Churaev --------- Co-authored-by: Ilya Churaev Co-authored-by: yanlan song Co-authored-by: Chen Peter --- src/inference/src/dev/core_impl.cpp | 3 +- src/inference/src/dev/core_impl_ie.cpp | 15 +++++-- .../functional/ov_register_plugin_test.cpp | 43 +++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp index 462a0b9f7cc5ae..77e5514ea9999c 100644 --- a/src/inference/src/dev/core_impl.cpp +++ b/src/inference/src/dev/core_impl.cpp @@ -553,7 +553,8 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const { it = pluginRegistry.find(deviceName); if (it == pluginRegistry.end()) { if (pluginName == ov::DEFAULT_DEVICE_NAME) - OPENVINO_THROW("No device is provided, so AUTO device is used by default, which failed loading."); + OPENVINO_THROW("No device is provided, so AUTO device is used by default, which is not registered in " + "the OpenVINO Runtime."); else OPENVINO_THROW("Device with \"", deviceName, "\" name is not registered in the OpenVINO Runtime"); } diff --git a/src/inference/src/dev/core_impl_ie.cpp b/src/inference/src/dev/core_impl_ie.cpp index dcae7503920d03..e689db3ee7113b 100644 --- a/src/inference/src/dev/core_impl_ie.cpp +++ b/src/inference/src/dev/core_impl_ie.cpp @@ -267,10 +267,17 @@ std::map ov::CoreImpl::GetVersions(const ov::DeviceIDParser parser(deviceName_); std::string deviceNameLocal = parser.get_device_name(); - ov::Plugin cppPlugin = get_plugin(deviceNameLocal); - - versions[deviceNameLocal] = - ov::legacy_convert::convert_plugin(ov::SoPtr{cppPlugin.m_ptr, cppPlugin.m_so})->GetVersion(); + try { + ov::Plugin cppPlugin = get_plugin(deviceNameLocal); + auto convertedPlugin = + ov::legacy_convert::convert_plugin(ov::SoPtr{cppPlugin.m_ptr, cppPlugin.m_so}); + versions[deviceNameLocal] = convertedPlugin->GetVersion(); + } catch (const ov::Exception& ex) { + std::string exception(ex.what()); + if (exception.find("not registered in the OpenVINO Runtime") == std::string::npos) { + throw; + } + } } return versions; diff --git a/src/inference/tests/functional/ov_register_plugin_test.cpp b/src/inference/tests/functional/ov_register_plugin_test.cpp index a42920237e9a63..0708cd347d916d 100644 --- a/src/inference/tests/functional/ov_register_plugin_test.cpp +++ b/src/inference/tests/functional/ov_register_plugin_test.cpp @@ -9,6 +9,7 @@ #include "openvino/runtime/properties.hpp" #include "openvino/util/file_util.hpp" #include "openvino/util/shared_object.hpp" +#include "unit_test_utils/mocks/openvino/runtime/mock_iplugin.hpp" using namespace ::testing; using namespace std; @@ -34,6 +35,48 @@ inline void mockPlugin(ov::Core& core, std::shared_ptr& plugin, std injectProxyEngine(plugin.get()); } +TEST(RegisterPluginTests, getVersionforRegisteredPluginThrows) { + ov::Core core; + auto plugin = std::make_shared(); + std::shared_ptr base_plugin = plugin; + std::shared_ptr m_so; + mockPlugin(core, base_plugin, m_so); + std::string mock_plugin_name{"MOCK_REGISTERED_HARDWARE"}; + // Registered plugin with invalid so here + ASSERT_NO_THROW(core.register_plugin( + ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("mock_registered_engine") + IE_BUILD_POSTFIX), + mock_plugin_name)); + ASSERT_THROW(core.get_versions("MOCK_REGISTERED_HARDWARE"), ov::Exception); +} + +TEST(RegisterPluginTests, getVersionforNoRegisteredPluginNoThrows) { + ov::Core core; + ASSERT_NO_THROW(core.get_versions("unkown_device")); + + auto plugin = std::make_shared>(); + + ON_CALL(*plugin.get(), get_property(ov::supported_properties.name(), _)) + .WillByDefault(Return(std::vector{})); + + ON_CALL(*plugin.get(), get_property(ov::internal::supported_properties.name(), _)) + .WillByDefault(Return(std::vector{})); + + ON_CALL(*plugin.get(), set_property(_)).WillByDefault(Return()); + + std::shared_ptr base_plugin = plugin; + std::shared_ptr m_so; + mockPlugin(core, base_plugin, m_so); + + std::string mock_plugin_name{"MOCK_HARDWARE"}; + + ASSERT_NO_THROW( + core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + mock_plugin_name)); + ASSERT_NO_THROW(core.get_versions("MOCK_HARDWARE")); +} + TEST(RegisterPluginTests, registerNewPluginNoThrows) { ov::Core core; auto plugin = std::make_shared();