id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
145,143
import functools as ft import inspect import weakref from collections.abc import Callable from typing import Optional, overload, TypeVar from typing_extensions import ParamSpec from .._custom_types import sentinel from .._eval_shape import filter_eval_shape from .._module import field, Module, module_update_wrapper fro...
null
145,144
import functools as ft import inspect import weakref from collections.abc import Callable from typing import Optional, overload, TypeVar from typing_extensions import ParamSpec from .._custom_types import sentinel from .._eval_shape import filter_eval_shape from .._module import field, Module, module_update_wrapper fro...
Asserts that the wrapped callable is not called more than `max_traces` times. The typical use-case for this is to check that a JIT-compiled function is not compiled more than `max_traces` times. (I.e. this function can be used to guard against bugs.) In this case it should be placed within the JIT wrapper. !!! Example ...
145,145
import functools as ft import inspect import weakref from collections.abc import Callable from typing import Optional, overload, TypeVar from typing_extensions import ParamSpec from .._custom_types import sentinel from .._eval_shape import filter_eval_shape from .._module import field, Module, module_update_wrapper fro...
Given a function wrapped in [`equinox.debug.assert_max_traces`][], return the number of times which it has been traced so far.
145,146
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,147
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,148
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,149
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,150
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,151
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,152
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,153
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
null
145,154
import functools as ft from collections.abc import Callable from typing import Any, Optional, Union import jax import jax._src.pretty_printer as pp import jax._src.source_info_util as source_info_util import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.m...
Marks a function as not being inlined into a larger computation. This can help to reduce compile time at the expense of increased runtime. `fn` can be any callable `PyTree[Any] -> PyTree[Any]`. In addition `fn` itself may be any (callable) PyTree; any JAX arrays in `fn`'s PyTree are also treated as inputs to the noinli...
145,155
import jax.numpy as jnp from ._finalise_jaxpr import finalise_fn def finalise_fn(fn): """Wraps a function to perform finalisation. (In a manner similar to e.g. `jax.vmap` wrapping a function to perform batching.) """ def _finalise_fn(*args): jaxpr, struct = jax.make_jaxpr(fn, return_shape=True...
Export a JAX function to ONNX. !!! Warning This is experimental and may be removed or changed. !!! Example ```python import equinox.internal as eqxi import jax.numpy as jnp def f(x, y): return x + y onnx_f = eqxi.to_onnx(f) result = onnx_f(jnp.array(1), jnp.array(2)) ```
145,156
import functools as ft import math import operator import typing from collections.abc import Callable, Sequence from typing import Any, cast, Optional, TypeVar, Union import jax import jax.core import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, ArrayLike, Bool from .....
Run the while loop, saving checkpoints whenever the controller (`_should_save_residual`) requires.
145,157
import functools as ft import math import operator import typing from collections.abc import Callable, Sequence from typing import Any, cast, Optional, TypeVar, Union import jax import jax.core import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, ArrayLike, Bool from .....
Time for the complicated bit: iterate backward through a checkpointed while loop, loading values from checkpoints and using treeverse to toggle between forward and backward steps.
145,158
from collections.abc import Callable, Sequence from typing import Any, Literal, Optional, TypeVar, Union import jax import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool from .bounded import bounded_while_loop from .checkpointed import checkpointed_while_loop from ....
A better while loop, supporting (1) reverse-mode autodifferentiation; (2) online checkpointing schemes; (3) efficient in-place scatters (normally XLA tends to make unnecessary copies). **Arguments:** - `cond_fun`: As `lax.while_loop`. - `body_fun`: As `lax.while_loop`. - `init_val`: As `lax.while_loop`. - `max_steps`: ...
145,159
from collections.abc import Callable, Sequence from typing import Any, Literal, Optional, TypeVar, Union import jax import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool from .bounded import bounded_while_loop from .checkpointed import checkpointed_while_loop from ....
As `jax.lax.scan`, but with optional checkpointing to reduce memory usage. **Arguments:** - `f`: As `jax.lax.scan`. - `init`: As `jax.lax.scan`. - `xs`: As `jax.lax.scan`. - `length`: As `jax.lax.scan`. - `buffers`: If passed, then every leaf of `tree_leaves(buffers(init))` must be an array; all such arrays become buff...
145,160
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,161
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,162
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,163
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,164
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,165
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,166
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,167
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,168
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
null
145,169
import itertools as it from typing import Any, TYPE_CHECKING, Union import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, Bool fr...
As `buffer.at[...].set(...)`, and supports the `pred` argument even if it is an array. This is primarily useful when calling a buffer-using cond or body function outside of a while loop, for any reason.
145,170
import inspect import types from typing import Any, Optional import jax.tree_util as jtu from .._module import Module def _make_cell(val): fn = lambda: val return fn.__closure__[0] # pyright: ignore
null
145,171
import inspect import types from typing import Any, Optional import jax.tree_util as jtu from .._module import Module def _adjust_function_closure(fn, closure): out = types.FunctionType( code=fn.__code__, globals=fn.__globals__, name=fn.__name__, argdefs=fn.__defaults__, clo...
null
145,172
import inspect import types from typing import Any, Optional import jax.tree_util as jtu from .._module import Module def _fixup_closure(leaf): if isinstance(leaf, types.FunctionType): return _Closure(leaf) else: return leaf The provided code snippet includes necessary dependencies for implemen...
Convert all function closures into pytree nodes. **Arguments:** - `tree`: Any pytree. **Returns:** A copy of `tree`, where all function closures have been replaced by a new object that is (a) callable like the original function, but (b) iterates over its `__closure__` as subnodes in the pytree. !!! Example ```python de...
145,173
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,174
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,175
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,176
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
For wrapping def_impl and def_abstract_eval. These can now take arbitrary inputs and outputs.
145,177
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
The input tangents (to the wrapped rule) will be a PyTree with the same structure as the input primals. `None` indicates symbolic zero tangents, in particular for non-JAX-array-likes. The output tangents are expected to match the output primals, necessarily with `None` for all non-JAX-array-likes.
145,178
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
The `inputs` to the transpose rule are a PyTree like the primal inputs, with `UndefinedPrimal`s where appropriate. The `cts_out` passed to the transpose rule are a PyTree like the primal output, with `None` for symbolic zero cotangents, in particular for non-JAX-array-likes. The output from the rule should be a PyTree ...
145,179
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
The input batch axes (to the wrapped rule) will be a PyTree with the same structure as the input primals, with `None` for all non-JAX-arrays. The output batch axes are expected to match the output primals, with `None` for all non-JAX-arrays.
145,180
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,181
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,182
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,183
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,184
import functools as ft from typing import Any import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._filters import combine, is_array, is_array_like, partition from .._...
null
145,185
from .._module import Module from .._pretty_print import text as pp_text class Module(metaclass=_ModuleMeta): """Base class. Create your model by inheriting from this. This will make your model a [dataclass](https://docs.python.org/3/library/dataclasses.html) and a [pytree](https://jax.readthedocs.io/...
Creates a JAXable object whose `str(...)` is the specified string.
145,186
import jax import jax.numpy as jnp from jaxtyping import Array def nextafter(x: Array) -> Array: """Returns the floating point number after `x`.""" y = jnp.nextafter(x, jnp.inf) # Flush denormal to normal. # Our use for these is to handle jumps in the vector field. Typically that means # there will ...
null
145,187
import jax import jax.numpy as jnp from jaxtyping import Array def prevbefore(x: Array) -> Array: """Returns the floating point number before `x`.""" y = jnp.nextafter(x, -jnp.inf) return jnp.where(x == 0, -jnp.finfo(x.dtype).tiny, y) # pyright: ignore def prevbefore_jvp(primals, tangents): (x,) = pri...
null
145,188
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
null
145,189
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
Identity function, which raises an error if it is transformed in any way. (i.e. in `jax.grad`, `jax.vmap` etc.) This is useful at the end of the `impl` rule for higher-order final-style primitives, for checking that no other tracers were captured via closure.
145,190
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
null
145,191
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
null
145,192
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
null
145,193
import functools as ft from typing import Optional import jax import jax.core import jax.interpreters.ad as ad import jax.interpreters.batching as batching import jax.interpreters.mlir as mlir import jax.tree_util as jtu from jaxtyping import PyTree from .._ad import nondifferentiable as nondifferentiable from .._erro...
null
145,194
import operator from collections.abc import Callable from typing import Any, Optional, TYPE_CHECKING import jax import jax.tree_util as jtu def _equal_code(fn1: Optional[Callable], fn2: Optional[Callable]): def _set_binary(base, name: str, op: Callable[[Any, Any], Any]) -> None: def fn(self, other): if isi...
null
145,195
import operator from collections.abc import Callable from typing import Any, Optional, TYPE_CHECKING import jax import jax.tree_util as jtu def _set_unary(base, name: str, op: Callable[[Any], Any]) -> None: def fn(self): return ω( jtu.tree_map(op, self.ω, is_leaf=self.is_leaf), is_l...
null
145,196
import operator from collections.abc import Callable from typing import Any, Optional, TYPE_CHECKING import jax import jax.tree_util as jtu def _rev(op): def __rev(x, y): return op(y, x) return __rev
null
145,197
import operator from collections.abc import Callable from typing import Any, Optional, TYPE_CHECKING import jax import jax.tree_util as jtu def _equal_code(fn1: Optional[Callable], fn2: Optional[Callable]): """Checks whether fn1 and fn2 both have the same code. It's essentially impossible to see if two function...
null
145,198
from collections.abc import Callable, Sequence from typing import Any, TypeVar import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, PyTree, Scalar from .._eval_shape import filter_eval_shape from .._filters import is_array from ._nontraceable import nonbatchable _X = Ty...
null
145,199
from collections.abc import Callable, Sequence from typing import Any, TypeVar import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, PyTree, Scalar from .._eval_shape import filter_eval_shape from .._filters import is_array from ._nontraceable import nonbatchable def fi...
null
145,200
from collections.abc import Callable, Sequence from typing import Any, TypeVar import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, PyTree, Scalar from .._eval_shape import filter_eval_shape from .._filters import is_array from ._nontraceable import nonbatchable def fi...
null
145,201
from collections.abc import Callable, Sequence from typing import Any, TypeVar import jax.lax as lax import jax.numpy as jnp import jax.tree_util as jtu from jaxtyping import Array, PyTree, Scalar from .._eval_shape import filter_eval_shape from .._filters import is_array from ._nontraceable import nonbatchable def fi...
null
145,202
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree def _impl_finalisation(prim: jax.core.Primitive, *args, **kwargs): primitive_finalisations ...
null
145,203
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p from ..debug._announce_trans...
null
145,204
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p from ..debug._announce_trans...
null
145,205
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p from ..debug._announce_trans...
null
145,206
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree def finalise_jaxpr(jaxpr: jax.core.ClosedJaxpr) -> jax.core.ClosedJaxpr: """A jaxpr-to-...
As `jax.make_jaxpr`, but finalises the result.
145,207
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p from ..debug._announce_trans...
null
145,208
import functools as ft from collections.abc import Callable from typing import Any, cast, Literal, overload, Union import jax import jax.core import jax.custom_derivatives import jax.tree_util as jtu from jaxtyping import PyTree from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p from ..debug._announce_trans...
null
145,209
from collections.abc import Callable from typing import Any, Optional, Union import jax import jax.numpy as jnp import jax.tree_util as jtu import numpy as np from jaxtyping import PyTree The provided code snippet includes necessary dependencies for implementing the `is_inexact_array_like` function. Write a Python fun...
Returns `True` if `element` is an inexact JAX array, an inexact NumPy array, or a Python `float` or `complex`.
145,210
import logging from functools import partial from pathlib import Path from typing import Any, Dict, List, Tuple, Union import click import numpy as np from datasets import Dataset, load_dataset from transformers import ( AutoModelForCausalLM, AutoTokenizer, DataCollatorForLanguageModeling, PreTrainedTok...
null
145,211
import logging import re from typing import List, Tuple import torch import numpy as np from transformers import ( AutoModelForCausalLM, AutoTokenizer, Pipeline, PreTrainedModel, PreTrainedTokenizer, ) from transformers.utils import is_tf_available from .consts import END_KEY, PROMPT_FOR_GENERATION_...
Loads the model and tokenizer so that it can be used for generating responses. Args: pretrained_model_name_or_path (str): name or path for model Returns: Tuple[PreTrainedModel, PreTrainedTokenizer]: model and tokenizer
145,212
import logging import re from typing import List, Tuple import torch import numpy as np from transformers import ( AutoModelForCausalLM, AutoTokenizer, Pipeline, PreTrainedModel, PreTrainedTokenizer, ) from transformers.utils import is_tf_available from .consts import END_KEY, PROMPT_FOR_GENERATION_...
Gets the token ID for a given string that has been added to the tokenizer as a special token. When training, we configure the tokenizer so that the sequences like "### Instruction:" and "### End" are treated specially and converted to a single, new token. This retrieves the token ID each of these keys map to. Args: tok...
145,213
import logging import re from typing import List, Tuple import torch import numpy as np from transformers import ( AutoModelForCausalLM, AutoTokenizer, Pipeline, PreTrainedModel, PreTrainedTokenizer, ) from transformers.utils import is_tf_available from .consts import END_KEY, PROMPT_FOR_GENERATION_...
Given an instruction, uses the model and tokenizer to generate a response. This formats the instruction in the instruction format that the model was fine-tuned on. Args: instruction (str): _description_ model (PreTrainedModel): the model to use tokenizer (PreTrainedTokenizer): the tokenizer to use Returns: str: respons...
145,214
import functools from functools import partial import math import os import copy import torch import torch.nn.functional as F from torch import nn import torchvision from torchvision import transforms def batch_normalize_images(input_images, mean, std): return (input_images - mean.view(1, -1, 1, 1)) / std....
null
145,215
import functools from functools import partial import math import os import copy import torch import torch.nn.functional as F from torch import nn import torchvision from torchvision import transforms hyp = { 'opt': { 'bias_lr': 1.525 * bias_scaler/512, # TODO: Is there maybe a better way to express ...
null
145,216
import functools from functools import partial import math import os import copy import torch import torch.nn.functional as F from torch import nn import torchvision from torchvision import transforms def batch_cutmix(inputs, targets, patch_size): with torch.no_grad(): batch_permuted = torch.randperm(inputs...
null
145,217
import functools from functools import partial import math import os import copy import torch import torch.nn.functional as F from torch import nn import torchvision from torchvision import transforms hyp = { 'opt': { 'bias_lr': 1.525 * bias_scaler/512, # TODO: Is there maybe a better way to express ...
null
145,218
import functools from functools import partial import math import os import copy import torch import torch.nn.functional as F from torch import nn import torchvision from torchvision import transforms def print_training_details(columns_list, separator_left='| ', separator_right=' ', final="|", column_heads_only=Fals...
null
145,219
def add(a,b): return a+b
null
145,220
def multiply(a,b): return a*b
null
145,221
from dataclasses import dataclass, field import random def price_func(): return float(random.randrange(20, 40))
null
145,222
import heapq def printNodes(node, val=''): # huffman code for current node newVal = val + str(node.huff) # if node is not an edge node # then traverse inside it if(node.left): printNodes(node.left, newVal) if(node.right): printNodes(node.right, newVal) # if node is edge node then # display its huffma...
null
145,223
from __future__ import division, print_function import os import io import re import sys import math import time import heapq import runpy import types import shlex import bisect import pprint import random import string import decimal import pathlib import asyncio import operator import builtins import argparse import...
Prints the values to a stream, or to sys.stdout by default.
145,224
def aggressiveCows(stalls, k): def isValid(mid): count = 1 # count of cows lastPosition = stalls[0] # position where we recently placed the cow for i in range(1, len(stalls)): if stalls[i] - lastPosition >= mid: # checking if we can place cow in this i'th position count += 1 if count == k: return ...
null
145,225
def isValid(arr, M, mid): amount = 0 for height in arr: if height > mid: amount += height - mid return amount >= M
null
145,226
def chopped_off(heights, t): return sum(max(i-t, 0) for i in heights) def search_optimal_height(heights, threshold): lo = min(heights) - threshold hi = max(heights) while lo <= hi: mid = (hi + lo)//2 if chopped_off(heights, mid) >= threshold: lo = mid+1 else: ...
null
145,227
def flatten(head): while head: if not head.next: return head if head.data <= head.next.data: a = head b = head.next c = b.next else: a = head.next b = head c = a.next head = head.next whil...
null
145,228
from os import * from sys import * from collections import * from math import * def mergeSort(arr): if len(arr) > 1: # mid is the point where the array is divided into two subarrays mid = len(arr)//2 left = arr[:mid] right = arr[mid:] # Sort the two halves mergeSor...
null
145,229
from os import * from sys import * from collections import * from math import * arr = takeInput() def takeInput() : arr = list(map(int, stdin.readline().strip().split(" "))) return arr
null
145,230
def insertionsort(a): for i in range(1, len(a)): currrent_element = a[i] position = i while currrent_element < a[position-1] and position > 0: a[position] = a[position-1] position -= 1 a[position] = currrent_element return a
null
145,231
def printList(head): if head is None: print(' ') return curr_node = head while curr_node: print(curr_node.data, end = " ") curr_node = curr_node.next print(' ')
null
145,232
def partition(arr, l, r): p = l while l <= r: while arr[l] <= arr[p] and l < r: l += 1 while arr[r] >= arr[p] and r > l: r -= 1 if l < r: arr[l], arr[r] = arr[r], arr[l] l += 1 r -= 1 arr[p], arr[r] = arr[r], arr[p] return r def quicksort(...
null
145,233
def countingSort(array): size = len(array) output = [0] * size count = [0] * 10 for i in range(0, size): count[array[i]] += 1 for i in range(1, 10): count[i] += count[i - 1] i = size - 1 while i >= 0: output[count[array[i]] - 1] = array[i] count...
null
145,234
def bubble_sort(arr): n = len(arr) for i in range(n): # Flag to optimize by breaking the loop if no swaps are performed in an iteration swapped = False for j in range(0, n-i-1): if arr[j] > arr[j+1]: # Swap the elements arr[j], arr[j...
null
145,235
import collections def LeftView(root): final_ans = [] q = collections.deque() q.append(root) if not root: return final_ans while q: final_ans.append(q[0].data) n = len(q) for i in range(n): node = q.popleft() if node.left: q.append(node.left) ...
null
145,236
def getTreeTraversal(root): res = [] tmp = [] def inorder(root): if not root: return inorder(root.left) tmp.append(root.data) inorder(root.right) inorder(root) res.append(tmp) tmp = [] def preorder(root): if not root: return tmp.app...
null
145,237
def serialize(root, A): #code here def dfs(root): if not root: A.append(-1) return A.append(root.data) dfs(root.left) dfs(root.right) dfs(root) return A
null
145,238
def deSerialize(A): #code here i = 0 def dfs(): nonlocal i if i >= len(A): return None if A[i] == -1: i += 1 return None root = Node(A[i]) i += 1 root.left = dfs() root.right = dfs() return root return dfs()
null
145,239
def findmatch(mat, pat, x, y, nrow, ncol, level) : l = len(pat) # Pattern matched if (level == l) : return True # Out of Boundary if (x < 0 or y < 0 or x >= nrow or y >= ncol) : return False # If grid matches with a letter # while recursion if (mat[x][y] == pat[level]) : # Marking this cell as visite...
null
145,240
import argparse import builtins import math import os import random import shutil import time import warnings from functools import partial import torch import torch.nn as nn import torch.nn.parallel import torch.backends.cudnn as cudnn import torch.distributed as dist import torch.optim import torch.multiprocessing as...
null
145,242
import math import torch import torch.nn as nn from functools import partial, reduce from operator import mul from timm.models.vision_transformer import VisionTransformer, _cfg from timm.models.layers.helpers import to_2tuple from timm.models.layers import PatchEmbed class VisionTransformerMoCo(VisionTransformer): ...
null
145,244
import math import torch import torch.nn as nn from functools import partial, reduce from operator import mul from timm.models.vision_transformer import VisionTransformer, _cfg from timm.models.layers.helpers import to_2tuple from timm.models.layers import PatchEmbed class VisionTransformerMoCo(VisionTransformer): ...
null