MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / create_linear_map

Function create_linear_map

bitsandbytes/functional.py:150–166  ·  view source on GitHub ↗
(signed=True, total_bits=8, add_zero=True)

Source from the content-addressed store, hash-verified

148
149
150def create_linear_map(signed=True, total_bits=8, add_zero=True):
151 sign = -1.0 if signed else 0.0
152 total_values = 2**total_bits
153 if add_zero or total_bits < 8:
154 # add a zero
155 # since we simulate less bits by having zeros in the data type, we
156 # we need to center the quantization around zero and as such lose
157 # a single value
158 total_values = 2**total_bits if not signed else 2**total_bits - 1
159
160 values = torch.linspace(sign, 1.0, total_values)
161 gap = 256 - values.numel()
162 if gap == 0:
163 return values
164 else:
165 l = values.numel() // 2 # noqa: E741
166 return torch.Tensor(values[:l].tolist() + [0] * gap + values[l:].tolist())
167
168
169def create_normal_map(offset=0.9677083, use_extra_value=True):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected