Repository navigation
A new AdapterOperator hierarchy, usable for convenient device/impl changes in operator pipelines. - #1722
Conversation
ca93aa8 to
59f96e4
Compare
This will be used for device changes etc. in pipelines that cannot use a single backend / device throughout.
…ators for their `_call`s. This avoids duplicate definition of the logic in the raw and operatorized form of an adapter.
… `@` over `*`. We decided earlier that the use of `*` for composition is confusing / error prone because it contradicts the behaviour of array libraries. The documentation should reflect that.
In 9a6761e that was accidentally changed, so for example the `repr` of an `OperatorComp` would show the exact class for the outer constructor but then defer to the shorter but less precise `str` for the operators being composed. This lead to inconsistent appearances.
They can now be composed both with other adapters, and with ordinary operators in arbitrary order.
These are unlikely to be useful per se, but make sense to include for completeness. What actually will be used in practice are the inverses of the concrete operator forms of the adapters (which is what `AdapterInverse` defers to).
…n of a test for device and impl change
…adapters. This is useful for only changing one (or some) of the participants of a product-space input.
As it turns out, using `odl_impl_device_pairs` directly in this function would cause it to see always the same impl and device as the `tspace`, since that itself is based on `odl_impl_device_pairs`. In that case the adapters are of course all trivial! Fortunately, the adapters themselves still work also under properly scrutinizing tests.
44fdcee to
79ac0eb
Compare
|
I'd say this feature is complete enough now, all that's left to do is mentioning the adapters in the Readthedocs. |
| >>> odl.rn(2).element([8,9]).to_impl('pytorch') | ||
| rn(2, 'float64', 'pytorch').element([ 8., 9.]) | ||
|
|
||
| These cannot be used as part of operator pipelines, though. |
There was a problem hiding this comment.
"These cannot be used as part of operator pipelines, though." Finishing the documentation with this sentence reads like the AdapterOperators cannot be used on pipelines. I would rephrase it as "Converting the device or implementation of a TensorSpace using the to_device/to_impl methods is not suited for operator composition, hence the need for the AdapterOperators."
There was a problem hiding this comment.
Good point, this might be misunderstood.
| raise OpTypeError( | ||
| odl.OpTypeError: `range` rn(4, 'float64', 'pytorch') of the right operator x * [ 10., 20., 30., 40.] not equal to the domain rn(4) of the left operator x * [ 1., 2., 3., 4.] | ||
|
|
||
| In situations where you are sure you need a copying step, you can use adapter-operators. |
There was a problem hiding this comment.
"... which wrap backend-specific device and implementation conversion and Operator syntax."
| In situations where you are sure you need a copying step, you can use adapter-operators. | ||
| These are conceptually identity operators but with different backends / devices for their domain and range. | ||
| For example, to change the device from CPU to the GPU, use `DeviceChange` with ``domain_device='cpu'`` and ``range_device='cuda:0'``. | ||
| Beware that the domain device is the first/left argument here, whereas the `@` composition has a right-to-left dataflow! |
There was a problem hiding this comment.
"Note that, unlike the @ composition, which has a right-to-left dataflow, the AdapterOperator has a domain-to-device syntax."
Emvlt
left a comment
There was a problem hiding this comment.
The AdapterOperator class looks great! Good work @leftaroundabout :)
I would make some changes to the documentation (hence the Request Changes), but the tests pass on my env :)
Condition to these passing on the CUDA-equiped machines, we should be able to merge the changes.
| >>> odl.rn(2).element([8,9]).to_impl('pytorch') | ||
| rn(2, 'float64', 'pytorch').element([ 8., 9.]) | ||
|
|
||
| These cannot be used as part of operator pipelines, though. |
There was a problem hiding this comment.
| These cannot be used as part of operator pipelines, though. | |
| These methods are not fully-fledged operators (with adjoint etc.) though, so for conversion within operator pipelines it is necessary to use `AdapterOperator`s. |
Hm actually that would also be misleading because AdapterOperator does not itself offer adjoint, either...
| These cannot be used as part of operator pipelines, though. | |
| These methods are not standalone objects though, so for conversion within operator pipelines it is necessary to use `AdapterOperator`s. |
Based on remarks by @Emvlt
No description provided.