Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ def test_embedding(self):
error = compute_error(original, quantized)
self.assertTrue(error > 20)

def test_add(self):
dtype = torch.bfloat16
device = "cpu"
a = torch.nn.Embedding(128, 256, dtype=dtype, device=device)
b = torch.nn.Embedding(128, 256, dtype=dtype, device=device)
a_orig = copy.deepcopy(a)
sum = a.weight + b.weight

quantize_(a, self.config)
a_quant_sum = a.weight + b.weight

quantize_(b, self.config)
b_quant_sum = a_orig.weight + b.weight
a_b_quant_sum = a.weight + b.weight

for quantized_sum in [a_quant_sum, b_quant_sum, a_b_quant_sum]:
error = compute_error(sum, quantized_sum)
self.assertTrue(error > 20)

def test_linear(self):
dtype = torch.bfloat16
device = "cpu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ def _(func, types, args, kwargs):
return torch.nn.functional.embedding(indices, weight_tensor, **kwargs)


@implements(aten.add.Tensor)
def _(func, types, args, kwargs):
assert len(args) == 2
t1, t2 = args[0], args[1]
if isinstance(t1, IntxUnpackedToInt8Tensor):
assert t1.activation_quantization is None
t1 = t1.dequantize()
if isinstance(t2, IntxUnpackedToInt8Tensor):
assert t2.activation_quantization is None
t2 = t2.dequantize()
return t1 + t2


@implements(aten.slice.Tensor)
def _(func, types, args, kwargs):
self, dim, start, end, step = fill_defaults(args, 5, [0, None, None, 1])
Expand Down
Loading