mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Some performance fixes (#94034)
Applies some performance fixes Pull Request resolved: https://github.com/pytorch/pytorch/pull/94034 Approved by: https://github.com/Skylion007
This commit is contained in:
@ -276,7 +276,7 @@ struct TORCH_API Node : std::enable_shared_from_this<Node> {
|
||||
|
||||
void add_next_edge(Edge edge) {
|
||||
update_topological_nr(edge);
|
||||
next_edges_.push_back(std::move(edge));
|
||||
next_edges_.emplace_back(std::move(edge));
|
||||
}
|
||||
|
||||
void set_next_edges(edge_list&& next_edges) {
|
||||
@ -456,7 +456,7 @@ struct TORCH_API Node : std::enable_shared_from_this<Node> {
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
uintptr_t add_post_hook(std::unique_ptr<FunctionPostHook>&& post_hook) {
|
||||
post_hooks_.push_back(std::move(post_hook));
|
||||
post_hooks_.emplace_back(std::move(post_hook));
|
||||
// Use the raw pointer as the unique key to identify this hook. This key
|
||||
// can then be used in del_post_hook(key) to remove this hook.
|
||||
return reinterpret_cast<std::uintptr_t>(post_hooks_.back().get());
|
||||
@ -483,11 +483,11 @@ struct TORCH_API Node : std::enable_shared_from_this<Node> {
|
||||
}
|
||||
|
||||
void add_pre_hook(std::unique_ptr<FunctionPreHook>&& pre_hook) {
|
||||
pre_hooks_.push_back(std::move(pre_hook));
|
||||
pre_hooks_.emplace_back(std::move(pre_hook));
|
||||
}
|
||||
|
||||
void add_tensor_pre_hook(std::unique_ptr<FunctionPreHook>&& pre_hook) {
|
||||
tensor_pre_hooks_.push_back(std::move(pre_hook));
|
||||
tensor_pre_hooks_.emplace_back(std::move(pre_hook));
|
||||
}
|
||||
|
||||
void add_retains_grad_hook(
|
||||
@ -672,7 +672,7 @@ struct MakeNextFunctionList : IterArgs<MakeNextFunctionList> {
|
||||
void operator()(const Variable& variable) {
|
||||
// NOLINTNEXTLINE(bugprone-branch-clone)
|
||||
if (variable.defined()) {
|
||||
next_edges.push_back(impl::gradient_edge(variable));
|
||||
next_edges.emplace_back(impl::gradient_edge(variable));
|
||||
} else {
|
||||
next_edges.emplace_back();
|
||||
}
|
||||
@ -680,7 +680,7 @@ struct MakeNextFunctionList : IterArgs<MakeNextFunctionList> {
|
||||
void operator()(const Variable* variable) {
|
||||
// NOLINTNEXTLINE(bugprone-branch-clone)
|
||||
if (variable->defined()) {
|
||||
next_edges.push_back(impl::gradient_edge(*variable));
|
||||
next_edges.emplace_back(impl::gradient_edge(*variable));
|
||||
} else {
|
||||
next_edges.emplace_back();
|
||||
}
|
||||
@ -688,7 +688,7 @@ struct MakeNextFunctionList : IterArgs<MakeNextFunctionList> {
|
||||
void operator()(const c10::optional<Variable>& variable) {
|
||||
// NOLINTNEXTLINE(bugprone-branch-clone)
|
||||
if (variable.has_value() && variable->defined()) {
|
||||
next_edges.push_back(impl::gradient_edge(*variable));
|
||||
next_edges.emplace_back(impl::gradient_edge(*variable));
|
||||
} else {
|
||||
next_edges.emplace_back();
|
||||
}
|
||||
|
Reference in New Issue
Block a user