Skip to content

why are we able to use 'if' inside a 'pmap' train_step? #2472

Answered by andsteing
yiyixuxu asked this question in Q&A
Discussion options

You must be logged in to vote

You can use Python control logic inside a jit/pmap, as long as that control flow is not value dependent.

In this case, the if statement is about the value of state.dynamic_scale which can be None, if no dynamic scaling is used, or am instance of dynamic_scale_lib.DynamicScale, if dynamic scaling is used. In either case, the value will be set from the config (see lines 227-230 in code snippet below), and is not changed during the training. In other words, jit/pmap will produce a single compiled version of the code.

def create_train_state(rng, config: ml_collections.ConfigDict,
model, image_size, learning_rate_fn):

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by yiyixuxu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants