--- title: Utils keywords: fastai sidebar: home_sidebar summary: "Basic utilities with few dependencies." ---
{% raw %}

    %load_ext autoreload
    %autoreload 2
    %matplotlib inline

At training time, we will typically want to put the model and the current mini batch on the GPU. When developing on a CPU, a GPU isn't available, so we define a variable that will automatically find the right device. This goes in utils rather than core to avoid circular imports with the callbacks module.

    DEVICE

    device(type='cpu')

#### `hasarg`[source]

> `hasarg`(`func`, `arg`)

    Checks if a function has a given argument.
    Works with args and kwargs as well if you exclude the
    stars. See example below.

    Parameters
    ----------
    func: function
    arg: str
        Name of argument to look for.

    Returns
    -------
    bool

    Example
    -------
    def foo(a, b=6, *args):
        return

    >>> hasarg(foo, 'b')
    True

    >>> hasarg(foo, 'args')
    True

    >>> hasarg(foo, 'c')
    False

#### `quick_stats`[source]

> `quick_stats`(`x`, `digits`=`3`)

    Quick wrapper to get mean and standard deviation of a tensor.

    Parameters
    ----------
    x: torch.Tensor
    digits: int
        Number of digits to round mean and standard deviation to.

    Returns
    -------
    tuple[float]

{% endraw %}