Skip to content

Add a tagged union type that replaces tensor in the interpreter.#9368

Closed
zdevito wants to merge 2 commits intopytorch:masterfrom
zdevito:pr/interpreter_value
Closed

Add a tagged union type that replaces tensor in the interpreter.#9368
zdevito wants to merge 2 commits intopytorch:masterfrom
zdevito:pr/interpreter_value

Conversation

@zdevito
Copy link
Contributor

@zdevito zdevito commented Jul 11, 2018

IValue is short for interpreter value. It is used frequently so a short name is important.
This will allow us to implement more non-tensor types in an efficient way and remove
many hacks from the compiler.

This PR is limited. It only introduces IValue and changes interpreter to use it.
Follow up PRs will:

  • Change the way aten_ops consume non-tensor types so that integer lists,
    are no longer represented as Tensors.
  • Introduce TensorList as a fundamental type and remove all vararg handling in gen_jit_dispatch
  • Change the compiler to implement math on primitive numbers rather than converting to tensors.

@jamesr66a @apaszke

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

IValue is short for interpreter value. It is used frequently so a short name is important.
This will allow us to implement more non-tensor types in an efficient way and remove
many hacks from the compiler.

This PR is limited. It only introduces IValue and changes interpreter to use it.
Follow up PRs will:
* Change the way aten_ops consume non-tensor types so that integer lists,
  are no longer represented as Tensors.
* Introduce TensorList as a fundamental type and remove all vararg handling in gen_jit_dispatch
* Change the compiler to implement math on primitive numbers rather than converting to tensors.
@zdevito zdevito force-pushed the pr/interpreter_value branch from 6ed3af6 to 569e13f Compare July 12, 2018 05:41
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some suggestions that might make the code nicer, but nothing big.

std::vector<at::Tensor> toTensors(at::ArrayRef<IValue> ivalues) {
return fmap(ivalues, [](const IValue& v) {
return v.toTensor();
});

This comment was marked as off-topic.


// helper to run interpreter on variables until we switch
// everything to IValue
inline variable_tensor_list runOneStage(const Code & code, variable_tensor_list inputs) {

This comment was marked as off-topic.

This comment was marked as off-topic.

inline variable_tensor_list runOneStage(const Code & code, variable_tensor_list inputs) {
std::vector<IValue> stack(inputs.begin(), inputs.end());
InterpreterState(code).runOneStage(stack);
// note: we never unwrapped inputs, because we want autograd to record the trace

This comment was marked as off-topic.

This comment was marked as off-topic.

std::vector<IValue> unwrapVariables(variable_tensor_list && list) const {
return fmap(list, [](const Variable& v) -> IValue {
return v.defined() ? autograd::as_variable_ref(v).detach() : at::Tensor();
});

This comment was marked as off-topic.

This comment was marked as off-topic.

}
private:
PointerType * pImpl;
};

This comment was marked as off-topic.

This comment was marked as off-topic.

return [num_inputs](Stack& stack) {
bool first = true;
for (at::Tensor i : last(stack, num_inputs)) {
for (IValue i_ : last(stack, num_inputs)) {

This comment was marked as off-topic.

auto list = constant_as<at::IntList>(input);
auto list = constant_as<std::vector<int64_t>>(input);
if(list)
return std::vector<int64_t>(*list);

This comment was marked as off-topic.

// outputs for that stage, suspending the computation.
// Call this function again continues computation where it left off.
void runOneStage(std::vector<at::Tensor> & stack);
void runOneStage(std::vector<IValue> & stack);

This comment was marked as off-topic.

auto foo2 = std::move(bar);
JIT_ASSERT(foo->use_count() == 3);
JIT_ASSERT(foo2.isIntList());
JIT_ASSERT(bar.isInt());

This comment was marked as off-topic.


auto move_it = std::move(baz).toIntList();
JIT_ASSERT(foo->use_count() == 2);
JIT_ASSERT(baz.isInt());

This comment was marked as off-topic.

* Adds a None type for default values
* Other minor fixes.
@zdevito zdevito force-pushed the pr/interpreter_value branch from e0570f9 to c1d2413 Compare July 16, 2018 18:57
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

goldsborough pushed a commit to goldsborough/pytorch that referenced this pull request Jul 20, 2018
…orch#9368)

Summary:
IValue is short for interpreter value. It is used frequently so a short name is important.
This will allow us to implement more non-tensor types in an efficient way and remove
many hacks from the compiler.

This PR is limited. It only introduces IValue and changes interpreter to use it.
Follow up PRs will:
* Change the way aten_ops consume non-tensor types so that integer lists,
  are no longer represented as Tensors.
* Introduce TensorList as a fundamental type and remove all vararg handling in gen_jit_dispatch
* Change the compiler to implement math on primitive numbers rather than converting to tensors.

jamesr66a  apaszke
Pull Request resolved: pytorch#9368

Reviewed By: ezyang

Differential Revision: D8817598

Pulled By: zdevito

fbshipit-source-id: 29dce80611ce5f6384234de9d12a67861d2b112f
jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
…orch#9368)

Summary:
IValue is short for interpreter value. It is used frequently so a short name is important.
This will allow us to implement more non-tensor types in an efficient way and remove
many hacks from the compiler.

This PR is limited. It only introduces IValue and changes interpreter to use it.
Follow up PRs will:
* Change the way aten_ops consume non-tensor types so that integer lists,
  are no longer represented as Tensors.
* Introduce TensorList as a fundamental type and remove all vararg handling in gen_jit_dispatch
* Change the compiler to implement math on primitive numbers rather than converting to tensors.

jamesr66a  apaszke
Pull Request resolved: pytorch#9368

Reviewed By: ezyang

Differential Revision: D8817598

Pulled By: zdevito

fbshipit-source-id: 29dce80611ce5f6384234de9d12a67861d2b112f
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
…orch#9368)

Summary:
IValue is short for interpreter value. It is used frequently so a short name is important.
This will allow us to implement more non-tensor types in an efficient way and remove
many hacks from the compiler.

This PR is limited. It only introduces IValue and changes interpreter to use it.
Follow up PRs will:
* Change the way aten_ops consume non-tensor types so that integer lists,
  are no longer represented as Tensors.
* Introduce TensorList as a fundamental type and remove all vararg handling in gen_jit_dispatch
* Change the compiler to implement math on primitive numbers rather than converting to tensors.

jamesr66a  apaszke
Pull Request resolved: pytorch#9368

Reviewed By: ezyang

Differential Revision: D8817598

Pulled By: zdevito

fbshipit-source-id: 29dce80611ce5f6384234de9d12a67861d2b112f
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants