forked from facebookresearch/beanmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minibmg: precompute and optimize expression trees to be used during i…
…nference (facebookresearch#1793) Summary: Pull Request resolved: facebookresearch#1793 Precompute the expression trees needed to evaluate the graph for NUTS. Avoids all use of AD during inference. This brings our performance to slightly faster than bmg. Reviewed By: rodrigodesalvobraz Differential Revision: D40813973 fbshipit-source-id: 335b1789cef73f742bbac996e82884e7f111c0a3
- Loading branch information
1 parent
f07bc3f
commit 3970cf1
Showing
16 changed files
with
438 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "beanmachine/minibmg/eval.h" | ||
#include <stdexcept> | ||
|
||
namespace beanmachine::minibmg { | ||
|
||
RecursiveNodeEvaluatorVisitor::RecursiveNodeEvaluatorVisitor( | ||
std::function<double(const std::string& name, const int identifier)> | ||
read_variable) | ||
: read_variable{read_variable} {} | ||
|
||
void RecursiveNodeEvaluatorVisitor::visit(const ScalarVariableNode* node) { | ||
result = read_variable(node->name, node->identifier); | ||
} | ||
|
||
void RecursiveNodeEvaluatorVisitor::visit(const ScalarSampleNode*) { | ||
throw std::logic_error("recursive evaluator may not sample"); | ||
} | ||
|
||
Real RecursiveNodeEvaluatorVisitor::evaluate_input(const ScalarNodep& node) { | ||
return evaluate_scalar(node); | ||
} | ||
|
||
std::shared_ptr<const Distribution<Real>> | ||
RecursiveNodeEvaluatorVisitor::evaluate_input_distribution( | ||
const DistributionNodep&) { | ||
throw std::logic_error( | ||
"recursive evaluator may not traffic in distributions"); | ||
} | ||
|
||
double eval_node( | ||
RecursiveNodeEvaluatorVisitor& evaluator, | ||
const ScalarNodep& node) { | ||
return evaluator.evaluate_scalar(node).value; | ||
} | ||
|
||
} // namespace beanmachine::minibmg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.