Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue where first update of the progress bar is 2 times the print rate #26

Closed
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
18 changes: 5 additions & 13 deletions jax_tqdm/pbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ def build_tqdm(
f"number of steps {n}, got {print_rate}"
)

remainder = n % print_rate

def _define_tqdm(_arg, bar_id: int):
bar_id = int(bar_id)
tqdm_bars[bar_id] = pbar(range(n), position=bar_id + position_offset, **kwargs)
Expand All @@ -184,24 +182,18 @@ def _update_progress_bar(iter_num, bar_id: int = 0):
lambda _: None,
operand=None,
)

_ = jax.lax.cond(
# update tqdm every multiple of `print_rate` except at the end
(iter_num % print_rate == 0) & (iter_num != n - remainder),
# update tqdm every multiple of `print_rate`
(iter_num != 0) & (iter_num % print_rate == 0),
lambda _: callback(_update_tqdm, print_rate, bar_id, ordered=True),
lambda _: None,
operand=None,
)

_ = jax.lax.cond(
# update tqdm by `remainder`
iter_num == n - remainder,
lambda _: callback(_update_tqdm, remainder, bar_id, ordered=True),
lambda _: None,
operand=None,
)

def _close_tqdm(_arg, bar_id: int):
dif = n - tqdm_bars[int(bar_id)].n
tqdm_bars[int(bar_id)].update(int(dif))
tqdm_bars[int(bar_id)].close()

def close_tqdm(result, iter_num, bar_id: int = 0):
Expand Down
Loading