Skip to content

Commit 5b6c4b4

Browse files
mdouzefacebook-github-bot
authored andcommitted
Back out "printf -> fmt::print in files inc faiss/IndexBinaryHNSW.cpp" (facebookresearch#3164)
Summary: Pull Request resolved: facebookresearch#3164 The original diff breaks the open-source Faiss compiles. Original commit changeset: 230540b26ec8 Original Phabricator Diff: D51486397 Reviewed By: algoriddle Differential Revision: D51938993 fbshipit-source-id: a57433c4267493d2fe2249e8f4191612c0f1da59
1 parent 131adc5 commit 5b6c4b4

10 files changed

+91
-122
lines changed

faiss/IndexBinaryHNSW.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <faiss/utils/Heap.h>
3232
#include <faiss/utils/hamming.h>
3333
#include <faiss/utils/random.h>
34-
#include <fmt/core.h>
3534

3635
namespace faiss {
3736

@@ -52,18 +51,17 @@ void hnsw_add_vertices(
5251
size_t ntotal = n0 + n;
5352
double t0 = getmillisecs();
5453
if (verbose) {
55-
fmt::print(
56-
"hnsw_add_vertices: adding {} elements on top of {} "
57-
"(preset_levels={})\n",
58-
n,
59-
n0,
60-
int(preset_levels));
54+
printf("hnsw_add_vertices: adding %zd elements on top of %zd "
55+
"(preset_levels=%d)\n",
56+
n,
57+
n0,
58+
int(preset_levels));
6159
}
6260

6361
int max_level = hnsw.prepare_level_tab(n, preset_levels);
6462

6563
if (verbose) {
66-
fmt::print(" max_level = {}\n", max_level);
64+
printf(" max_level = %d\n", max_level);
6765
}
6866

6967
std::vector<omp_lock_t> locks(ntotal);
@@ -110,8 +108,7 @@ void hnsw_add_vertices(
110108
int i0 = i1 - hist[pt_level];
111109

112110
if (verbose) {
113-
fmt::print(
114-
"Adding {} elements at level {}\n", i1 - i0, pt_level);
111+
printf("Adding %d elements at level %d\n", i1 - i0, pt_level);
115112
}
116113

117114
// random permutation to get rid of dataset order bias
@@ -138,7 +135,7 @@ void hnsw_add_vertices(
138135

139136
if (prev_display >= 0 && i - i0 > prev_display + 10000) {
140137
prev_display = i - i0;
141-
fmt::print(" {} / {}\r", i - i0, i1 - i0);
138+
printf(" %d / %d\r", i - i0, i1 - i0);
142139
fflush(stdout);
143140
}
144141
}
@@ -148,7 +145,7 @@ void hnsw_add_vertices(
148145
FAISS_ASSERT(i1 == 0);
149146
}
150147
if (verbose) {
151-
fmt::print("Done in {:.3f} ms\n", getmillisecs() - t0);
148+
printf("Done in %.3f ms\n", getmillisecs() - t0);
152149
}
153150

154151
for (int i = 0; i < ntotal; i++)

faiss/IndexBinaryHash.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <faiss/impl/AuxIndexStructures.h>
2121
#include <faiss/impl/FaissAssert.h>
2222
#include <faiss/impl/platform_macros.h>
23-
#include <fmt/core.h>
2423

2524
namespace faiss {
2625

@@ -269,12 +268,12 @@ size_t IndexBinaryHash::hashtable_size() const {
269268

270269
void IndexBinaryHash::display() const {
271270
for (auto it = invlists.begin(); it != invlists.end(); ++it) {
272-
fmt::print("%" PRId64 ": [", it->first);
271+
printf("%" PRId64 ": [", it->first);
273272
const std::vector<idx_t>& v = it->second.ids;
274273
for (auto x : v) {
275-
fmt::print("%" PRId64 " ", x);
274+
printf("%" PRId64 " ", x);
276275
}
277-
fmt::print("]\n");
276+
printf("]\n");
278277
}
279278
}
280279

faiss/IndexBinaryIVF.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <faiss/utils/hamming.h>
2424
#include <faiss/utils/sorting.h>
2525
#include <faiss/utils/utils.h>
26-
#include <fmt/core.h>
2726

2827
namespace faiss {
2928

@@ -88,11 +87,10 @@ void IndexBinaryIVF::add_core(
8887
n_add++;
8988
}
9089
if (verbose) {
91-
fmt::print(
92-
"IndexBinaryIVF::add_with_ids: added "
93-
"%" PRId64 " / %" PRId64 " vectors\n",
94-
n_add,
95-
n);
90+
printf("IndexBinaryIVF::add_with_ids: added "
91+
"%" PRId64 " / %" PRId64 " vectors\n",
92+
n_add,
93+
n);
9694
}
9795
ntotal += n_add;
9896
}
@@ -235,17 +233,16 @@ size_t IndexBinaryIVF::remove_ids(const IDSelector& sel) {
235233

236234
void IndexBinaryIVF::train(idx_t n, const uint8_t* x) {
237235
if (verbose) {
238-
fmt::print("Training quantizer\n");
236+
printf("Training quantizer\n");
239237
}
240238

241239
if (quantizer->is_trained && (quantizer->ntotal == nlist)) {
242240
if (verbose) {
243-
fmt::print("IVF quantizer does not need training.\n");
241+
printf("IVF quantizer does not need training.\n");
244242
}
245243
} else {
246244
if (verbose) {
247-
fmt::print(
248-
"Training quantizer on %" PRId64 " vectors in {}D\n", n, d);
245+
printf("Training quantizer on %" PRId64 " vectors in %dD\n", n, d);
249246
}
250247

251248
Clustering clus(d, nlist, cp);
@@ -254,9 +251,8 @@ void IndexBinaryIVF::train(idx_t n, const uint8_t* x) {
254251
IndexFlatL2 index_tmp(d);
255252

256253
if (clustering_index && verbose) {
257-
fmt::print(
258-
"using clustering_index of dimension {} to do the clustering\n",
259-
clustering_index->d);
254+
printf("using clustering_index of dimension %d to do the clustering\n",
255+
clustering_index->d);
260256
}
261257

262258
// LSH codec that is able to convert the binary vectors to floats.

faiss/IndexFastScan.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <faiss/impl/pq4_fast_scan.h>
2727
#include <faiss/impl/simd_result_handlers.h>
2828
#include <faiss/utils/quantize_lut.h>
29-
#include <fmt/core.h>
3029

3130
namespace faiss {
3231

@@ -74,7 +73,7 @@ void IndexFastScan::add(idx_t n, const float* x) {
7473
for (idx_t i0 = 0; i0 < n; i0 += bs) {
7574
idx_t i1 = std::min(n, i0 + bs);
7675
if (verbose) {
77-
fmt::print("IndexFastScan::add {}/{}\n", size_t(i1), size_t(n));
76+
printf("IndexFastScan::add %zd/%zd\n", size_t(i1), size_t(n));
7877
}
7978
add(i1 - i0, x + i0 * d);
8079
}

faiss/IndexHNSW.cpp

+16-21
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <faiss/utils/distances.h>
3434
#include <faiss/utils/random.h>
3535
#include <faiss/utils/sorting.h>
36-
#include <fmt/core.h>
3736

3837
extern "C" {
3938

@@ -135,12 +134,11 @@ void hnsw_add_vertices(
135134
size_t ntotal = n0 + n;
136135
double t0 = getmillisecs();
137136
if (verbose) {
138-
fmt::print(
139-
"hnsw_add_vertices: adding {} elements on top of {} "
140-
"(preset_levels={})\n",
141-
n,
142-
n0,
143-
int(preset_levels));
137+
printf("hnsw_add_vertices: adding %zd elements on top of %zd "
138+
"(preset_levels=%d)\n",
139+
n,
140+
n0,
141+
int(preset_levels));
144142
}
145143

146144
if (n == 0) {
@@ -150,7 +148,7 @@ void hnsw_add_vertices(
150148
int max_level = hnsw.prepare_level_tab(n, preset_levels);
151149

152150
if (verbose) {
153-
fmt::print(" max_level = {}\n", max_level);
151+
printf(" max_level = %d\n", max_level);
154152
}
155153

156154
std::vector<omp_lock_t> locks(ntotal);
@@ -198,8 +196,7 @@ void hnsw_add_vertices(
198196
int i0 = i1 - hist[pt_level];
199197

200198
if (verbose) {
201-
fmt::print(
202-
"Adding {} elements at level {}\n", i1 - i0, pt_level);
199+
printf("Adding %d elements at level %d\n", i1 - i0, pt_level);
203200
}
204201

205202
// random permutation to get rid of dataset order bias
@@ -235,7 +232,7 @@ void hnsw_add_vertices(
235232

236233
if (prev_display >= 0 && i - i0 > prev_display + 10000) {
237234
prev_display = i - i0;
238-
fmt::print(" {} / {}\r", i - i0, i1 - i0);
235+
printf(" %d / %d\r", i - i0, i1 - i0);
239236
fflush(stdout);
240237
}
241238
if (counter % check_period == 0) {
@@ -254,7 +251,7 @@ void hnsw_add_vertices(
254251
FAISS_ASSERT(i1 == 0);
255252
}
256253
if (verbose) {
257-
fmt::print("Done in {:.3f} ms\n", getmillisecs() - t0);
254+
printf("Done in %.3f ms\n", getmillisecs() - t0);
258255
}
259256

260257
for (int i = 0; i < ntotal; i++) {
@@ -541,13 +538,13 @@ void IndexHNSW::init_level_0_from_entry_points(
541538
*dis, pt_id, nearest, (*dis)(nearest), 0, locks.data(), vt);
542539

543540
if (verbose && i % 10000 == 0) {
544-
fmt::print(" {} / {}\r", i, n);
541+
printf(" %d / %d\r", i, n);
545542
fflush(stdout);
546543
}
547544
}
548545
}
549546
if (verbose) {
550-
fmt::print("\n");
547+
printf("\n");
551548
}
552549

553550
for (int i = 0; i < ntotal; i++)
@@ -589,7 +586,7 @@ void IndexHNSW::reorder_links() {
589586
}
590587

591588
void IndexHNSW::link_singletons() {
592-
fmt::print("search for singletons\n");
589+
printf("search for singletons\n");
593590

594591
std::vector<bool> seen(ntotal);
595592

@@ -614,12 +611,10 @@ void IndexHNSW::link_singletons() {
614611
}
615612
}
616613

617-
fmt::print(
618-
" Found {} / %" PRId64
619-
" singletons ({} appear in a level above)\n",
620-
n_sing,
621-
ntotal,
622-
n_sing_l1);
614+
printf(" Found %d / %" PRId64 " singletons (%d appear in a level above)\n",
615+
n_sing,
616+
ntotal,
617+
n_sing_l1);
623618

624619
std::vector<float> recons(singletons.size() * d);
625620
for (int i = 0; i < singletons.size(); i++) {

faiss/IndexIVF.cpp

+19-24
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <faiss/impl/CodePacker.h>
2929
#include <faiss/impl/FaissAssert.h>
3030
#include <faiss/impl/IDSelector.h>
31-
#include <fmt/core.h>
3231

3332
namespace faiss {
3433

@@ -63,19 +62,18 @@ void Level1Quantizer::train_q1(
6362
size_t d = quantizer->d;
6463
if (quantizer->is_trained && (quantizer->ntotal == nlist)) {
6564
if (verbose)
66-
fmt::print("IVF quantizer does not need training.\n");
65+
printf("IVF quantizer does not need training.\n");
6766
} else if (quantizer_trains_alone == 1) {
6867
if (verbose)
69-
fmt::print("IVF quantizer trains alone...\n");
68+
printf("IVF quantizer trains alone...\n");
7069
quantizer->train(n, x);
7170
quantizer->verbose = verbose;
7271
FAISS_THROW_IF_NOT_MSG(
7372
quantizer->ntotal == nlist,
7473
"nlist not consistent with quantizer size");
7574
} else if (quantizer_trains_alone == 0) {
7675
if (verbose)
77-
fmt::print(
78-
"Training level-1 quantizer on {} vectors in {}D\n", n, d);
76+
printf("Training level-1 quantizer on %zd vectors in %zdD\n", n, d);
7977

8078
Clustering clus(d, nlist, cp);
8179
quantizer->reset();
@@ -88,11 +86,10 @@ void Level1Quantizer::train_q1(
8886
quantizer->is_trained = true;
8987
} else if (quantizer_trains_alone == 2) {
9088
if (verbose) {
91-
fmt::print(
92-
"Training L2 quantizer on {} vectors in {}D{}\n",
93-
n,
94-
d,
95-
clustering_index ? "(user provided index)" : "");
89+
printf("Training L2 quantizer on %zd vectors in %zdD%s\n",
90+
n,
91+
d,
92+
clustering_index ? "(user provided index)" : "");
9693
}
9794
// also accept spherical centroids because in that case
9895
// L2 and IP are equivalent
@@ -108,11 +105,11 @@ void Level1Quantizer::train_q1(
108105
clus.train(n, x, *clustering_index);
109106
}
110107
if (verbose) {
111-
fmt::print("Adding centroids to quantizer\n");
108+
printf("Adding centroids to quantizer\n");
112109
}
113110
if (!quantizer->is_trained) {
114111
if (verbose) {
115-
fmt::print("But training it first on centroids table...\n");
112+
printf("But training it first on centroids table...\n");
116113
}
117114
quantizer->train(nlist, clus.centroids.data());
118115
}
@@ -213,10 +210,9 @@ void IndexIVF::add_core(
213210
for (idx_t i0 = 0; i0 < n; i0 += bs) {
214211
idx_t i1 = std::min(n, i0 + bs);
215212
if (verbose) {
216-
fmt::print(
217-
" IndexIVF::add_with_ids %" PRId64 ":%" PRId64 "\n",
218-
i0,
219-
i1);
213+
printf(" IndexIVF::add_with_ids %" PRId64 ":%" PRId64 "\n",
214+
i0,
215+
i1);
220216
}
221217
add_core(
222218
i1 - i0,
@@ -265,11 +261,10 @@ void IndexIVF::add_core(
265261
}
266262

267263
if (verbose) {
268-
fmt::print(
269-
" added {} / %" PRId64 " vectors ({} -1s)\n",
270-
nadd,
271-
n,
272-
nminus1);
264+
printf(" added %zd / %" PRId64 " vectors (%zd -1s)\n",
265+
nadd,
266+
n,
267+
nminus1);
273268
}
274269

275270
ntotal += n;
@@ -1133,13 +1128,13 @@ void IndexIVF::update_vectors(int n, const idx_t* new_ids, const float* x) {
11331128

11341129
void IndexIVF::train(idx_t n, const float* x) {
11351130
if (verbose) {
1136-
fmt::print("Training level-1 quantizer\n");
1131+
printf("Training level-1 quantizer\n");
11371132
}
11381133

11391134
train_q1(n, x, verbose, metric_type);
11401135

11411136
if (verbose) {
1142-
fmt::print("Training IVF residual\n");
1137+
printf("Training IVF residual\n");
11431138
}
11441139

11451140
// optional subsampling
@@ -1176,7 +1171,7 @@ void IndexIVF::train_encoder(
11761171
const idx_t* assign) {
11771172
// does nothing by default
11781173
if (verbose) {
1179-
fmt::print("IndexIVF: no residual training\n");
1174+
printf("IndexIVF: no residual training\n");
11801175
}
11811176
}
11821177

0 commit comments

Comments
 (0)