This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Add_SimpleCategorical #1169
Closed
Closed
Add_SimpleCategorical #1169
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
caac99b
Add_SimpleCategorical
enkilee 458f76b
fix
enkilee 1775934
fix
enkilee 7e22183
fix
enkilee 65b8638
fix
enkilee 982db95
fix
enkilee e1b7557
fix
enkilee d73ea55
fix
enkilee e750ae2
fix
enkilee 67f0d79
fix format
enkilee 617d246
fix
enkilee 59132d8
format
enkilee 5c4f636
Merge branch 'develop' into Add_SampleCategorica
enkilee ccfd29f
fix
enkilee f8e318d
fix
enkilee File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ class ScheduleImpl { | |
void FlattenLoops(const std::vector<Expr>& loops, const bool force_flat = false); | ||
void CopyTransformAndLoopInfo(const Expr& block, const Expr& block_target); | ||
void CopyTransformAndLoopInfo(const std::string& block_name, const std::string& block_target_name); | ||
Expr SimpleCategorical(const std::vector<int>& candidates, const std::vector<float>& probs); | ||
|
||
private: | ||
void Replace(const Expr& src_sref, const Expr& tgt_stmt); | ||
|
@@ -1692,6 +1693,25 @@ void ScheduleImpl::FlattenLoops(const std::vector<Expr>& loops, const bool flat_ | |
this->Replace(loops[0], loop); | ||
} | ||
|
||
Expr ScheduleImpl::SimpleCategorical(const std::vector<int>& candidates, const std::vector<float>& probs) { | ||
int i = -1; | ||
// check two sizes | ||
CHECK_EQ(candidates.size(), probs.size()) << "candidates and probs must have same size."; | ||
// generate | ||
std::vector<double> weights; | ||
for (auto p : probs) { | ||
weights.push_back(p); | ||
} | ||
std::discrete_distribution<int32_t> prob_int(weights.begin(), weights.end()); | ||
|
||
std::random_device seed; | ||
std::default_random_engine engine(seed()); | ||
Comment on lines
+1707
to
+1708
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可参照SamplePerfectTile实现,在内部ScheduleImpl实现函数中新增参数传入随机数种子https://github.com/PaddlePaddle/CINN/blob/develop/cinn/ir/ir_schedule.cc#L2089 |
||
i = prob_int(engine); | ||
auto result = candidates[i]; | ||
Expr result_Expr(result); | ||
return result_Expr; | ||
} | ||
|
||
void ScheduleImpl::CopyTransformAndLoopInfo(const std::string& block_name, const std::string& block_target_name) { | ||
auto block = this->GetBlock(block_name); | ||
auto block_target = this->GetBlock(block_target_name); | ||
|
@@ -2093,6 +2113,10 @@ std::vector<Expr> IRSchedule::SamplePerfectTile(const Expr& loop, int n, int max | |
{result})); | ||
return result; | ||
} | ||
|
||
Expr IRSchedule::SimpleCategorical(const std::vector<int>& candidates, const std::vector<float>& probs) { | ||
auto result = impl_->SimpleCategorical(candidates, probs); | ||
trace_.Append(ScheduleDesc::Step("SimpleCategorical", {}, {{"candidates", candidates}, {"probs", probs}}, {result})); | ||
return result; | ||
} | ||
} // namespace ir | ||
} // namespace cinn |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在schedule_desc.cc添加注册SimpleCategorical Step类型,并在schedule_desc_test.cc中补充对应单测,可参照其它原语实现