Skip to content

Commit

Permalink
Update computeAttributions function (#1309)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Chenyu Liu authored and facebook-github-bot committed Jul 22, 2022
1 parent 692e27e commit be82624
Showing 1 changed file with 67 additions and 29 deletions.
96 changes: 67 additions & 29 deletions fbpcs/emp_games/pcf2_attribution/AttributionGame_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,39 +456,77 @@ AttributionGame<schedulerId, usingBatch, inputEncryption>::computeAttributions(
CHECK_EQ(thresholdArrays.size(), tpArrays.size())
<< "threshold arrays and touchpoint arrays are not the same length.";

std::vector<SecBitT<schedulerId, usingBatch>> attributions;
if (FLAGS_use_new_output_format) {
std::vector<AttributionReformattedOutputFmtT<schedulerId, usingBatch>>
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<schedulerId, usingBatch>
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<SecBitT<schedulerId, usingBatch>> 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<schedulerId, usingBatch> 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<schedulerId, usingBatch> 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;
}
Expand Down

0 comments on commit be82624

Please sign in to comment.