Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat lazy tensor indexing #9334

Merged
merged 32 commits into from
Nov 23, 2022
Merged

Feat lazy tensor indexing #9334

merged 32 commits into from
Nov 23, 2022

Conversation

wyg1997
Copy link
Contributor

@wyg1997 wyg1997 commented Oct 28, 2022

lazy tensor indexing 支持。

主要处理了:

  • indexing functor 内对 eager/lazy mode 的管理,value tensor 可以做合适的预处理
  • 解决 lazy boxing 中对 0size tensor 没有处理,导致的程序崩溃

@wyg1997 wyg1997 marked this pull request as ready for review November 4, 2022 11:26
@wyg1997 wyg1997 changed the title [WIP] Feat lazy tensor indexing Feat lazy tensor indexing Nov 4, 2022
@wyg1997 wyg1997 requested a review from strint November 4, 2022 11:26
Scalar value_scalar = functional::PyUnpackScalar(value);
value_tensor = ASSERT_PTR(
functional::Constant(Shape({}), value_scalar, tensor->dtype(), ASSERT(tensor->device())));
std::shared_ptr<Tensor> value_tensor;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里代码太长,只是加了一个作用域

Comment on lines +566 to +567
// NOTE: LocalToGlobal should be called in eager mode
LazyMode::Guard lazy_mode_disabled_guard(/*is_enabled*/ false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

LocalToGlobal 只能在 eager 模式下调用

Comment on lines 106 to 112
/*static*/ Maybe<void> SliceUpdateOp::InferPhysicalTensorDesc(user_op::InferContext* ctx) {
return InferLogicalTensorDesc(ctx);
const user_op::TensorDesc& ref_desc = ctx->InputTensorDesc("ref", 0);
auto* y_desc = ctx->MutOutputTensorDesc("y", 0);
y_desc->set_shape(ref_desc.shape());
y_desc->set_is_dynamic(ref_desc.is_dynamic());
return Maybe<void>::Ok();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

之前 SliceUpdate 的物理 Tensor 推导是错误的,它支持 S + B -> S,是不能和逻辑 shape 推导共用推导函数(逻辑推导函数中有一些 shape 的检察,物理 tensor shape 推导不需要)

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 









❌ OneFlow resnet50 time: 140.5ms (= 14054.5ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 162.8ms (= 16276.3ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.16 (= 162.8ms / 140.5ms)

OneFlow resnet50 time: 85.3ms (= 8529.6ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 102.5ms (= 10254.7ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.20 (= 102.5ms / 85.3ms)

OneFlow resnet50 time: 58.1ms (= 11619.5ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 78.3ms (= 15669.7ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.35 (= 78.3ms / 58.1ms)

OneFlow resnet50 time: 44.1ms (= 8821.0ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 73.3ms (= 14653.6ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.66 (= 73.3ms / 44.1ms)

OneFlow resnet50 time: 41.7ms (= 8345.2ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 68.9ms (= 13780.2ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.65 (= 68.9ms / 41.7ms)

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9334/

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 









❌ OneFlow resnet50 time: 141.0ms (= 14099.6ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 168.3ms (= 16830.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 168.3ms / 141.0ms)

OneFlow resnet50 time: 86.1ms (= 8611.7ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 102.6ms (= 10263.0ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 102.6ms / 86.1ms)

OneFlow resnet50 time: 58.2ms (= 11638.5ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 78.0ms (= 15606.5ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.34 (= 78.0ms / 58.2ms)

OneFlow resnet50 time: 44.3ms (= 8856.9ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 71.2ms (= 14238.6ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.61 (= 71.2ms / 44.3ms)

OneFlow resnet50 time: 40.3ms (= 8058.9ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 73.7ms (= 14747.7ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.83 (= 73.7ms / 40.3ms)

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9334/

@wyg1997 wyg1997 requested review from oneflow-ci-bot and removed request for oneflow-ci-bot November 23, 2022 02:20
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 









❌ OneFlow resnet50 time: 141.0ms (= 14096.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 164.6ms (= 16455.1ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 164.6ms / 141.0ms)

OneFlow resnet50 time: 85.5ms (= 8547.5ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 101.3ms (= 10129.1ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 101.3ms / 85.5ms)

OneFlow resnet50 time: 57.6ms (= 11529.6ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 87.4ms (= 17484.0ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.52 (= 87.4ms / 57.6ms)

OneFlow resnet50 time: 44.3ms (= 8869.0ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 70.4ms (= 14086.8ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.59 (= 70.4ms / 44.3ms)

OneFlow resnet50 time: 40.3ms (= 8051.6ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 76.2ms (= 15246.5ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.89 (= 76.2ms / 40.3ms)

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 









❌ OneFlow resnet50 time: 141.6ms (= 14156.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 159.6ms (= 15958.5ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.13 (= 159.6ms / 141.6ms)

OneFlow resnet50 time: 86.0ms (= 8598.7ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 102.6ms (= 10258.6ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 102.6ms / 86.0ms)

OneFlow resnet50 time: 58.5ms (= 11708.1ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 77.9ms (= 15586.9ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.33 (= 77.9ms / 58.5ms)

OneFlow resnet50 time: 44.4ms (= 8887.2ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 83.0ms (= 16608.7ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.87 (= 83.0ms / 44.4ms)

OneFlow resnet50 time: 42.3ms (= 8458.8ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 67.6ms (= 13515.7ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.60 (= 67.6ms / 42.3ms)

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9334/

@mergify mergify bot merged commit 0434698 into master Nov 23, 2022
@mergify mergify bot deleted the feat-lazy_tensor_indexing branch November 23, 2022 07:16
farmerzhang1 pushed a commit that referenced this pull request Nov 30, 2022
* feat(boxing): collective_boxing slice_boxing support 0size tensor

* test(Indexing): add lazy tensor basic indexing

* add MaskTensor judgement

* format code

* feat(TensorIndexing): support lazy advance getitem indexing

* feat(Indexing): support lazy indexing for lazy_tensor and free_tensor

* fix(Indexing): fix indexing test bug

* test(Indexing): test all advance indexing

* test(GlobalIndexing): fix eager global indexing bug

* test(Indexing): support combined indexing

* add last test cases

* fix merge bug

* fix lazy mode guard

* test(Indexing): refine set scalar value test

* test(Indexing): enable all bool tensor index setitem

* decrease test time

* refine 0size shape judgement

* add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants