tsalib icon indicating copy to clipboard operation
tsalib copied to clipboard

Updating DimVar's value best practice

Open finngaida opened this issue 5 years ago • 4 comments

So I'm declaring global DimVars (without a hardcoded value) and later at runtime want to update their values based on some hyperparams to do shape assertions. I'm aware I can just manipulate their ._val propery, but that seems a bit hacky to me, what's the intended workflow for this kind of problem?

finngaida avatar Mar 29 '20 15:03 finngaida

@finngaida sorry for the delayed reply. I think there was a DimVar.update function somewhere but not exposed in docs. Will check and get back soon.

Also, can you tell me more about which DimVar you are trying to update? Any reason you can't initialize it upfront from config variables?

ekshaks avatar Apr 13 '20 13:04 ekshaks

@ekshaks same issue here.

For example, the text sequence dimension [batch_size, sequence_size, hidden_size] can vary from batch to batch (padded only at batch level). It would be super helpful to make some kind of dynamic dimension variables.

BTW, thanks for this awesome package!

ChenghaoMou avatar May 02 '20 18:05 ChenghaoMou

Thanks @ChenghaoMou and @finngaida for comments on the issue. Added update_dim_vars_len in the commit dd2e7475cfd914cc8f5402b57fa4cf33f312446a. Please see the README (API) for usage.

Let me know if this works for you.

ekshaks avatar May 17 '20 11:05 ekshaks

That sounds great, especially the update_len call is what I needed 👍

finngaida avatar May 18 '20 16:05 finngaida