python_code
stringlengths
0
108k
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`586`-compliant **type hint test data.** ''' # ....................{ IMPORTS }...........
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`589`-compliant **type hint test data.** ''' # ....................{ IMPORTS }...........
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`484`-compliant **type hint test data.** Caveats ---------- Note that: * The :pep:`484`-compliant annotated bu...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`604`-compliant **type hint test data.** ''' # ....................{ IMPORTS }...........
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`585`-compliant **type hint test data.** ''' # ....................{ IMPORTS }.........
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **NumPy-specific PEP-noncompliant type hints** (i.e., unofficial type hints declared by the third-party :mod:`numpy` package) test ...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide **PEP-compliant type hints test data.** This submodule predefines low-level global constants whose values are PEP-non...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`484`-compliant PEP-noncompliant type hint test data. :pep:`484`-compliant type hints *mostly* indistinguishabl...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Beartype-specific PEP-noncompliant type hints** (i.e., unofficial type hints supported *only* by the :mod:`beartype.beartype` dec...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Testing-specific **type hint metadata class hierarchy** (i.e., hierarchy of classes encapsulating sample type hints instantiated b...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' :mod:`pytest` **PEP-agnostic type hint utilities.** ''' # ....................{ IMPORTS }................
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`570` **data submodule.** This submodule exercises :pep:`570` support for positional-only parameters implemented...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`563` **cultural data submodule.** This submodule exercises edge-case :pep:`563` support implemented in the :fu...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`563` **poetic data submodule.** This submodule exercises :pep:`563` support implemented in the :func:`beartype....
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide **importable data submodule.** This submodule exercises dynamic importability by providing an importable submodule de...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide **unimportable data submodule.** This submodule exercises dynamic importability by providing an unimportable submodul...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Beartype module getter data submodule.** This submodule predefines module-scoped objects of various types with well-known line ...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Beartype generic callable code data submodule.** This submodule predefines low-level class constants exercising known edge case...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide :pep:`570` **data submodule.** This submodule exercises :pep:`570` support implemented in the :func:`beartype.bearty...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' Project-wide **sample callable** submodule. This submodule predefines sample pure-Python callables exercising known edge cases on ...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project-wide functional static type-checker tests.** This submodule functionally tests the this project's compliance with third...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project-wide nuitka integration tests.** This submodule functionally tests that the third-party ``nuitka`` compiler successfull...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project-wide functional beartype-in-Sphinx tests.** This submodule functionally tests the :func:`beartype.beartype` decorator t...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' :mod:`pytest` **Sphinx test plugin** (i.e., early-time configuration guaranteed to be run by :mod:`pytest` *after* passed command...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project-wide functional beartype-in-Sphinx tests.** This submodule functionally tests the :func:`beartype.beartype` decorator t...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project ``README.rst`` functional tests.** This submodule functionally tests the syntactic validity of this project's top-level...
# Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- # If ex...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Sphinx-specific functional test module** (i.e., module intended to be imported *only* by Sphinx's bundled :mod:`sphinx.ext.autod...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Nuitka-specific functional test script** (i.e., script intended to be compiled by the third-party :mod:`nuitka` compiler). This...
#!/usr/bin/env python3 # --------------------( LICENSE )-------------------- # Copyright (c) 2014-2022 Beartype authors. # See "LICENSE" for further details. ''' **Project-wide functional importation tests.** This submodule functionally tests the this project's behaviour with respect to imp...
import streamlit as st st.set_page_config( page_title="Home", ) st.title('Annotated Transformers') st.write("A collection of annotated transformer architectures in Meta's [PyTorch](https://pytorch.org/) and DeepMind's " "[Haiku](https://github.com/deepmind/dm-haiku), [Optax](https://github.com/deepmind/...
import streamlit as st # Global Variables language='python' # Section for Title st.title('Vision Transformer') st.image( "https://media.giphy.com/media/lr9Xd6IkR8F0mAv0bL/giphy.gif", caption="Animated Vision Transformer", #width=400, # The actual size of most gifs on GIPHY are really small, and using t...
import streamlit as st st.header('Linear') st.write(""" `nn.Linear()` is a class in PyTorch. This class represents a linear transformation of the input data. In other words, it applies a linear function to the input data, which can be used to map the input data to a different space. This is often used in the first ...
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. from pathlib import Path from setuptools import setup # type: ignore setup( name="cc_net", version="1.0.0", pa...
# 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. # """ Main script to download a CC dump, remove duplicates, split by language and filter the documents. The pipeline parameters are described...
# 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. # """ Creates mono-lingual corpus from Wikipedia. """ import functools import re import subprocess import urllib.request from pathlib import ...
# 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. # """ Manipulate files containing one json per line. """ import argparse import collections import contextlib import functools import glob imp...
# 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. # import functools import itertools import logging import os import sys import time import warnings from pathlib import Path from typing impor...
# 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. # import sys import time import warnings from typing import Iterable, Iterator, Sequence, Sized, Tuple, Type import numpy as np HASH_TYPE: T...
# 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. # import base64 import hashlib import itertools import urllib.parse from pathlib import Path from typing import Dict, Iterable, List, Optional...
# 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. # import re import unicodedata UNICODE_PUNCT = { ",": ",", "。": ".", "、": ",", "„": '"', "”": '"', "“": '"', "«":...
# 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. # import logging import subprocess from pathlib import Path from typing import List import func_argparse import numpy as np from cc_net impo...
# 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. # import argparse import time from pathlib import Path from typing import Dict, List, Optional, Sequence, Tuple, Union import kenlm # type: ...
# 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. #
# 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. # import time from typing import Dict, Optional import sacremoses # type: ignore from cc_net import jsonql, text_normalizer class RobustT...
# 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. # """ Tools to remove duplicate paragraphs across one or several shards. """ import argparse import gc import hashlib import logging import m...
# 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. # import contextlib import functools import logging import re import tempfile import time import urllib.request from pathlib import Path from ...
# 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. # import func_argparse import cc_net.mine def main(): func_argparse.parse_and_call(cc_net.mine.get_main_parser()) if __name__ == "__...
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import argparse import collections from pathlib import Path from typing import Dict, Optional import fasttext # type: igno...
# 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. # import contextlib import functools import gzip import logging import multiprocessing from collections import defaultdict from pathlib import...
# 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. # """ This code is used to train a fastText classifier to label document with DMOZ categories. The data, distributed under the cc-by 3.0 lice...
# 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. # """ Tools to search sentences in CC similar to sentences in another corpus. """ import functools import logging import math import subproce...
# 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. # import json from pathlib import Path from typing import Iterable, Sequence from cc_net import dedup, jsonql from cc_net.dedup import str_ha...
# 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. # import cc_net.text_normalizer as txt def test_unicode_punct(): weird = ",。、„”“«»1」「《》´∶:?!();–—.~’…━〈〉【】%" replaced = ',.,""""""""...
# 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. # from pathlib import Path from cc_net import process_wet_file def test_parsing(): sample = Path(__file__).parent / "data" / "sample.wa...
# 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. # import numpy as np import pytest from cc_net.flat_hash_set import HASH_TYPE, FlatHashSet, NaiveHashSet def as_dict(flat_hash_set) -> dict...
# 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. # import pytest def _request_is_disabled(self, *args, **kwargs): raise Exception( f"Your code tried to call 'request' with: {arg...
# 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. # #
# 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. # import time from cc_net import jsonql, regroup def check_regroup(tmp_path, regroup_fn, check_blocks_boundaries=False): n_shards = 4 ...
# 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. # import io from pathlib import Path from typing import Sequence import numpy as np import pytest from cc_net import jsonql def bar(small_...
# 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. # import json from pathlib import Path import pytest import cc_net import cc_net.minify as minify from cc_net import jsonql, process_wet_fil...
# 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. # import inspect import pickle from pathlib import Path import pytest from cc_net import dedup, jsonql, perplexity, split_by_lang, tokenizer...
from cross_vit_flax.cross_vit_flax import CrossViT
import flax.linen as nn import jax import jax.numpy as jnp from jax.numpy import einsum from typing import Any, Callable from einops import rearrange, repeat def exists(val): return val is not None def default(val, d): return val if exists(val) else d class PreNorm(nn.Module): fn: Callable @nn.co...
import torch import colossalai from colossalai.trainer import Trainer, hooks from colossalai.utils import MultiTimer from colossalai.logging import disable_existing_loggers, get_dist_logger from colossalai.core import global_context as gpc from colossalai.zero.init_ctx import ZeroInitContext from utils.build_dataload...
import copy from itertools import chain from datasets import load_dataset from torch.utils.data import DataLoader, DistributedSampler from torch.distributed import get_world_size from transformers import BloomTokenizerFast, default_data_collator from .hugging_face_config import CFG def build_dataloaders(cfg: CFG): ...
from typing import Optional, ClassVar from dataclasses import dataclass, field @dataclass class CFG: """ Configuration for data loader. """ train_dataset_name: Optional[str] = field( default="codeparrot/codeparrot-train-v2-near-dedup", metadata={"help": "Path to Hugging Face training...
from colossalai.amp import AMP_TYPE from colossalai.zero.shard_utils import TensorShardStrategy # Colossal AI Global Config EPOCHS = 1 LEARNING_RATE = 0.001 zero = dict( model_config = dict( shard_strategy = TensorShardStrategy(), tensor_placement_policy = 'auto', reuse_fp16_shard = True ...
# 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. import os from setuptools import setup, find_packages def read(fname): return open(os.path.join(os.path.dirname(__file__), fname))....
# 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. import pytest import torch import bitsandbytes as bnb from itertools import product from bitsandbytes import functional as F def setup(...
# 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. import os import time import shutil import uuid import pytest import ctypes import torch import bitsandbytes as bnb import bitsandbytes.fu...
# 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. import pytest import torch import bitsandbytes as bnb from itertools import product from bitsandbytes import functional as F @pytest.m...
# 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. from .optim import adam from .nn import modules __pdoc__ = {'libBitsNBytes' : False, 'optim.optimizer.Optimizer8bit': False, ...
# 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. import os import random import math import ctypes as ct import torch from torch import Tensor from typing import Tuple lib = ct.cdll.Load...
# 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. from .modules import StableEmbedding, Embedding
# 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. import torch from typing import Optional from torch import Tensor from torch.nn.parameter import Parameter import torch.nn.functional as...
# 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. import torch from bitsandbytes.optim.optimizer import Optimizer1State class RMSprop(Optimizer1State): def __init__(self, params, lr=1...
# 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. from bitsandbytes.optim.optimizer import Optimizer2State class LAMB(Optimizer2State): def __init__(self, params, lr=1e-3, bias_correc...