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

Misc changes from compiled autograd branch #104316

Closed
wants to merge 7 commits into from

Conversation

jansel
Copy link
Contributor

@jansel jansel commented Jun 28, 2023

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 28, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104316

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b9276f5:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link
Contributor

@wconstab wconstab left a comment

Choose a reason for hiding this comment

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

these lgtm, except maybe the private thing. maybe @albanD can also take a look

self.create_symbol(
value,
source=source,
dynamic_dim=dynamic_dim,
Copy link
Contributor

Choose a reason for hiding this comment

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

was it significant to remove constraint_dim=none here?

was there any actual change other than code motion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just code motion so it can be reused in the next PR.

constraint_dim=none is the default value.

@@ -2807,12 +2807,6 @@ def forward(ctx, *deduped_flat_tensor_args):
)

num_outputs = CompiledFunction.metadata.num_outputs
num_outputs_aliased_to_inputs = (
Copy link
Contributor

Choose a reason for hiding this comment

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

dead code removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@@ -52,7 +52,6 @@ struct TypeAndSize {

Tensor zeros() { return at::zeros_symint(sym_sizes, options); }

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

is it nontrivial to utilize accessors for these from the codegen code or just more convenient this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The visitors need to mutate these. I could do a mutable reference accessor, but this is more convenient.

torch/_dynamo/variables/builder.py Show resolved Hide resolved
c10::SymInt& mutable_storage_offset() {
return storage_offset_;
}
void recompute() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be called from the constructor as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like the constructor is using a cached copy of numel?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes and we compute it alongside of the stride for the contiguous case.
I guess not re-use it is ok then!

aten/src/ATen/TensorGeometry.h Outdated Show resolved Hide resolved
@@ -113,6 +113,27 @@ struct TORCH_API TensorGeometry {
return r;
}

std::vector<c10::SymInt>& mutable_sizes() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the thread-safety story on these?
I haven't dived into how they are used in the other PR but this structure is saved on the graph which can be used in multiple threads at the same time. So if this is not read-only anymore, do we need to add locking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code using this in the other PR only uses a single thread.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How do you guarantee that? The user could be calling backward() from multiple threads?

Copy link
Contributor Author

@jansel jansel Jul 6, 2023

Choose a reason for hiding this comment

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

We could add a lock around compiled_autograd tracing. Since we are mutating nodes in-place, it is not thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this isn't needed. This is already protected by:

pybind11::gil_scoped_acquire gil;

Copy link
Collaborator

Choose a reason for hiding this comment

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

The gil doesn't create critical blocks. In can be released in most places in there and another thread pick up.
Also you could have a vanilla backward running in another thread that would not hold the gil right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a lock in the other PR. compiled_autograd is enabled per-process, so mixing it between threads is not supported.

This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
@jansel jansel requested a review from albanD June 29, 2023 16:26
Copy link
Collaborator

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

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

Nit

aten/src/ATen/TensorGeometry.h Outdated Show resolved Hide resolved
This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
@jansel
Copy link
Contributor Author

jansel commented Jul 6, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 6, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: inductor / linux-focal-cpu-py3.8-gcc7-inductor / test (inductor_torchbench_dynamic_cpu_accuracy, 1, 1, linux.12xlarge)

Details for Dev Infra team Raised by workflow job

This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
This PR pulls out some standalone changes from #103822


cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78

[ghstack-poisoned]
@jansel
Copy link
Contributor Author

jansel commented Jul 8, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@facebook-github-bot facebook-github-bot deleted the gh/jansel/138/head branch July 12, 2023 14:16
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.

None yet

6 participants