Spike Compressors#

将浮点数表示的脉冲张量转换为更紧凑的表示形式的压缩器。


Compressors that convert spike tensors represented in floating-point numbers into more compact representations.

class spikingjelly.activation_based.memopt.compress.SpikeCompressor[源代码]#

基类:ABC

API Language - 中文 | English


  • 中文

无状态张量压缩器的抽象基类。compress 返回的 payload 必须包含 decompress 恢复 shape、dtype 和 device 所需的信息。实现不得把单次调用的 信息保存在实例中。


  • English

Abstract base class for stateless tensor compressors. The payload returned by compress must contain everything decompress needs to restore the shape, dtype, and device. Implementations must not keep per-call data on the instance.

abstractmethod compress(x)[源代码]#

API Language - 中文 | English


  • 中文

压缩一个张量。

参数:

x (Tensor) -- 输入张量;支持的 shape、dtype 和 device 由实现决定。

返回:

可传给 decompress() 的 payload。

返回类型:

object


  • English

Compress one tensor.

参数:

x (Tensor) -- Input tensor; supported shapes, dtypes, and devices are defined by the implementation.

返回:

Payload accepted by decompress().

返回类型:

object

abstractmethod decompress(packed)[源代码]#

API Language - 中文 | English


  • 中文

恢复一个张量。

参数:

packed (object) -- compress() 返回的 payload。

返回:

恢复 shape、dtype 和 device 的张量。

返回类型:

Tensor


  • English

Restore one tensor.

参数:

packed (object) -- Payload returned by compress().

返回:

Tensor restored to its original shape, dtype, and device.

返回类型:

Tensor

class spikingjelly.activation_based.memopt.compress.BooleanSpikeCompressor[源代码]#

基类:SpikeCompressor

API Language - 中文 | English


  • 中文

将严格取值为 0 或 1 的脉冲张量保存为 bool。支持 PyTorch 可用的 CPU 和加速器 device,并在解压时恢复原 shape、dtype 和 device。


  • English

Store spike tensors whose values are strictly 0 or 1 as bool. It works on CPU and accelerator devices supported by PyTorch, and restores the original shape, dtype, and device.

compress(x)[源代码]#

API Language - 中文 | English


  • 中文

将严格二值张量转换为 bool。

参数:

x (Tensor) -- 任意 shape 和 device 的张量,元素必须为 0 或 1。

返回:

bool 张量、原 dtype 和原 shape。

返回类型:

object


  • English

Convert a strictly binary tensor to bool.

参数:

x (Tensor) -- Tensor of any shape and device whose values must be 0 or 1.

返回:

Boolean tensor, original dtype, and original shape.

返回类型:

object

decompress(packed)[源代码]#

API Language - 中文 | English


  • 中文

恢复 compress() 生成的 payload。

参数:

packed (object) -- bool 张量、原 dtype 和原 shape。

返回:

恢复原 shape、dtype 和 device 的张量。

返回类型:

Tensor


  • English

Restore a payload produced by compress().

参数:

packed (object) -- Boolean tensor, original dtype, and original shape.

返回:

Tensor with its original shape, dtype, and device.

返回类型:

Tensor

class spikingjelly.activation_based.memopt.compress.Uint8SpikeCompressor[源代码]#

基类:SpikeCompressor

API Language - 中文 | English


  • 中文

将取值范围为 0 到 255 的整数脉冲保存为 uint8,并在解压时恢复原 shape、dtype 和 device。


  • English

Store integer-valued spikes in the range 0 to 255 as uint8, then restore their original shape, dtype, and device.

compress(x)[源代码]#

API Language - 中文 | English


  • 中文

将整数值张量转换为 uint8。

参数:

x (Tensor) -- 任意 shape 和 device 的张量,元素必须是 [0, 255] 内的整数。

返回:

uint8 张量、原 dtype 和原 shape。

返回类型:

object


  • English

Convert an integer-valued tensor to uint8.

参数:

