<commit_before><!-- Copyright 2019 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================-->

<html>

<head>
  <title>TensorFlow.js Model Benchmark</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
  <link href="./main.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
  <link rel="shortcut icon"
    href="https://www.gstatic.com/devrel-devsite/prod/vf4ca28c48392b1412e7b030290622a0dd55b62dec1202c59f119b1e23227c988/tensorflow/images/favicon.png">
</head>

<body>
  <h2>TensorFlow.js Model Benchmark</h2>
  <div id="modal-msg"></div>
  <div id="container">
    <div id="stats">
      <div class="box">
        <pre id="env"></pre>
      </div>
      <table class="table" id="parameters">
        <caption>Parameters</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
      <table class="table" id="modelInputs" style="display: none;">
        <caption>Inputs</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody></tbody>
      </table>
      <table class="table" id="timings">
        <caption>Model</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
      <div class="box" id="perf-trendline-container">
        <div class="label">Inference times</div>
        <div class="trendline">
          <div class="yMax"></div>
          <div class="yMin"></div>
          <svg>
            <path></path>
          </svg>
        </div>
      </div>
    </div>
    <table class="table" id="kernels">
      <caption>Kernel</caption>
      <thead id="kernels-thead">
        <tr>
          <th>Type</th>
          <th>Time(ms)</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
  </div>
  <script src="https://unpkg.com/@tensorflow/tfjs-core@latest/dist/tf-core.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-cpu@latest/dist/tf-backend-cpu.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-webgl@latest/dist/tf-backend-webgl.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-webgpu@latest/dist/tf-backend-webgpu.min.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-wasm@latest/dist/tf-backend-wasm.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-automl@latest/dist/tf-automl.js" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/speech-commands" crossorigin> </script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@2" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix@2" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/pose-detection" crossorigin></script>

  <script src="../model_config.js"></script>
  <script src="../benchmark_util.js"></script>
  <script src="./util.js"></script>
  <script src="./index.js"></script>
  <script>
    'use strict';

    let urlState = null;
    let runTimes = 50;
    let warmupTimes = 1;
    // Default do not run any task.
    let task = '';
    function getURLState(url) {
      let params = new URLSearchParams(url);
      const keys = [...params.keys()];
      if (keys.length === 0)
        return null;
      if (params.has('run')) {
        runTimes = Number(params.get('run'));
      }
      if (params.has('warmup')) {
        warmupTimes = Number(params.get('warmup'));
      }
      if (params.has('task')) {
        task = params.get('task');
      }
      return params;
    }
    // Controllers can be updated by URI or clicked by user.
    let modelController = null;
    let numRunsController = null;
    let modelParameterFolder = null;
    let backendsController = null;
    let runButton = null;
    let correctnessButton = null;
    let inputSizeController = null;
    let inputTypeController = null;
    let modelArchitectureController = null;

    function updateGUIFromURLState() {
      if (urlState == null)
        return;
      // The model parameter will be update automically by onChange.
      if (modelController != null && urlState.has('benchmark'))
        modelController.setValue(urlState.get('benchmark'));
      if (numRunsController != null && urlState.has('run'))
        numRunsController.setValue(urlState.get('run'));
      if (backendsController != null && urlState.has('backend'))
        backendsController.setValue(urlState.get('backend'));
      // Only auto run when URI component exists.
      if (correctnessButton != null && task == 'correctness') {
        correctnessButton.domElement.click();
      }
      if (runButton != null && task == 'performance') {
        runButton.domElement.click();
      }
    }

    const state = {
      numRuns: runTimes,
      benchmark: 'mobilenet_v2',
      run: (v) => {
        runBenchmark().catch(e => {
          showMsg('Error: ' + e.message);
          throw e;
        });
      },
      testCorrectness: async () => {
        if (!tf.engine().backendNames().includes(state.backend)) {
          return;
        }
        await tf.ready();
        if (state.isFlagChanged) {
          await setEnvFlags(state.flags);
          envDiv.innerHTML = '';
          showVersions();
          await showEnvironment();
        }

        let match, predictionData, referenceData;
        await cleanUpTable();

        // load model and run inference
        try {
          await loadModelAndRecordTime();
          await showMsg('Testing correctness');
          await showInputs();
          await showCorrectnessTestParameters();

          tf.setBackend('cpu');
          let inferenceInput;
          await showMsg('Runing on cpu');
          if (state.benchmark === 'custom') {
            inferenceInput = generateInputFromDef(
              state.inputs, model instanceof tf.GraphModel);
          }
          const referencePrediction = predict(model, inferenceInput);
          referenceData = await getPredictionData(referencePrediction);

          await tf.setBackend(state.backend);
          await showMsg(`Runing on ${state.backend}`);
          const prediction = predict(model, inferenceInput);
          predictionData = await getPredictionData(prediction);
        } catch (e) {
          showMsg('Error: ' + e.message);
          throw e;<commit_msg>[E2E] Fix test correctness issue (#5315)<commit_after><!-- Copyright 2019 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================-->

<html>

<head>
  <title>TensorFlow.js Model Benchmark</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
  <link href="./main.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
  <link rel="shortcut icon"
    href="https://www.gstatic.com/devrel-devsite/prod/vf4ca28c48392b1412e7b030290622a0dd55b62dec1202c59f119b1e23227c988/tensorflow/images/favicon.png">
</head>

<body>
  <h2>TensorFlow.js Model Benchmark</h2>
  <div id="modal-msg"></div>
  <div id="container">
    <div id="stats">
      <div class="box">
        <pre id="env"></pre>
      </div>
      <table class="table" id="parameters">
        <caption>Parameters</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
      <table class="table" id="modelInputs" style="display: none;">
        <caption>Inputs</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody></tbody>
      </table>
      <table class="table" id="timings">
        <caption>Model</caption>
        <thead>
          <tr>
            <th>Type</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
      <div class="box" id="perf-trendline-container">
        <div class="label">Inference times</div>
        <div class="trendline">
          <div class="yMax"></div>
          <div class="yMin"></div>
          <svg>
            <path></path>
          </svg>
        </div>
      </div>
    </div>
    <table class="table" id="kernels">
      <caption>Kernel</caption>
      <thead id="kernels-thead">
        <tr>
          <th>Type</th>
          <th>Time(ms)</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
  </div>
  <script src="https://unpkg.com/@tensorflow/tfjs-core@latest/dist/tf-core.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-cpu@latest/dist/tf-backend-cpu.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-webgl@latest/dist/tf-backend-webgl.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-webgpu@latest/dist/tf-backend-webgpu.min.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-layers@latest/dist/tf-layers.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-converter@latest/dist/tf-converter.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-backend-wasm@latest/dist/tf-backend-wasm.js" crossorigin></script>
  <script src="https://unpkg.com/@tensorflow/tfjs-automl@latest/dist/tf-automl.js" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/speech-commands" crossorigin> </script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@2" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix@2" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/pose-detection" crossorigin></script>

  <script src="../model_config.js"></script>
  <script src="../benchmark_util.js"></script>
  <script src="./util.js"></script>
  <script src="./index.js"></script>
  <script>
    'use strict';

    let urlState = null;
    let runTimes = 50;
    let warmupTimes = 1;
    // Default do not run any task.
    let task = '';
    function getURLState(url) {
      let params = new URLSearchParams(url);
      const keys = [...params.keys()];
      if (keys.length === 0)
        return null;
      if (params.has('run')) {
        runTimes = Number(params.get('run'));
      }
      if (params.has('warmup')) {
        warmupTimes = Number(params.get('warmup'));
      }
      if (params.has('task')) {
        task = params.get('task');
      }
      return params;
    }
    // Controllers can be updated by URI or clicked by user.
    let modelController = null;
    let numRunsController = null;
    let modelParameterFolder = null;
    let backendsController = null;
    let runButton = null;
    let correctnessButton = null;
    let inputSizeController = null;
    let inputTypeController = null;
    let modelArchitectureController = null;

    function updateGUIFromURLState() {
      if (urlState == null)
        return;
      // The model parameter will be update automically by onChange.
      if (modelController != null && urlState.has('benchmark'))
        modelController.setValue(urlState.get('benchmark'));
      if (numRunsController != null && urlState.has('run'))
        numRunsController.setValue(urlState.get('run'));
      if (backendsController != null && urlState.has('backend'))
        backendsController.setValue(urlState.get('backend'));
      // Only auto run when URI component exists.
      if (correctnessButton != null && task == 'correctness') {
        correctnessButton.domElement.click();
      }
      if (runButton != null && task == 'performance') {
        runButton.domElement.click();
      }
    }

    const state = {
      numRuns: runTimes,
      benchmark: 'mobilenet_v2',
      run: (v) => {
        runBenchmark().catch(e => {
          showMsg('Error: ' + e.message);
          throw e;
        });
      },
      testCorrectness: async () => {
        if (!tf.engine().backendNames().includes(state.backend)) {
          return;
        }
        await tf.ready();
        if (state.isFlagChanged) {
          await setEnvFlags(state.flags);
          envDiv.innerHTML = '';
          showVersions();
          await showEnvironment();
        }

        let match, predictionData, referenceData;
        await cleanUpTable();

        // load model and run inference
        try {
          tf.setBackend('cpu');
          await loadModelAndRecordTime();
          await showMsg('Testing correctness');
          await showInputs();
          await showCorrectnessTestParameters();

          let inferenceInput;
          await showMsg('Runing on cpu');
          if (state.benchmark === 'custom') {
            inferenceInput = generateInputFromDef(
              state.inputs, model instanceof tf.GraphModel);
          }
          const referencePrediction = predict(model, inferenceInput);
          referenceData = await getPredictionData(referencePrediction);

          await tf.setBackend(state.backend);
          await showMsg(`Runing on ${state.backend}`);
          const prediction = predict(model, inferenceInput);
          predictionData = await getPredictionData(prediction);
        } catch (e) {
          showMsg('Error: ' + e.message);
          throw e;
{'fraction_non_alphanumeric': 0.15878979632193, 'fraction_numerical': 0.008898556456397073, 'mean_word_length': 2.6279292204686753, 'pattern_counts': {'":': 0, '<': 261, '<?xml version=': 0, '>': 267, 'https://': 32, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '119833', 'n_tokens_mistral': 4719, 'n_tokens_neox': 4547, 'n_words': 932}