python_code
stringlengths
0
229k
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Special implementations of mathematical functions that solve numerical issues of naive implementations. .. [Mae...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations import math import warnings from abc import abstractproperty from collections imp...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # NOTE: To be removed once (if) https://github.com/pytorch/pytorch/pull/37385 lands from __future__ import annotatio...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from copy import deepcopy from math import pi from typing import List, Optional ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Callable, List, Optional, Tuple import botorch.models.model a...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Optional, Sequence import torch from botorch.utils.probabilit...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from inspect import getmembers from typing import Optional, Sequence, Union impo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Linear Elliptical Slice Sampler. References .. [Gessner2020] A. Gessner, O. Kanjilal, and P. Hennig. Integr...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.utils.probability.bvn import bvn, bvnmom from botorch.utils.probability.lin_ess import LinearEllipticalS...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Bivariate conditioning algorithm for approximating Gaussian probabilities, see [Genz2016numerical]_ and [Trinh20...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from dataclasses import dataclass, InitVar from itertools import chain from typin...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations import math from functools import lru_cache from math import pi from numbers imp...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Methods for computing bivariate normal probabilities and statistics. .. [Genz2004bvnt] A. Genz. Numerical c...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.utils.multi_objective.hypervolume import Hypervolume, infer_reference_point from botorch.utils.multi_obj...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations import torch from torch import Tensor # maximum tensor size for simple pareto co...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Helper utilities for constructing scalarizations. References .. [Knowles2005] J. Knowles, "ParEGO: a hybri...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Hypervolume Utilities. References .. [Fonseca2006] C. M. Fonseca, L. Paquete, and M. Lopez-Ibanez. An impro...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Box decomposition algorithms. References .. [Lacour17] R. Lacour, K. Klamroth, C. Fonseca. A box decomposit...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.utils.multi_objective.box_decompositions.box_decomposition_list import ( # noqa E501 BoxDecomposit...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Utilities for box decomposition algorithms.""" from typing import Optional, Tuple import torch from botorch.exc...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Algorithms for partitioning the dominated space into hyperrectangles.""" from __future__ import annotations fro...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Box decomposition container.""" from __future__ import annotations from typing import List, Union import torch...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Algorithms for partitioning the non-dominated space into rectangles. References .. [Couckuyt2012] I. Coucku...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" References .. [Zhe2019hogp] S. Zhe, W. Xing, and R. M. Kirby. Scalable high-order gaussian process regressi...
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Multi-task Gaussian Process Regression models with fully Bayesian inference. """ from typing import Any, Dict, List, Mapping, NoRetur...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" References .. [Feng2020HDCPS] Q. Feng, B. Latham, H. Mao and E. Backshy. High-Dimensional Contextual Policy...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Deterministic Models: Simple wrappers that allow the usage of deterministic mappings via the BoTorch Model and P...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Abstract model class for all GPyTorch-based botorch models. To implement your own, simply inherit from both the...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Dict, List, Optional from botorch.models.gp_regression import FixedNoiseGP from botorch.models.ke...
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Gaussian Process Regression models with fully Bayesian inference. Fully Bayesian models use Bayesian inference over model hyperparamet...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" References .. [burt2020svgp] David R. Burt and Carl Edward Rasmussen and Mark van der Wilk, Convergence...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Utilities for converting between different models. """ from __future__ import annotations from copy import dee...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.models.approximate_gp import ( ApproximateGPyTorchModel, SingleTaskVariationalGP, ) from botorch...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Preference Learning with Gaussian Process .. [Chu2005preference] Wei Chu, and Zoubin Ghahramani. Preference...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Gaussian Process Regression models based on GPyTorch models. These models are often a good starting point and a...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Abstract base module for all BoTorch models. This module contains `Model`, the abstract base class for all BoTor...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Ensemble Models: Simple wrappers that allow the usage of ensembles via the BoTorch Model and Posterior APIs. """...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Multi-Task GP models. References .. [Bonilla2007MTGP] E. Bonilla, K. Chai and C. Williams. Multi-task Gaus...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Cost models to be used with multi-fidelity optimization. Cost are useful for defining known cost functions when...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Model List GP Regression models. """ from __future__ import annotations from copy import deepcopy from typing ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Multi-Fidelity Gaussian Process Regression models based on GPyTorch models. For more on Multi-Fidelity BO, see ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations import warnings from typing import Any, Callable, Dict, List, Optional import to...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Optional import torch from gpytorch.constraints import Interv...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch from gpytorch.kernels.kernel import Kernel from torch import Tensor class CategoricalKernel(Kernel): ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math from typing import List, Optional, Tuple import numpy import torch from botorch.exceptions.errors import UnsupportedError from ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.models.kernels.categorical import CategoricalKernel from botorch.models.kernels.downsampling import Down...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Any, Dict, List, Optional import torch from gpytorch.kernels.kernel import Kernel from gpytorch.k...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Any, List, Optional import torch from botorch.exceptions impo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Any, Dict, List, Optional import torch from gpytorch.constraints import Positive from gpytorch.ke...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Optional import torch from gpytorch.constraints import Interv...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Optional import torch from gpytorch.constraints.constraints import GreaterThan from gpytorch.kern...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Functionality for allocating the inducing points of sparse Gaussian process models. References .. [chen2018dpp...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Parsing rules for BoTorch datasets.""" from __future__ import annotations from typing import Any, Dict, Hashab...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.models.utils.assorted import ( _make_X_full, add_output_dim, check_min_max_scaling, chec...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r"""Assorted helper methods and objects for working with BoTorch models.""" from __future__ import annotations impo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.models.likelihoods.pairwise import ( PairwiseLogitLikelihood, PairwiseProbitLikelihood, ) __al...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Pairwise likelihood for pairwise preference model (e.g., PairwiseGP). """ from __future__ import annotations i...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Outcome transformations for automatically transforming and un-transforming model outputs. Outcome transformation...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.models.transforms.factory import get_rounding_input_transform from botorch.models.transforms.input impor...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from collections import OrderedDict from typing import Dict, List, Optional from...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from functools import wraps from typing import Tuple import torch from torch imp...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Input Transformations. These classes implement a variety of transformations for input parameters including: lea...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Botorch Warnings. """ class BotorchWarning(Warning): r"""Base botorch warning.""" pass class BadIni...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.exceptions.errors import ( BotorchError, BotorchTensorDimensionError, CandidateGenerationErr...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Botorch Errors. """ from typing import Any import numpy as np class BotorchError(Exception): r"""Base bo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Optional, Tuple import torch from botorch.exceptions.errors import BotorchTensorDimensionError fr...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Deterministic (degenerate) posteriors. Used in conjunction with deterministic models. """ from __future__ impor...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Posterior module to be used with GPyTorch models. """ from __future__ import annotations import warnings from...
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Callable, Optional, Tuple import torch from botorch.posteriors.gpytorch import GPyTo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.posteriors.deterministic import DeterministicPosterior from botorch.posteriors.fully_bayesian import Ful...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Abstract base module for all botorch posteriors. """ from __future__ import annotations from functools import ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations import torch from gpytorch.distributions.multitask_multivariate_normal import ( ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Ensemble posteriors. Used in conjunction with ensemble models. """ from __future__ import annotations from typ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Abstract base module for all botorch posteriors. """ from __future__ import annotations import warnings from ...
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Optional, Tuple, Union import torch from botorch.exceptions.errors import BotorchTensorDimensionError from botorch.poste...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Posterior module to be used with PyTorch distributions. """ from __future__ import annotations from typing imp...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from typing import Callable, Optional, Tuple import torch from botorch.posterior...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Candidate generation utilities. """ from __future__ import annotations import time import warnings from functo...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from botorch.generation.gen import ( gen_candidates_scipy, gen_candidates_torch, get_best_candidates, ) ...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from __future__ import annotations from dataclasses import dataclass from typing import Callable, Dict, List, Option...
#!/usr/bin/env python3 # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. r""" Sampling-based generation strategies. A SamplingStrategy returns samples from the input points (i.e. Tensors in...
#!/usr/bin/env python import confu parser = confu.standard_parser("cpuinfo configuration script") parser.add_argument("--log", dest="log_level", choices=("none", "fatal", "error", "warning", "info", "debug"), default="error") parser.add_argument("--mock", dest="mock", action="store_true") def main(args): op...
#!/usr/bin/env python import os import sys import argparse import shutil parser = argparse.ArgumentParser(description='Android system files extractor') parser.add_argument("-p", "--prefix", metavar="NAME", required=True, help="Prefix for stored files, e.g. galaxy-s7-us") SYSTEM_FILES = [ "/...
#!/usr/bin/env python from __future__ import print_function import argparse import sys import re parser = argparse.ArgumentParser(description='x86 CPUID dump parser') parser.add_argument("input", metavar="INPUT", nargs=1, help="Path to CPUID dump log") def main(args): options = parser.pars...
#!/usr/bin/env python import os import sys import string import argparse import subprocess import tempfile root_dir = os.path.abspath(os.path.dirname(__file__)) parser = argparse.ArgumentParser(description='Android system files extractor') parser.add_argument("-p", "--prefix", metavar="NAME", required=True, ...
#!/usr/bin/env python import confu parser = confu.standard_parser("clog configuration script") def main(args): options = parser.parse_args(args) build = confu.Build.from_options(options) build.export_cpath("include", ["clog.h"]) with build.options(source_dir="src", extra_include_dirs="src"): ...
from typing import Dict, List, Optional, Tuple import json import math from fairseq.data import Dictionary import torch import torchaudio from torchaudio.pipelines import EMFORMER_RNNT_BASE_LIBRISPEECH from torchaudio.models import Hypothesis def get_hypo_tokens(hypo: Hypothesis) -> List[int]: return hypo[0] d...
import torch import torchaudio from torch.utils.mobile_optimizer import optimize_for_mobile def get_demo_wrapper(): wrapper = torch.jit.load("scripted_wrapper_tuple.pt") return wrapper wrapper = get_demo_wrapper() scripted_model = torch.jit.script(wrapper) optimized_model = optimize_for_mobile(scripted_model)...
import pyaudio import queue import numpy as np import torch import torchaudio def get_demo_wrapper(): wrapper = torch.jit.load("scripted_wrapper_tuple.pt") return wrapper wrapper = get_demo_wrapper() ################################################################ data_queue = queue.Queue() def callba...
import torch import torch.utils.cpp_extension print(torch.version.__version__) op_source = """ #include <opencv2/opencv.hpp> #include <torch/script.h> torch::Tensor warp_perspective(torch::Tensor image, torch::Tensor warp) { cv::Mat image_mat(/*rows=*/image.size(0), /*cols=*/image.size(1), ...
import torch from torch.utils.mobile_optimizer import optimize_for_mobile model = torch.hub.load('pytorch/vision:v0.11.0', 'deeplabv3_resnet50', pretrained=True) model.eval() scripted_module = torch.jit.script(model) optimized_scripted_module = optimize_for_mobile(scripted_module) # Export full jit version model (no...
import torch from torch import Tensor from torch.utils.mobile_optimizer import optimize_for_mobile import torchaudio from torchaudio.models.wav2vec2.utils.import_huggingface import import_huggingface_model from transformers import Wav2Vec2ForCTC # Wav2vec2 model emits sequences of probability (logits) distributions ov...
import torch from pytorchvideo.accelerator.deployment.mobile_cpu.utils.model_conversion import ( convert_to_deployable_form, ) from pytorchvideo.models.accelerator.mobile_cpu.efficient_x3d import EfficientX3d from torch.hub import load_state_dict_from_url from torch.utils.mobile_optimizer import ( optimize_for_...
import torch from transformers import DistilBertTokenizer, DistilBertForQuestionAnswering from torch.utils.mobile_optimizer import optimize_for_mobile tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased-distilled-squad') model = DistilBertForQuestionAnswering.from_pretrained('distilbert-base-uncas...
# based on https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html from __future__ import unicode_literals, print_function, division from io import open import unicodedata import string import re import random import torch import torch.nn as nn from torch import optim import torch.nn.functional a...
import torch from torch.utils.mobile_optimizer import optimize_for_mobile model = torch.hub.load('facebookresearch/deit:main', 'deit_base_patch16_224', pretrained=True) quantized_model = torch.quantization.quantize_dynamic(model, qconfig_spec={torch.nn.Linear}, dtype=torch.qint8) ts_model = torch.jit.script(quantized_...
import torch import torch.nn.functional as F from torch import nn from einops import rearrange class Residual(nn.Module): def __init__(self, fn): super().__init__() self.fn = fn def forward(self, x, **kwargs): return self.fn(x, **kwargs) + x class PreNorm(nn.Module): def __init__...
import torch import torchvision import time from vit_pytorch import * from torch.utils.mobile_optimizer import optimize_for_mobile torch.manual_seed(42) DOWNLOAD_PATH = 'data/mnist' BATCH_SIZE_TRAIN = 100 BATCH_SIZE_TEST = 1000 # 0.1307 and 0.3081 are the mean and std computed on the MNIST training set transform_mn...
#!/usr/bin/env python3 import contextlib import copy import os import unittest from PIL import Image import torch from d2go.export.api import convert_and_export_predictor from d2go.export.d2_meta_arch import patch_d2_meta_arch from d2go.runner import create_runner, GeneralizedRCNNRunner from d2go.model_zoo import mod...
import torch import torchvision from torch.utils.mobile_optimizer import optimize_for_mobile model = torchvision.models.mobilenet_v3_small(pretrained=True) model.eval() example = torch.rand(1, 3, 224, 224) traced_script_module = torch.jit.trace(model, example) optimized_traced_model = optimize_for_mobile(traced_script...