x (Tensor) -- Tensor of any shape and device with integer values in [0, 255].

返回:

Uint8 tensor, original dtype, and original shape.

返回类型:

object

decompress(packed)[源代码]#

API Language - 中文 | English


  • 中文

恢复 compress() 生成的 payload。

参数:

packed (object) -- uint8 张量、原 dtype 和原 shape。

返回:

恢复原 shape、dtype 和 device 的张量。

返回类型:

Tensor


  • English

Restore a payload produced by compress().

参数:

packed (object) -- Uint8 tensor, original dtype, and original shape.

返回:

Tensor with its original shape, dtype, and device.

返回类型:

Tensor

class spikingjelly.activation_based.memopt.compress.BitSpikeCompressor[源代码]#

基类:SpikeCompressor

API Language - 中文 | English


  • 中文

将 8 个严格取值为 0 或 1 的脉冲打包进一个字节。CPU 和 CUDA 使用相同的 PyTorch 张量运算,且该路径可被 torch.compile 捕获。解压时恢复原 shape、dtype 和 device。


  • English

Pack eight spikes whose values are strictly 0 or 1 into one byte. CPU and CUDA use the same PyTorch tensor operations, and the path can be captured by torch.compile. Decompression restores the original shape, dtype, and device.

compress(x)[源代码]#

API Language - 中文 | English


  • 中文

将严格二值张量按每 8 个元素一组打包。

参数:

x (Tensor) -- 任意 shape 和 device 的张量,元素必须为 0 或 1。

返回:

打包后的字节张量、原 dtype 和原 shape。

返回类型:

object


  • English

Pack a strictly binary tensor in groups of eight values.

参数:

x (Tensor) -- Tensor of any shape and device whose values must be 0 or 1.

返回:

Packed byte tensor, original dtype, and original shape.

返回类型:

object

decompress(packed)[源代码]#

API Language - 中文 | English


  • 中文

恢复 compress() 生成的 payload。

参数:

packed (object) -- 字节张量、原 dtype 和原 shape。

返回:

恢复原 shape、dtype 和 device 的张量。

返回类型:

Tensor


  • English

Restore a payload produced by compress().

参数:

packed (object) -- Byte tensor, original dtype, and original shape.

返回:

Tensor with its original shape, dtype, and device.

返回类型:

Tensor

class spikingjelly.activation_based.memopt.compress.SparseSpikeCompressor(dtype=torch.int64)[源代码]#

基类:SpikeCompressor

API Language - 中文 | English


  • 中文

只保存严格二值脉冲中非零元素的一维索引。适合稀疏输入;解压时恢复原 shape、dtype 和 device。

参数:

dtype (dtype) -- 保存索引的整数 dtype。


  • English

Store only the flattened indices of nonzero elements in a strictly binary spike tensor. This suits sparse inputs; decompression restores the original shape, dtype, and device.

参数:

dtype (dtype) -- Integer dtype used for stored indices.

compress(x)[源代码]#

API Language - 中文 | English


  • 中文

保存严格二值张量中非零元素的一维索引。

参数:

x (Tensor) -- 任意 shape 和 device 的张量,元素必须为 0 或 1。

返回:

非零索引、原 dtype 和原 shape。

返回类型:

object


  • English

Store the flattened indices of nonzero values in a strictly binary tensor.

参数:

x (Tensor) -- Tensor of any shape and device whose values must be 0 or 1.

返回:

Nonzero indices, original dtype, and original shape.

返回类型:

object

decompress(packed)[源代码]#

API Language - 中文 | English


  • 中文

恢复 compress() 生成的 payload。

参数:

packed (object) -- 非零索引、原 dtype 和原 shape。

返回:

恢复原 shape、dtype 和 device 的张量。

返回类型:

Tensor


  • English

Restore a payload produced by compress().

参数:

packed (object) -- Nonzero indices, original dtype, and original shape.

返回:

Tensor with its original shape, dtype, and device.

返回类型:

Tensor