Commit d1bf39cf authored by wenjh's avatar wenjh
Browse files

Fix lack of lds in vector_blockwise


Signed-off-by: wenjh's avatarwenjh <wenjh@sugon.com>
parent 3653fbfb
...@@ -263,30 +263,16 @@ void compare_scaling_factors(const std::string& name, const float* test, const f ...@@ -263,30 +263,16 @@ void compare_scaling_factors(const std::string& name, const float* test, const f
void compare_scaling_factors_one_dimensional_blocks(const std::string& name, const float* test, void compare_scaling_factors_one_dimensional_blocks(const std::string& name, const float* test,
const float* ref, const size_t rows, const float* ref, const size_t rows,
const size_t col_blocks const size_t col_blocks) {
#ifdef __HIP_PLATFORM_AMD__
, double atol = 0., double rtol = 0.
#endif
) {
const size_t test_stride = scale_align_stride(rows); const size_t test_stride = scale_align_stride(rows);
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
for (int j = 0; j < col_blocks; ++j) { for (int j = 0; j < col_blocks; ++j) {
const int test_idx = i + test_stride * j; const int test_idx = i + test_stride * j;
const int ref_idx = i + rows * j; const int ref_idx = i + rows * j;
#ifdef __HIP_PLATFORM_AMD__
double t = static_cast<double>(static_cast<float>(test[test_idx]));
double r = static_cast<double>(static_cast<float>(ref[ref_idx]));
bool mismatch = fabs(t - r) > atol && (r == 0 || fabs((t - r) / r) > rtol);
ASSERT_FALSE(mismatch)
<< "Error in " << name << std::endl
<< "Mismatch: " << t << " vs " << r << " at index " << test_idx
<< "," << ref_idx;
#else
ASSERT_FALSE(test[test_idx] != ref[ref_idx]) ASSERT_FALSE(test[test_idx] != ref[ref_idx])
<< "Error in " << name << std::endl << "Error in " << name << std::endl
<< "Mismatch: " << test[test_idx] << " vs " << ref[ref_idx] << " at index " << test_idx << "Mismatch: " << test[test_idx] << " vs " << ref[ref_idx] << " at index " << test_idx
<< "," << ref_idx; << "," << ref_idx;
#endif
} }
} }
} }
...@@ -425,33 +411,17 @@ void runTestCaseOneDimensionalBlocks(const ProcessingMethod processing_method, ...@@ -425,33 +411,17 @@ void runTestCaseOneDimensionalBlocks(const ProcessingMethod processing_method,
float atol = 0.0; float atol = 0.0;
float rtol = 0.0; float rtol = 0.0;
#ifdef __HIP_PLATFORM_AMD__
double atol_scale = 0.0;
double rtol_scale = 0.0;
if(itype == DType::kFloat32)
{
atol_scale = 1e-5;
}
#endif
if (rowwise) { if (rowwise) {
compareResults("output_c", output_c, ref_output.get(), true, atol, rtol); compareResults("output_c", output_c, ref_output.get(), true, atol, rtol);
compare_scaling_factors_one_dimensional_blocks("scale_inv", compare_scaling_factors_one_dimensional_blocks("scale_inv",
output_c.rowwise_cpu_scale_inv_ptr<float>(), output_c.rowwise_cpu_scale_inv_ptr<float>(),
ref_scale_inv.get(), rows, blocks_x ref_scale_inv.get(), rows, blocks_x);
#ifdef __HIP_PLATFORM_AMD__
, atol_scale, rtol_scale
#endif
);
} }
if (colwise) { if (colwise) {
compareResults("output_c_t", output_c, ref_output_t.get(), false, atol, rtol); compareResults("output_c_t", output_c, ref_output_t.get(), false, atol, rtol);
compare_scaling_factors_one_dimensional_blocks("scale_inv_t", compare_scaling_factors_one_dimensional_blocks("scale_inv_t",
output_c.columnwise_cpu_scale_inv_ptr<float>(), output_c.columnwise_cpu_scale_inv_ptr<float>(),
ref_scale_inv_t.get(), cols, blocks_x_t ref_scale_inv_t.get(), cols, blocks_x_t);
#ifdef __HIP_PLATFORM_AMD__
, atol_scale, rtol_scale
#endif
);
} }
} }
......
...@@ -153,7 +153,7 @@ def check_quantization_block_tiling_versus_reference( ...@@ -153,7 +153,7 @@ def check_quantization_block_tiling_versus_reference(
) )
# Check # Check
torch.testing.assert_close(qx.float(), qx_ref.float(), atol=0.0 if quant_dtype != torch.int8 else 1.0, rtol=0.0) torch.testing.assert_close(qx.float(), qx_ref.float(), atol=0.0, rtol=0.0)
# Zero out values that are don't care values # Zero out values that are don't care values
# Scale format has padding. # Scale format has padding.
scale_mask = torch.ones( scale_mask = torch.ones(
...@@ -163,7 +163,7 @@ def check_quantization_block_tiling_versus_reference( ...@@ -163,7 +163,7 @@ def check_quantization_block_tiling_versus_reference(
QuantizeResult(qx, scale_mask, None, None), tile_size QuantizeResult(qx, scale_mask, None, None), tile_size
).scale ).scale
sx = sx * scale_mask sx = sx * scale_mask
torch.testing.assert_close(sx, sx_ref, atol=0.0 if x_dtype != torch.float32 else 1e-5, rtol=0.0 if x_dtype != torch.float32 else 5e-5) torch.testing.assert_close(sx, sx_ref, atol=0.0, rtol=0.0)
if return_transpose: if return_transpose:
assert qx_t is not None assert qx_t is not None
...@@ -179,8 +179,8 @@ def check_quantization_block_tiling_versus_reference( ...@@ -179,8 +179,8 @@ def check_quantization_block_tiling_versus_reference(
QuantizeResult(qx_t, scale_mask, None, None), tile_size QuantizeResult(qx_t, scale_mask, None, None), tile_size
).scale ).scale
sx_t = sx_t * scale_mask sx_t = sx_t * scale_mask
torch.testing.assert_close(qx_t.float(), qx_t_ref.float(), atol=0.0 if quant_dtype != torch.int8 else 1.0, rtol=0.0 if x_dtype != torch.float32 else 2.5e-1) torch.testing.assert_close(qx_t.float(), qx_t_ref.float(), atol=0.0, rtol=0.0)
torch.testing.assert_close(sx_t, sx_t_ref, atol=0.0 if x_dtype != torch.float32 else 1e-5, rtol=0.0 if x_dtype != torch.float32 else 5e-5) torch.testing.assert_close(sx_t, sx_t_ref, atol=0.0, rtol=0.0)
else: else:
# should be None # should be None
assert qx_t is None and qx_t_ref is None assert qx_t is None and qx_t_ref is None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment