Closed elanmart closed 3 years ago
The source of the issue is that order of arguments is different for models with optional and non-optional args
@mcx.model
def model(x):
a <~ dist.Normal(0, 1)
return a
gives
<function __main__.model_sample_posterior_predictive(rng_key, x, a)>
While
@mcx.model
def model(x = None):
a <~ dist.Normal(0, 1)
return a
gives
<function __main__.model_sample_posterior_predictive(rng_key, a, x=None)>
I'd actually suggest to make it impossible to pass non-keyword arguments to those generated functions, I guess it would simplify things a lot.
Alternative would be to always generate a signature of type func(*params, *model_args, **model_kwargs)
.
I'd actually suggest to make it impossible to pass non-keyword arguments to those generated functions, I guess it would simplify things a lot.
Yes, that would make things a lot easier. The reason why there is a difference is that I didn't need to pay attention to that: in the core, everything is passed as a keyword argument.
Alternative would be to always generate a signature of type
func(*params, *model_args, **model_kwargs)
.
In terms of usability, which of these two options would you say is best?
(again, thank you for raising an issue!)
In terms of usability, which of these two options would you say is best?
After a second thought, actually I don't think it would be a good idea to go with "keyword-only" option.
So the generated functions would have to have the signature func(key, *params, *model_args, **model_kwargs)
Basically the same signature as the original function?
@elanmart There is actually a good reason why things are as they currently are; I will go with your solution and will try to write the patch to fix #90 at the same time.
@rlouf thanks a lot! In the meantime I've just patched my local version of mcx
so I can carry on without issues. For #90 I also have a small workaround, so it's all fine for now :)
Cool! I'll go through the outstanding issues and missing features next week or the week after that. Hopefully this and the key splitting issue will be solved. Let me know if you find anything else.
@elanmart This was fixed in #106
Given the model:
This code: https://github.com/rlouf/mcx/blob/master/mcx/model.py#L218-L220
Will generate a function with a signature
model_sample_posterior_predictive(rng_key, x, a)
This function will then be called here: https://github.com/rlouf/mcx/blob/master/mcx/model.py#L226-L228 passing
*self.trace.chain_values(self.chain_id)
asx
.The fix is to modify the
generative_function.__call__
method to