metric
Compute a specified metric for the given tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor. |
required |
metric_name
|
str
|
The name of the metric to compute. Supported metrics: - "norm", "batch_norm", "l2_norm", "batch_l2_norm", "l1_norm", "batch_l1_norm" - "max", "batch_max", "min", "batch_min", "sum", "batch_sum", "prod", "batch_prod" |
required |
*args
|
Additional arguments for specific metrics. |
()
|
|
**kwargs
|
Additional arguments for specific metrics. |
()
|
Returns:
Type | Description |
---|---|
Tensor
|
The computed metric. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the input tensor or metric name is None. |
ValueError
|
If an unknown metric name is provided. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the norm of a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
p
|
Union[int, float, str, Any]
|
The norm order (e.g., 1, 2, "inf"). |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The computed norm. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the input tensor is not 1D. |
ValueError
|
If the nuclear norm is requested for a 1D tensor. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the norm of a batch of tensors along a specified dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
p
|
Union[int, float, str, Any]
|
The norm order (e.g., 1, 2, "nuc"). |
required |
dim
|
int
|
The dimension along which to compute the norm. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The computed norms. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the input tensor is not 2D or the dimension is invalid. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the L1 norm of a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The L1 norm. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the L1 norm of a batch of tensors along a specified dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the L1 norm. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The L1 norms. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the L2 norm of a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The L2 norm. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the L2 norm of a batch of tensors along a specified dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the L2 norm. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The L2 norms. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the sum of elements in a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The sum of elements. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the sum of elements along a specified dimension in a batch of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the sum. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The sums. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the product of elements in a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The product of elements. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the product of elements along a specified dimension in a batch of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the product. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The products. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the maximum value in a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The maximum value. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the maximum values along a specified dimension in a batch of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the maximum values. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The maximum values. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the minimum value in a 1D tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 1D tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The minimum value. |
Source code in tinybig/koala/linear_algebra/metric.py
Compute the minimum values along a specified dimension in a batch of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input 2D tensor. |
required |
dim
|
int
|
The dimension along which to compute the minimum values. Default is 1. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
The minimum values. |