From be82624679578babad43140a59c848e37525a972 Mon Sep 17 00:00:00 2001 From: Chenyu Liu Date: Fri, 22 Jul 2022 00:41:52 -0700 Subject: [PATCH] Update computeAttributions function (#1309) Summary: Pull Request resolved: https://github.com/facebookresearch/fbpcs/pull/1309 # Reformat Attribution Output We will apply performance improvements to private attribution product (game) by changing the format of attribution result. For this we will need to make changes to both private attribution and private aggregation stages. The original format of attribution result is: { "last_click_1d": { "default": { "0": [ { "is_attributed": true }, { "is_attributed": false }, { "is_attributed": false }, { "is_attributed": false }, { "is_attributed": false } ] } } } Proposed format: [ {ad_id, conversion_value, is_attributed}, {ad_id, conversion_value, is_attributed}, {ad_id, conversion_value, is_attributed}, {ad_id, conversion_value, is_attributed}, ] The design plan: https://docs.google.com/document/d/1QyBtCkTeZA8IXAkok0n8EhfCZeLTU0SSN1VL57vjBCo/edit?usp=sharing # This Diff Update computeAttributions function. # This Stack 1. Add a flag to validate whether to use new vs old output format in Private Attribution. 2. Modify PCS stage for attribution with the new flag. 3. Parse the input for new output format. 4. Add a new output format file in attribution game. 5. Add ComputAttributionHelperV2 function for new output format. 6. **Update computeAttributions function.** 7. Update unit tests for PCF2 Attribution logic. 8. Add json test files for new output format. 9. Modify revealXORedResult method for new output. 10. Add unit tests for new output format - testCorrectness. Reviewed By: chualynn Differential Revision: D37867483 fbshipit-source-id: 5b4ab2de85f061b01b86ae4ab8da3eaaed56ba19 --- .../pcf2_attribution/AttributionGame_impl.h | 96 +++++++++++++------ 1 file changed, 67 insertions(+), 29 deletions(-) diff --git a/fbpcs/emp_games/pcf2_attribution/AttributionGame_impl.h b/fbpcs/emp_games/pcf2_attribution/AttributionGame_impl.h index 5340df9ec..60e10773b 100644 --- a/fbpcs/emp_games/pcf2_attribution/AttributionGame_impl.h +++ b/fbpcs/emp_games/pcf2_attribution/AttributionGame_impl.h @@ -456,39 +456,77 @@ AttributionGame::computeAttributions( CHECK_EQ(thresholdArrays.size(), tpArrays.size()) << "threshold arrays and touchpoint arrays are not the same length."; - std::vector> attributions; + if (FLAGS_use_new_output_format) { + std::vector> + attributionsReformatted; + + if constexpr (usingBatch) { + attributionsReformatted = computeAttributionsHelperV2( + tpArrays, convArrays, *attributionRule, thresholdArrays, numIds); + + } else { + // Compute row by row if not using batch + for (size_t i = 0; i < numIds; ++i) { + auto attributionReformattedRow = computeAttributionsHelperV2( + tpArrays.at(i), + convArrays.at(i), + *attributionRule, + thresholdArrays.at(i), + numIds); + attributionsReformatted.push_back( + std::move(attributionReformattedRow)); + } + } + AttributionReformattedOutput + attributionReformattedOutput{ids, attributionsReformatted}; + XLOGF( + INFO, + "Retrieving attribution results for rule {}.", + attributionRule->name); + attributionMetrics.formatToAttribution[attributionFormat] = + attributionReformattedOutput.reveal(); + out.ruleToMetrics[attributionRule->name] = attributionMetrics; + + XLOGF( + INFO, + "Done computing attributions for rule {}.", + attributionRule->name); - if constexpr (usingBatch) { - attributions = computeAttributionsHelper( - tpArrays, convArrays, *attributionRule, thresholdArrays, numIds); } else { - // Compute row by row if not using batch - for (size_t i = 0; i < numIds; ++i) { - auto attributionRow = computeAttributionsHelper( - tpArrays.at(i), - convArrays.at(i), - *attributionRule, - thresholdArrays.at(i), - numIds); - attributions.push_back(std::move(attributionRow)); + std::vector> attributions; + + if constexpr (usingBatch) { + attributions = computeAttributionsHelper( + tpArrays, convArrays, *attributionRule, thresholdArrays, numIds); + } else { + // Compute row by row if not using batch + for (size_t i = 0; i < numIds; ++i) { + auto attributionRow = computeAttributionsHelper( + tpArrays.at(i), + convArrays.at(i), + *attributionRule, + thresholdArrays.at(i), + numIds); + attributions.push_back(std::move(attributionRow)); + } } - } - AttributionOutput attributionOutput{ - ids, attributions}; - - XLOGF( - INFO, - "Retrieving attribution results for rule {}.", - attributionRule->name); - attributionMetrics.formatToAttribution[attributionFormat] = - attributionOutput.reveal(); - out.ruleToMetrics[attributionRule->name] = attributionMetrics; - - XLOGF( - INFO, - "Done computing attributions for rule {}.", - attributionRule->name); + AttributionOutput attributionOutput{ + ids, attributions}; + + XLOGF( + INFO, + "Retrieving attribution results for rule {}.", + attributionRule->name); + attributionMetrics.formatToAttribution[attributionFormat] = + attributionOutput.reveal(); + out.ruleToMetrics[attributionRule->name] = attributionMetrics; + + XLOGF( + INFO, + "Done computing attributions for rule {}.", + attributionRule->name); + } } return out; }