code: def test_inference_pretrained(self):
      model = FlaxWav2Vec2ForPreTraining.from_pretrained(
          "facebook/wav2vec2-large-lv60", from_pt=True
      )
      feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(
          "facebook/wav2vec2-large-lv60", return_attention_mask=True
      )
      input_speech = self._load_datasamples(2)
  
      inputs_dict = feature_extractor(
          input_speech, return_tensors="np", padding=True
      )
  
      features_shape = (
          inputs_dict["input_values"].shape[0],
          model._get_feat_extract_output_lengths(
              np.array(inputs_dict["input_values"].shape[1])
          ),
      )
  
      mask_time_indices = _compute_mask_indices(
          features_shape,
          model.config.mask_time_prob,
          model.config.mask_time_length,
          min_masks=2,
      )
  
      outputs = model(
          inputs_dict.input_values,
          attention_mask=inputs_dict.attention_mask,
          mask_time_indices=mask_time_indices,
      )
  
      # compute cosine similarity
      cosine_sim = optax.cosine_similarity(
          outputs.projected_states,
          outputs.projected_quantized_states,
          epsilon=1e-8,
      )
  
      # retrieve cosine sim of masked features
      cosine_sim_masked = cosine_sim[mask_time_indices]
  
      # ... now compare to randomly initialized model
  
      config = Wav2Vec2Config.from_pretrained(
          "facebook/wav2vec2-large-lv60"
      )
      model_rand = FlaxWav2Vec2ForPreTraining(config)
  
      outputs_rand = model_rand(
          inputs_dict.input_values,
          attention_mask=inputs_dict.attention_mask,
          mask_time_indices=mask_time_indices,
      )
  
      # compute cosine similarity
      cosine_sim_rand = optax.cosine_similarity(
          outputs_rand.projected_states,
          outputs_rand.projected_quantized_states,
      )
  
      # retrieve cosine sim of masked features
      cosine_sim_masked_rand = cosine_sim_rand[mask_time_indices]
  
      # a pretrained wav2vec2 model has learned to predict the quantized latent states
      # => the cosine similarity between quantized states and predicted states > 0.5
      # a random wav2vec2 model has not learned to predict the quantized latent states
      # => the cosine similarity between quantized states and predicted states is very likely < 0.1
      self.assertTrue(
          cosine_sim_masked.mean().item()
          - 5 * cosine_sim_masked_rand.mean().item()
          > 0
      )
  
imports: import inspect
  import math
  import multiprocessing
  import traceback
  import unittest
  import numpy
  from datasets import load_dataset
  from transformers import Wav2Vec2Config, is_flax_available
  from transformers.testing_utils import CaptureLogger, is_flaky, is_librosa_available, is_pt_flax_cross_test, is_pyctcdecode_available, require_flax, require_librosa, require_pyctcdecode, require_soundfile, run_test_in_subprocess, slow
  from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, random_attention_mask
label_desc: Use image node_id 3 for calling the FlaxWav2Vec2ModelIntegrationTest obj's underlying member method code with example usage: obj.test_inference_pretrained() without return types