minuet.utils.helpers#

Functions

as_tuple(value, *[, size, name])

Make a given value as a tuple of size size

autotune(model, model_cache, data[, cache_path])

Autotune a given torch.nn.Module recursively.

dump_tunable_config(module)

Dump tunable configurations of a torch.nn.Module recursively to a dict

generate_kernel_offsets(ndim, kernel_size, ...)

Generate the kernel weight offsets for SparseConv

load_tunable_config(module, config)

Load tunable configurations for a torch.nn.Module recursively from a dict

set_kernel_map_cache(module, cache)

Set kernel map cache for a given torch.nn.Module recursively.

as_tuple(value: T | Tuple[T, ...], *, size: int = 3, name: str | None = None)#

Make a given value as a tuple of size size

Parameters:
  • value – The value for making a tuple

  • size – The size of the tuple

  • name – The name of the tuple. Useful for showing exceptions.

Returns:

A tuple of size size.

autotune(model: Module, model_cache: KernelMapCache, data: SparseTensor | Iterable[SparseTensor], cache_path: str | None = None)#

Autotune a given torch.nn.Module recursively.

Parameters:
  • model – a given torch.nn.Module instance

  • model_cache – a KernelMapCache instance

  • data – an iterable instance that generates :py:class:’~minuet.tensors.SparseTensor’

  • cache_path – the path to which the autotuned configurations will be stored

Returns:

the original torch.nn.Module instance

dump_tunable_config(module: Module) dict#

Dump tunable configurations of a torch.nn.Module recursively to a dict

Parameters:

module – a given torch.nn.Module instance

Returns:

the configuration dict

generate_kernel_offsets(ndim: int, kernel_size: int | Tuple[int, ...], source_stride: int | Tuple[int, ...], dilation: int | Tuple[int, ...], layout: str = 'minuet')#

Generate the kernel weight offsets for SparseConv

Parameters:
  • ndim – the dimension of each weight offset

  • kernel_size – the kernel size of SparseConv

  • source_stride – the tensor stride of the input

  • dilation – the dilation of SparseConv

  • layout – the layout of the sparse convolution, only minuet, minkowski, and torchsparse are supported

Returns:

a numpy array consists of the generated sparse convolution

load_tunable_config(module: Module, config: dict)#

Load tunable configurations for a torch.nn.Module recursively from a dict

Parameters:
  • module – a given torch.nn.Module instance

  • config – the configuration dict

Returns:

the original torch.nn.Module instance

set_kernel_map_cache(module: Module, cache: KernelMapCache)#

Set kernel map cache for a given torch.nn.Module recursively.

Parameters:
Returns:

the original torch.nn.Module instance