Skip to content

Commit

Permalink
Make tests a little less verbose
Browse files Browse the repository at this point in the history
Summary: Useful info on github test runs is burried in spurious logging. Avoid this.

Reviewed By: mlomeli1

Differential Revision: D47209139

fbshipit-source-id: b5111c91e2b94f0c3678d599197f8e7094993df1
  • Loading branch information
mdouze authored and facebook-github-bot committed Jul 4, 2023
1 parent 4bfdd43 commit 1c1d5c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/common_faiss_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def evalres(self, DI):
for rank in 1, 10, 100:
e[rank] = ((I[:, :rank] == self.gt.reshape(-1, 1)).sum() /
float(self.nq))
print("1-recalls: %s" % e)
# print("1-recalls: %s" % e)
return e


Expand Down
8 changes: 4 additions & 4 deletions tests/test_index_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def subtest(self, mt):
radius = float(D[:, -1].max())
else:
radius = float(D[:, -1].min())
print("radius", radius)
# print("radius", radius)

lims, D3, I3 = index.range_search(xq, radius)
ntot = ndiff = 0
Expand All @@ -278,14 +278,14 @@ def subtest(self, mt):
Iref = set(I2[i, mask])
ndiff += len(Inew ^ Iref)
ntot += len(Iref)
print("ndiff %d / %d" % (ndiff, ntot))
# print("ndiff %d / %d" % (ndiff, ntot))
assert ndiff < ntot * 0.01

for pm in 1, 2:
print("parallel_mode=%d" % pm)
# print("parallel_mode=%d" % pm)
index.parallel_mode = pm
lims4, D4, I4 = index.range_search(xq, radius)
print("sizes", lims4[1:] - lims4[:-1])
# print("sizes", lims4[1:] - lims4[:-1])
for qno in range(len(lims) - 1):
Iref = I3[lims[qno]: lims[qno + 1]]
Inew = I4[lims4[qno]: lims4[qno + 1]]
Expand Down
15 changes: 7 additions & 8 deletions tests/test_residual_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_training(self):

# in practice RQ is often better than PQ but it does not the case here, so just check
# that we are within some factor.
print(err_pq, err_rq)
# print(err_pq, err_rq)
self.assertLess(err_rq, err_pq * 1.2)

def test_beam_size(self):
Expand Down Expand Up @@ -285,7 +285,6 @@ def test_clipping(self):

# verify that prefixes are the same
for i in range(ds.nb):
print(i, ds.nb)
br = faiss.BitstringReader(faiss.swig_ptr(codes[i]), rq.code_size)
br2 = faiss.BitstringReader(faiss.swig_ptr(codes2[i]), rq2.code_size)
self.assertEqual(br.read(rq2.tot_bits), br2.read(rq2.tot_bits))
Expand Down Expand Up @@ -319,10 +318,10 @@ def retrain_AQ_codebook(index, xt):

x_decoded = index.sa_decode(codes_packed)
MSE = ((xt - x_decoded) ** 2).sum() / n
print(f"Initial MSE on training set: {MSE:g}")
# print(f"Initial MSE on training set: {MSE:g}")

codes = unpack_codes(index.rq, codes_packed)
print("ref codes", codes[0])
# print("ref codes", codes[0])
codebook_offsets = faiss.vector_to_array(rq.codebook_offsets)

# build sparse code matrix (represented as a dense matrix)
Expand All @@ -342,7 +341,7 @@ def retrain_AQ_codebook(index, xt):
B, residuals, rank, singvals = scipy.linalg.lstsq(C, xt, )

MSE = ((C @ B - xt) ** 2).sum() / n
print(f"MSE after retrainining: {MSE:g}")
# print(f"MSE after retrainining: {MSE:g}")

# replace codebook
# faiss.copy_array_to_vector(B.astype('float32').ravel(), index.rq.codebooks)
Expand Down Expand Up @@ -503,7 +502,7 @@ def test_reestimate_codebook_2(self):
xt_decoded = ir.sa_decode(ir.sa_encode(xt))
err_after_refined = ((xt - xt_decoded) ** 2).sum()

print(err_before, err_after_refined)
# print(err_before, err_after_refined)
# ref run 7474.98 / 7006.1777
self.assertGreater(err_before, err_after_refined * 1.06)

Expand Down Expand Up @@ -1165,7 +1164,7 @@ def test_codec(self):
pq.train(xt)
err_pq = eval_codec(pq, xb)

print(err_prq, err_pq)
# print(err_prq, err_pq)
self.assertLess(err_prq, err_pq)

def test_with_rq(self):
Expand All @@ -1186,7 +1185,7 @@ def test_with_rq(self):
rq.train(xt)
err_rq = eval_codec(rq, xb)

print(err_prq, err_rq)
# print(err_prq, err_rq)
self.assertEqual(err_prq, err_rq)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_standalone_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ def test_rw(self):
for i in range(nbyte):
self.assertTrue(((bignum >> (i * 8)) & 255) == bs[i])

for i in range(nbyte):
print(bin(bs[i] + 256)[3:], end=' ')
print()
#for i in range(nbyte):
# print(bin(bs[i] + 256)[3:], end=' ')
# print()

br = faiss.BitstringReader(swig_ptr(bs), nbyte)

for nbit, xref in ctrl:
xnew = br.read(nbit)
print('nbit %d xref %x xnew %x' % (nbit, xref, xnew))
# print('nbit %d xref %x xnew %x' % (nbit, xref, xnew))
self.assertTrue(xnew == xref)


Expand Down

0 comments on commit 1c1d5c8

Please sign in to comment.