MCPcopy Create free account
hub / github.com/EmbodiedGPT/EmbodiedGPT_Pytorch / CLinear

Class CLinear

robohusky/compression.py:32–49  ·  view source on GitHub ↗

Compressed Linear Layer.

Source from the content-addressed store, hash-verified

30
31
32class CLinear(nn.Module):
33 """Compressed Linear Layer."""
34
35 def __init__(self, weight=None, bias=None, device=None):
36 super().__init__()
37 if weight is None:
38 self.weight = None
39 elif isinstance(weight, Tensor):
40 self.weight = compress(weight.data.to(device), default_compression_config)
41 else:
42 self.weight = weight
43 self.bias = bias
44
45 def forward(self, input: Tensor) -> Tensor:
46 weight = decompress(self.weight, default_compression_config)
47 if self.bias is None:
48 return F.linear(input.to(weight.dtype), weight)
49 return F.linear(input.to(weight.dtype), weight, self.bias.to(weight.dtype))
50
51
52def compress_module(module, target_device):

Callers 2

compress_moduleFunction · 0.85
apply_compressed_weightFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected