python_code
stringlengths
0
679k
repo_name
stringlengths
9
41
file_path
stringlengths
6
149
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """Megatron tokenizers.""" from abc import ABC from abc import abstractmethod from .bert_tokenization import FullTokenizer as FullBertTokenizer from .gpt2_tokenization import GPT2Tokenizer def build_tokenizer(args): """Initialize tokenizer.""" i...
Megatron-LM-master
megatron/tokenizer/tokenizer.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import os import pathlib import subprocess from torch.utils import cpp_extension # Setting this param to a list has a problem of generating different # compilation commands (with diferent order of architectures) and # leading to recompilation of fused ke...
Megatron-LM-master
megatron/fused_kernels/__init__.py
Megatron-LM-master
megatron/fused_kernels/tests/__init__.py
import math import torch from torch.nn import LayerNorm from megatron.model.enums import AttnMaskType from megatron.model.fused_layer_norm import MixedFusedLayerNorm from megatron.model.fused_softmax import FusedScaleMaskSoftmax from megatron.model.utils import attention_mask_func from megatron.fused_kernels import l...
Megatron-LM-master
megatron/fused_kernels/tests/test_fused_kernels.py
import os import torch import sys from megatron import get_args, print_rank_0, get_tokenizer from megatron.core import mpu from megatron.checkpointing import fix_query_key_value_ordering from megatron.checkpointing import get_checkpoint_tracker_filename from megatron.checkpointing import get_checkpoint_name from megat...
Megatron-LM-master
megatron/model/biencoder_model.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """This code is copied fron NVIDIA apex: https://github.com/NVIDIA/apex with some changes. """ import numbers import torch from torch.nn.parameter import Parameter from torch.nn import init import importlib from megatron.core.utils import make_v...
Megatron-LM-master
megatron/model/fused_layer_norm.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Multiple choice model.""" import torch from megatron import get_args, print_rank_last from megatron.model.enums import AttnMaskType from megatron.model.bert_model import bert_extended_attention_mask, bert_position_ids from megatron.model.language_mode...
Megatron-LM-master
megatron/model/multiple_choice.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """Transformer based language model.""" import torch import torch.nn.functional as F from megatron import get_args from megatron.core import mpu, tensor_parallel from megatron.core.enums import ModelType from megatron.core.models.common.rotary_pos_embedd...
Megatron-LM-master
megatron/model/language_model.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. import enum class LayerType(enum.Enum): encoder = 1 decoder = 2 retro_encoder = 3 retro_decoder = 4 retro_decoder_with_retriever = 5 class AttnType(enum.Enum): self_attn = 1 cross_attn = 2 class AttnMaskType(enum.Enum): ...
Megatron-LM-master
megatron/model/enums.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import torch import torch.nn as nn from megatron.model.enums import AttnMaskType class ScaledUpperTriangMaskedSoftmax(torch.autograd.Function): """ Fused operation which performs following three operations in sequence 1. Scale the tensor. ...
Megatron-LM-master
megatron/model/fused_softmax.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Classification model.""" import torch from megatron import get_args, print_rank_last from megatron.model.enums import AttnMaskType from megatron.model.bert_model import bert_extended_attention_mask, bert_position_ids from megatron.model.language_model...
Megatron-LM-master
megatron/model/classification.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """BERT model.""" import torch from megatron import get_args from megatron.core import tensor_parallel from megatron.model.enums import AttnMaskType from megatron.model.language_model import parallel_lm_logits from megatron.model.language_model import ge...
Megatron-LM-master
megatron/model/bert_model.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. from .fused_layer_norm import MixedFusedLayerNorm as LayerNorm from .rms_norm import RMSNorm from .distributed import DistributedDataParallel from .bert_model import BertModel from .gpt_model import GPTModel from .t5_model import T5Model from .language_mo...
Megatron-LM-master
megatron/model/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import torch ###### BIAS GELU FUSION/ NO AUTOGRAD ################ # 1/sqrt(2*pi)-> 0.3989423 # 1/sqrt(2) -> 0.70710678 # sqrt(2/pi) -> 0.79788456 # this function is tanh approximation of gelu # actual gelu is: # x * 0.5 * (1.0 + torch.erf(x * 0.70710...
Megatron-LM-master
megatron/model/fused_bias_gelu.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. import math from abc import ABC, abstractmethod from contextlib import contextmanager from typing import Dict, List import torch from megatron.core import mpu from .module import MegatronModule class MemoryBuffer: def __init__(self, numel: int, nu...
Megatron-LM-master
megatron/model/distributed.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """T5 model.""" import torch from megatron import get_args from megatron.core import tensor_parallel from megatron.model.enums import AttnMaskType from megatron.model.language_model import parallel_lm_logits, get_language_model from megatron.model import...
Megatron-LM-master
megatron/model/t5_model.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """Utilities for models.""" import math import torch from megatron import get_args from megatron.model import LayerNorm, RMSNorm def init_method_normal(sigma): """Init method based on N(0, sigma).""" def init_(tensor): return torch.nn.i...
Megatron-LM-master
megatron/model/utils.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """Transformer.""" from contextlib import nullcontext import math import numpy as np import torch import torch.nn.functional as F from typing import Optional from megatron import get_timers, get_args, get_retro_args, core, get_num_microbatches from .modul...
Megatron-LM-master
megatron/model/transformer.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. """GPT-2 model.""" import torch from megatron import get_args from megatron.core import tensor_parallel from .module import MegatronModule from .enums import AttnMaskType from .language_model import parallel_lm_logits from .language_model import get_lan...
Megatron-LM-master
megatron/model/gpt_model.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Megatron Module""" import torch from torch.autograd import Variable from torch.nn.parameter import Parameter from megatron import get_args from megatron.core import mpu, tensor_parallel _FLOAT_TYPES = (torch.FloatTensor, torch.cuda.FloatTensor) _HAL...
Megatron-LM-master
megatron/model/module.py
import os import torch from megatron import get_args, print_rank_0 from megatron.checkpointing import get_checkpoint_tracker_filename, get_checkpoint_name from megatron.model import BertModel from .module import MegatronModule from megatron.core import mpu from megatron.model.enums import AttnMaskType from megatron.mo...
Megatron-LM-master
megatron/model/realm_model.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. import torch from torch import nn class RMSNorm(torch.nn.Module): def __init__(self, dim: int, eps: float = 1e-6): super().__init__() self.eps = eps self.weight = nn.Parameter(torch.ones(dim)) def _norm(self, x): ...
Megatron-LM-master
megatron/model/rms_norm.py
# Copyright (c) 2021 Microsoft # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # -------------------------------------------------------- # Modified by Chunyuan Li (chunyl@microsoft.com) # Swin Transformer # ----------------------------------...
Megatron-LM-master
megatron/model/vision/esvit_swin_backbone.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Vision Transformer(VIT) model.""" import torch from torch.nn.init import trunc_normal_ from megatron import get_args from megatron.model.utils import get_linear_layer from megatron.model.vision.vit_backbone import VitBackbone, VitMlpHead from megatron....
Megatron-LM-master
megatron/model/vision/classification.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. import math import apex import einops import torch import torch.nn.functional as F from megatron import get_args, print_rank_0 fr...
Megatron-LM-master
megatron/model/vision/inpainting.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Vision Transformer(VIT) model.""" import math import einops import torch import apex import torch.nn.functional as F from megatron import get_args from megatron.model.transformer import ParallelTransformer from megatron.model.utils import ( get_lin...
Megatron-LM-master
megatron/model/vision/vit_backbone.py
import torch.nn.functional as F import torch from megatron import print_rank_0, get_args from megatron.core import mpu from megatron.data.vit_dataset import ClassificationTransform from megatron.data.image_folder import ImageFolder _FEATURE_BANK = None def build_data_loader(dataset, drop_last=True, shuffle=False): ...
Megatron-LM-master
megatron/model/vision/knn_monitor.py
import warnings import torch import torch.nn.functional as F def resize(input, size=None, scale_factor=None, mode='nearest', align_corners=None, warning=True): if warning: if size is not None and align_corners: input_h, input_w = tuple(int...
Megatron-LM-master
megatron/model/vision/utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the Apache license found in the # LICENSE file in the root directory of this source tree. # copied from https://github.com/facebookresearch/dino/blob/main/main_dino.py # reworked/refactored some parts to make it run in Megatron. ...
Megatron-LM-master
megatron/model/vision/dino.py
# Copyright (c) 2023, NVIDIA Corporation. All rights reserved. import math import torch import torch.nn as nn import torch.nn.functional as F from functools import partial from torch.nn.init import trunc_normal_ from megatron.model.transformer import DropPath from megatron.model import LayerNorm class Mlp(nn.Module)...
Megatron-LM-master
megatron/model/vision/mit_backbone.py
# Copyright (c) 2021 Microsoft # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # -------------------------------------------------------- # Swin Transformer # -------------------------------------------------------- import torch import torch...
Megatron-LM-master
megatron/model/vision/swin_backbone.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Blendable dataset.""" import hashlib import os import time import numpy as np import torch from megatron import print_rank_0 from megatron.core import mpu class BlendableDataset(torch.utils.data.Dataset): def __init__(self, datasets, weights, ...
Megatron-LM-master
megatron/data/blendable_dataset.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """BERT Style dataset.""" import numpy as np import torch from megatron import ( get_args, get_tokenizer, mpu, print_rank_0 ) from megatron.data.dataset_utils import ( get_samples_mapping, get_a_and_b_segments, truncate_segmen...
Megatron-LM-master
megatron/data/bert_dataset.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """GPT style dataset.""" import hashlib import os import time import numpy as np import torch from megatron import print_rank_0 from megatron.core import mpu from megatron.data.blendable_dataset import BlendableDataset from megatron.data.dataset_utils i...
Megatron-LM-master
megatron/data/gpt_dataset.py
import itertools import os import pickle import shutil import numpy as np import torch from megatron import get_args from megatron.core import mpu def detach(tensor): return tensor.detach().cpu().numpy() class OpenRetreivalDataStore(object): """ Serializable data structure for holding data for blocks ...
Megatron-LM-master
megatron/data/realm_index.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Dataloaders.""" import random import torch import numpy as np from torch.utils.data import Dataset from megatron import get_args from megatron.core import mpu def build_pretraining_data_loader(dataset, consumed_samples): """Buld dataloader given...
Megatron-LM-master
megatron/data/data_samplers.py
from . import indexed_dataset
Megatron-LM-master
megatron/data/__init__.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors, and NVIDIA. # # 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 ...
Megatron-LM-master
megatron/data/dataset_utils.py
# BSD 3-Clause License # # Copyright (c) Soumith Chintala 2016, # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this #...
Megatron-LM-master
megatron/data/image_folder.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """Wikipedia dataset from DPR code for ORQA.""" from abc import ABC import csv import numpy as np import random import torch from torch.utils.data import Dataset from megatron import print_rank_0, get_args, get_tokenizer from megatron.core import tensor_...
Megatron-LM-master
megatron/data/orqa_wiki_dataset.py
"""AutoAugment data augmentation policy for ImageNet. -- Begin license text. MIT License Copyright (c) 2018 Philip Popien Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, in...
Megatron-LM-master
megatron/data/autoaugment.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. from PIL import Image, UnidentifiedImageError import numpy as np import io import torch try: from torchvision.transforms import InterpolationMode BICUBIC = InterpolationMode.BICUBIC except ImportError: BICUBIC = Image.BICUBIC from torchvision...
Megatron-LM-master
megatron/data/multimodal_dataset.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import os import random import numpy as np import torch import torchvision.transforms as T from torchvision import datasets from megatron import get_args from megatron.data.image_folder import ImageFolder from megatron.data.autoaugment import ImageNetPolicy...
Megatron-LM-master
megatron/data/vit_dataset.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """T5 Style dataset.""" import collections import numpy as np import torch from megatron import get_tokenizer from megatron.data.dataset_utils import ( create_masked_lm_predictions, get_samples_mapping ) class T5Dataset(torch.utils.data.Dataset...
Megatron-LM-master
megatron/data/t5_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Essentially re-written in entirety import os import shutil import struct from enum import Enum from functools import lru_cache from itertoo...
Megatron-LM-master
megatron/data/indexed_dataset.py
import os import time import numpy as np import torch from megatron import print_rank_0 from megatron.core import mpu, tensor_parallel from megatron.data.dataset_utils import create_masked_lm_predictions, pad_and_convert_to_numpy from megatron import get_args, get_tokenizer, print_rank_0 def get_one_epoch_dataloade...
Megatron-LM-master
megatron/data/realm_dataset_utils.py
import itertools import random import numpy as np from torch.utils.data import Dataset from megatron import get_tokenizer from megatron import get_args from megatron.data.dataset_utils import get_indexed_dataset_ from megatron.data.realm_dataset_utils import get_block_samples_mapping def make_attention_mask(source_b...
Megatron-LM-master
megatron/data/ict_dataset.py
import os import time import numpy as np import torch from megatron import get_args, get_tokenizer, print_rank_0 from megatron.core import mpu, tensor_parallel from megatron.data.dataset_utils import create_masked_lm_predictions, \ pad_and_convert_to_numpy from megatron.dat...
Megatron-LM-master
megatron/data/biencoder_dataset_utils.py
# This file isn't really a formal automated test, it's just a place to # put some code used during development and manual testing of # indexed_dataset. from megatron.data import indexed_dataset from megatron.tokenizer import build_tokenizer import argparse import os import sys import torch script_dir = os.path.dirna...
Megatron-LM-master
megatron/data/test/test_indexed_dataset.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. """For backward compatibility, we need the class definitions to deserialize.""" class LossScaler: def __init__(self, scale=1): self.cur_scale = scale class DynamicLossScaler: def __init__(self, init_scale=2**32, ...
Megatron-LM-master
megatron/fp16_deprecated/loss_scaler.py
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. import atexit import copy import io import os import re import subprocess import tempfile from distutils.version import LooseVersion from setuptools import setup, find_packages, Extension from setuptools.command.build_ext import build_ext __version__ = '0...
atex-release
setup.py
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # See LICENSE for license information. from . import nv_norms from . import structured_sparsity
atex-release
atex/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import os import copy import argparse import time from statistics import mean # os.environ['TF_CPP_MIN_LOG_LEVEL'] = "3" import numpy as np import tensorflow as tf from tensorflow.python.compiler.tensorrt import trt_convert as trt SAVEDMODEL_PATH = "...
atex-release
atex/structured_sparsity/tftrt_infer.py
# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # See LICENSE for license information. from . import tf_asp
atex-release
atex/structured_sparsity/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import inspect import numpy as np import os import tempfile import tensorflow as tf from atex.structured_sparsity import tf_asp import shutil from tensorflow.keras import layers, optimizers from tensorflow.python.platform import test def GetSingleLayer...
atex-release
atex/structured_sparsity/tf_asp_optimizer_test.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # WARNING:tensorflow:[TF-ASP] Allowlist is used: (Dense, Conv2D, ) # WARNING:tensorflow:[TF-ASP] Pruning list accepts the "kernel" variable from layer: dense_2 (type=Dense, shape=(128, 8)) # WARNING:tensorflow:[TF-ASP] Pruning list accepts the "kernel" va...
atex-release
atex/structured_sparsity/main.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import tensorflow as tf import numpy as np from tensorflow.keras import layers, optimizers from tensorflow.python.platform import tf_logging from itertools import permutations # A PoC optimizer wrapper to perform pruning with masks. class AspOptimizerWra...
atex-release
atex/structured_sparsity/tf_asp/tf_asp_optimizer.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import os import numpy as np import time import ctypes import subprocess ### support for searching on the GPU gpus_tested = False gpus_found = 0 E = None def set_cpu_device(): global gpus_tested, gpus_found gpus_tested = True gpus_found = 0 def ...
atex-release
atex/structured_sparsity/tf_asp/permuting_search_utils.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. from .tf_asp_optimizer import AspOptimizerWrapper from .tf_asp_optimizer_v2 import AspOptimizerWrapperV2 from .tf_asp_optimizer_v2 import check_pruned_layers from .tf_asp_logging import *
atex-release
atex/structured_sparsity/tf_asp/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import tensorflow as tf SHOW_PRUNING_INFO = tf.compat.v1.logging.WARN # 30 SHOW_PERMUTATION_INFO = 29 SHOW_PERMUTATION_MORE_INFO = 28 SHOW_PERMUTATION_DEBUG_INFO = tf.compat.v1.logging.DEBUG
atex-release
atex/structured_sparsity/tf_asp/tf_asp_logging.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import json import numpy as np import os import pprint import shutil import tempfile import tensorflow as tf import time from google.protobuf import json_format from itertools import count from tensorflow.keras import layers, optimizers, models from tenso...
atex-release
atex/structured_sparsity/tf_asp/permuting_utils.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import numpy as np import tensorflow as tf from itertools import permutations from tensorflow.keras import layers, optimizers from tensorflow.python.platform import tf_logging from .permuting_utils import permute_model from .pruning_utils import get_2to...
atex-release
atex/structured_sparsity/tf_asp/tf_asp_optimizer_v2.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. import tensorflow as tf import numpy as np from tensorflow.keras import layers, optimizers from tensorflow.python.platform import tf_logging def _m4n2_1d(matrix, patterns): m, n = 4, 2 mat = tf.math.abs(tf.reshape(matrix, shape=(-1, m))) pmax = tf...
atex-release
atex/structured_sparsity/tf_asp/pruning_utils.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. from .permuting_search_utils import * ################################################################################################################ # Exhaustive # Try them all # - order of columns within a group doesn't matter # - order of group...
atex-release
atex/structured_sparsity/tf_asp/permuting_search.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== from __future__ import absolute_import from atex.nv_norms.python.ops.nv_norm_ops import fused_layer_norm_op from atex.nv_norms.python.ops.nv_norm_ops import fused_layer_norm_...
atex-release
atex/nv_norms/__init__.py
atex-release
atex/nv_norms/python/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== """Use fused layer and instance norm ops in python.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import os...
atex-release
atex/nv_norms/python/ops/nv_norm_ops.py
atex-release
atex/nv_norms/python/ops/__init__.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== """Tests for fused instance norm ops.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import itertools import ...
atex-release
atex/nv_norms/tests/fused_instance_norm_test.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== """Tests for fused layer norm ops.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import itertools import num...
atex-release
atex/nv_norms/tests/fused_layer_norm_test.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== import argparse from atex import nv_norms import tensorflow as tf import tensorflow_addons as tfa from tensorflow.keras import layers, models parser = argparse.ArgumentParser...
atex-release
atex/nv_norms/examples/sample_instanceN.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== import argparse from atex import nv_norms import tensorflow as tf from tensorflow.keras import layers, models parser = argparse.ArgumentParser(description="Use --nvops to rep...
atex-release
atex/nv_norms/examples/sample_layerN.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== import argparse from atex import nv_norms import tensorflow as tf import time from tensorflow.keras import mixed_precision parser = argparse.ArgumentParser(description='Bench...
atex-release
atex/nv_norms/benchmarks/benchmark_layer_norm.py
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # ============================================================================== import argparse from atex import nv_norms import tensorflow as tf import tensorflow_addons as tfa import time from tensorflow.keras import mixed_precision parser = argparse.A...
atex-release
atex/nv_norms/benchmarks/benchmark_instance_norm.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import print_function import torch import numpy as np from PIL import Image from torch.autograd import Variable import torchvisi...
FastPhotoStyle-master
process_stylization_ade20k_ssn.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import print_function import time import numpy as np from PIL import Image from torch.autograd import Variable import torchvision...
FastPhotoStyle-master
process_stylization.py
# Download code taken from Code taken from https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive/39225039#39225039 import requests def download_file_from_google_drive(id, destination): URL = "https://docs.google.com/uc?export=download" session = requests.Session() response =...
FastPhotoStyle-master
download_models.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ import torch.nn as nn class VGGEncoder(nn.Module): def __init__(self, level): super(VGGEncoder, self).__init__() self.level...
FastPhotoStyle-master
models.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ src = ''' #include "/usr/local/cuda/include/math_functions.h" #define TB 256 #define EPS 1e-7 __device__ bool InverseMat4x4(double m_in[4][4...
FastPhotoStyle-master
smooth_filter.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import division import torch.nn as nn import scipy.misc import numpy as np import scipy.sparse import scipy.sparse.linalg from ...
FastPhotoStyle-master
photo_smooth.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import print_function import argparse import os import torch import process_stylization_ade20k_ssn from torch import nn from phot...
FastPhotoStyle-master
demo_with_ade20k_ssn.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import print_function import argparse import os import torch from photo_wct import PhotoWCT import process_stylization parser = ...
FastPhotoStyle-master
process_stylization_folder.py
import os import torch import torch.nn as nn from torch.utils.serialization import load_lua from models import VGGEncoder, VGGDecoder from photo_wct import PhotoWCT def weight_assign(lua, pth, maps): for k, v in maps.items(): getattr(pth, k).weight = nn.Parameter(lua.get(v).weight.float()) getat...
FastPhotoStyle-master
converter.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ import numpy as np from PIL import Image import torch import torch.nn as nn from models import VGGEncoder, VGGDecoder class PhotoWCT(nn.Module...
FastPhotoStyle-master
photo_wct.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import division from PIL import Image from torch import nn import numpy as np import cv2 from cv2.ximgproc import guidedFilter ...
FastPhotoStyle-master
photo_gif.py
""" Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). """ from __future__ import print_function import argparse import torch import process_stylization from photo_wct import PhotoWCT parser = argparse.A...
FastPhotoStyle-master
demo.py
# Copyright (c) 2020–2021, NVIDIA Corporation. # # 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 agre...
data-science-blueprints-main
churn/generate.py
#!/usr/bin/env python # coding: utf-8 import os default_spark_master = "local[*]" app_name = "data-summary" default_input_file = "churn-etl" default_output_prefix = "" default_input_kind = "parquet" import argparse import pyspark import pyspark.sql.types as T import pyspark.sql.functions as F parser = parser = argp...
data-science-blueprints-main
churn/summarize.py
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2020–2021, NVIDIA Corporation. # # 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 # # Un...
data-science-blueprints-main
churn/do-analytics.py
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2020–2021, NVIDIA Corporation. # # 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 # # Un...
data-science-blueprints-main
churn/churn/etl.py
# Copyright (c) 2020–2021, NVIDIA Corporation. # # 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 agre...
data-science-blueprints-main
churn/churn/augment.py
# Copyright (c) 2020–2021, NVIDIA Corporation. # # 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 agre...
data-science-blueprints-main
churn/churn/eda.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
setup.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/topLevel.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/__init__.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/cli.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/__main__.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/imageContainers/abstractImage.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/imageContainers/__init__.py
# Copyright (c) 2020, NVIDIA CORPORATION. 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 applic...
PixelView-master
PixelView/imageContainers/common.py