Skip to content

Commit 84b69f1

Browse files
authored
Disable tqdm in non-interactive mode (stanford-crfm#1422)
1 parent 62e7e2d commit 84b69f1

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

scripts/fact_completion/create_benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main():
7676
# Select head QIDS to include in dataset
7777
selected = []
7878
all_qids = set()
79-
for p in tqdm(prop_map):
79+
for p in tqdm(prop_map, disable=None):
8080
np.random.seed(0)
8181
head_qids = list(prop_map[p].keys())
8282
idxs = np.random.choice(len(head_qids), min(1000, len(head_qids)), replace=False)

scripts/fact_completion/fetch_triples_and_aliases.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def main() -> None:
8080
table_files.extend(get_batch_files(processed_folder / args.entity_values_folder))
8181

8282
filtered_triples = []
83-
for filepath in tqdm(table_files):
83+
for filepath in tqdm(table_files, disable=None):
8484
filtered_triples.extend(rel_filtering_func(seed_relations, filepath))
8585
print(f"Extracted {len(filtered_triples)} triples for seed relations.")
8686

@@ -96,7 +96,7 @@ def main() -> None:
9696

9797
table_files = get_batch_files(processed_folder / args.aliases_folder)
9898
filtered_aliases = []
99-
for filepath in tqdm(table_files):
99+
for filepath in tqdm(table_files, disable=None):
100100
filtered_aliases.extend(alias_filtering_func(qids, filepath))
101101
print(f"Extracted {len(filtered_aliases)} aliases.")
102102

scripts/fact_completion/filter_triples.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def main() -> None:
7373
print("Loading Wikipedia table.")
7474
wikipedia_qids = set()
7575
table_files = get_batch_files(processed_folder / args.wikipedia_links_folder)
76-
for f in tqdm(table_files):
76+
for f in tqdm(table_files, disable=None):
7777
with open(f) as in_file:
7878
for line in in_file:
7979
item = json.loads(line)
@@ -84,7 +84,7 @@ def main() -> None:
8484
triples_file = benchmark_folder / "triples.jsonl"
8585
print(f"Loading triples from {triples_file}. Filtering based on alias quality...")
8686
filtered_triples = []
87-
for triple in tqdm(jsonl_generator(str(triples_file)), total=215288006):
87+
for triple in tqdm(jsonl_generator(str(triples_file)), total=215288006, disable=None):
8888
q1 = triple["qid"]
8989
q2 = triple["value"]
9090
if bad_alias(qid2alias[q1]) or bad_alias(qid2alias[q2]):

src/helm/benchmark/presentation/summarize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def read_runs(self):
291291
# run_suite_path can contain subdirectories that are not runs (e.g. eval_cache, groups)
292292
# so filter them out.
293293
run_dir_names = sorted([p for p in os.listdir(self.run_suite_path) if p != "eval_cache" and p != "groups"])
294-
for run_dir_name in tqdm(run_dir_names):
294+
for run_dir_name in tqdm(run_dir_names, disable=None):
295295
run_spec_path: str = os.path.join(self.run_suite_path, run_dir_name, "run_spec.json")
296296
stats_path: str = os.path.join(self.run_suite_path, run_dir_name, "stats.json")
297297
if not os.path.exists(run_spec_path) or not os.path.exists(stats_path):

src/helm/benchmark/runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
ensure_directory_exists(self.eval_cache_path)
9797

9898
def run_all(self, run_specs: List[RunSpec]):
99-
for run_spec in tqdm(run_specs):
99+
for run_spec in tqdm(run_specs, disable=None):
100100
try:
101101
with htrack_block(f"Running {run_spec.name}"):
102102
self.run_one(run_spec)

src/helm/benchmark/scenarios/copyright_scenario.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_instances(self) -> List[Instance]:
7272

7373
# Read all the instances
7474
instances: List[Instance] = []
75-
for prefix, prefix_to_end in tqdm.tqdm(data["data"].items(), desc="load instances"):
75+
for prefix, prefix_to_end in tqdm.tqdm(data["data"].items(), desc="load instances", disable=None):
7676
instances.append(
7777
Instance(
7878
input=Input(text=prefix),

src/helm/common/general.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ def parallel_map(
195195
with htrack_block(f"Parallelizing computation on {len(items)} items over {parallelism} {units}"):
196196
results: List
197197
if parallelism == 1:
198-
results = list(tqdm(map(process, items), total=len(items)))
198+
results = list(tqdm(map(process, items), total=len(items), disable=None))
199199
elif multiprocessing:
200200
with ProcessPoolExecutor(max_workers=parallelism) as executor:
201-
results = list(tqdm(executor.map(process, items), total=len(items)))
201+
results = list(tqdm(executor.map(process, items), total=len(items), disable=None))
202202
else:
203203
with ThreadPoolExecutor(max_workers=parallelism) as executor:
204-
results = list(tqdm(executor.map(process, items), total=len(items)))
204+
results = list(tqdm(executor.map(process, items), total=len(items), disable=None))
205205
return results
206206

207207

0 commit comments

Comments
 (0)