funsor icon indicating copy to clipboard operation
funsor copied to clipboard

Implement optimized GEMM-like ops for Tensor and Gaussian

Open fritzo opened this issue 6 years ago • 3 comments
trafficstars

  • [x] #281 For Tensor use a GEMM op, fixing the bugs in https://github.com/pyro-ppl/funsor/blob/d18c78e/funsor/torch.py#L495 (which only works for scalar event shape)
  • [ ] For Gaussian see pyro.ops.gaussian.gaussian_tensordot() pyro-ppl/pyro#1980 . This is lower priority than Tensor because the naive (x+y).reduce() version is only slightly more expensive.

fritzo avatar Sep 16 '19 23:09 fritzo

@eb8680 can you confirm that I can implement these as something like

@eager.register(Contraction, AddOp, MulOp, frozenset, Variadic[Tensor])
def eager_contract_tensor(red_op, bin_op, reduced_vars, *operands):
    equation = "TODO define an einsum string"
    data = pyro.ops.einsum.contract(equation, *(x.data for x in operands))
    inputs = "TODO"
    output = "TODO"
    return Tensor(data, inputs, output)

@eager.register(Contraction, LogaddexpOp, AddOp, frozenset, Variadic[Tensor])
def eager_contract_tensor(red_op, bin_op, reduced_vars, *operands):
    ...backend='pyro.ops.einsum.torch_log'...

fritzo avatar Oct 16 '19 18:10 fritzo

can you confirm

Yep, this should work as expected.

eb8680 avatar Oct 16 '19 18:10 eb8680

@fehiepsi did you already complete this?

fritzo avatar Mar 25 '20 20:03 fritzo