Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[branching io manager][fix] Fix loading partitioned parent assets in BranchingIOManager #18491

Merged
merged 7 commits into from
Dec 12, 2023

Conversation

benpankow
Copy link
Member

@benpankow benpankow commented Dec 5, 2023

Summary

Tweak of fix in #17303 which uses the upstream asset partition rather than the current asset partition when using the branching IO manager. Uses context.asset_partition_key rather than the upstream output's partition key, which can sometimes be None when the upstream output is not available.

Test Plan

Adds a new unit test with a non-standard partition mapping, which previously failed.

@benpankow
Copy link
Member Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@smackesey
Copy link
Collaborator

I'm confused as to why InputContext.asset_partition_key and InputContext.partition_key differ in the first place. Shouldn't the InputContext.partition_key be scoped to the input being loaded instead of the run? Do we ever use the run value?

@danielgafni
Copy link
Contributor

danielgafni commented Dec 5, 2023

We might not be loading an asset at all. The IOManager should also work for normal jobs. This is because it’s often used as a drop-in replacement for an existing IOManager.

@smackesey
Copy link
Collaborator

smackesey commented Dec 5, 2023

We might not be loading an asset at all. The IOManager should also work for normal jobs. This is because it’s often used as a drop-in replacement for an existing IOManager.

That's true, but the question I'm raising is about InputContext.partition_key. Seems to me this should mean "partition key for the input that this InputContext is defined for". In cases where that key matches the run partition key, then OK. But when it doesn't, then it should be set to the appropriate key.

@danielgafni
Copy link
Contributor

Sorry, I don’t see any tests logs or anything. Maybe that’s because I’m on mobile, not sure. Anyway, keeping this use case in mind (working with non-assets) is all what I wanted to point out, and it seems like we are on the same page about this :)

@benpankow
Copy link
Member Author

I'm confused as to why InputContext.asset_partition_key and InputContext.partition_key differ in the first place. Shouldn't the InputContext.partition_key be scoped to the input being loaded instead of the run? Do we ever use the run value?

I'm not sure why it's set to be the partition for the asset that's currently being materialized.

It is pretty confusing especially since the two properties would seemingly be the same thing - the input manager should really be agnostic to what's being produced in the actual compute step.

We might not be loading an asset at all. The IOManager should also work for normal jobs. This is because it’s often used as a drop-in replacement for an existing IOManager.

This is a good call-out - right now if there's no upstream asset involved the IO manager will fallback to None partition, so it should continue to work in the op case. Will add a test just to sanity check.

@benpankow benpankow force-pushed the benpankow/fix-branching-io-manager branch from 13f501c to dc9f19e Compare December 5, 2023 23:49
@smackesey
Copy link
Collaborator

smackesey commented Dec 6, 2023

I'm not sure why it's set to be the partition for the asset that's currently being materialized.

It is pretty confusing especially since the two properties would seemingly be the same thing - the input manager should really be agnostic to what's being produced in the actual compute step.

My inclination is to consider this a bug and change it so that partition_key and asset_partition_key are the same. Curious what @alangenfeld thinks of this.

To summarize Alex, InputContext.partition_key currently is the partition key of the run while InputContext.asset_partition_key is the partition_key of the key of the upstream asset partition being loaded. IMO partition_key should always indicate the partition key of the input being loaded, which would be the same as asset_partition_key for asset runs.

Copy link
Member

@alangenfeld alangenfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This touches on the complexity around how partitioning works and is modeled that I don't have a great grasp on.

I don't think its OK to make a breaking change the @public partition_key method, until 2.0 given my understanding of our policy. My first reaction was that maybe we could deprecate it and replace it with run_partition_key to more clearly disambiguate, but I don't have confidence that thats the right move.

When does the upstream output partition key differ from the run partition key in the non asset case? From what I understand you can only attach PartitionMapping to assets.

Comment on lines 78 to 81
try:
partition_key = context.asset_partition_key
except CheckError:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there not a better way to do this? would prefer adding a has_ over control flow exceptions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, updated to handle the multi-partition-key case and this logic is a bit cleaner now.

else None
)
try:
partition_key = context.asset_partition_key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about for other complex partition mapping schemes where asset_partition_key would raise due to there being more than 1 value? https://github.com/dagster-io/dagster/blob/master/python_modules/dagster/dagster/_core/execution/context/input.py#L347-L350

Copy link
Member Author

@benpankow benpankow Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated logic & added test case, should be able to handle non-standard (e.g. many-to-one) partition mappings now.

@@ -69,10 +70,20 @@ def load_input(self, context: InputContext) -> Any:
return self.branch_io_manager.load_input(context)
else:
# we are dealing with an asset input
partition_key = (
context.upstream_output.partition_key
if context.upstream_output and context.upstream_output.has_partition_key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benpankow benpankow force-pushed the benpankow/fix-branching-io-manager branch from 7531548 to 4b47f02 Compare December 7, 2023 18:09
@benpankow benpankow requested a review from alangenfeld December 7, 2023 18:09
@smackesey
Copy link
Collaborator

When does the upstream output partition key differ from the run partition key in the non asset case? From what I understand you can only attach PartitionMapping to assets.

Pretty sure it doesn't. So it would only change in the asset case. I am supportive of introducing run_partition_key and changing partition_key to reflect the input in 2.0 (with a warning introduced in the meantime, that we can emit only if we are loading an asset).

@benpankow benpankow force-pushed the benpankow/fix-branching-io-manager branch from c7daeea to 7bee3fd Compare December 7, 2023 18:28
Copy link
Member

@alangenfeld alangenfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version seems like a more principled fix to me, I assume the cases that danielgafni mentioned above are under test somewhere so this continues to work for them?

)
for partition_key in partition_keys
]
if all(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful here on all([]) == True if nothing comes back - may want an explicit check for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
if (
event_log_entry

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a little comment block explaining why were doing this would be nice, make [1] easier to grok

partition_keys = context.asset_partition_keys

if len(partition_keys) == 0:
partition_keys = [None]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[1]

@benpankow benpankow force-pushed the benpankow/fix-branching-io-manager branch from 7bee3fd to 39e178d Compare December 11, 2023 23:31
Copy link

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-eebygj240-elementl.vercel.app
https://benpankow-fix-branching-io-manager.components-storybook.dagster-docs.io

Built with commit 39e178d.
This pull request is being automatically deployed with vercel-action

Copy link

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-8z1knpx0x-elementl.vercel.app
https://benpankow-fix-branching-io-manager.core-storybook.dagster-docs.io

Built with commit 39e178d.
This pull request is being automatically deployed with vercel-action

Copy link

Deploy preview for dagster-docs ready!

Preview available at https://dagster-docs-39dn3bt9j-elementl.vercel.app
https://benpankow-fix-branching-io-manager.dagster.dagster-docs.io

Direct link to changed pages:

@benpankow benpankow merged commit 262853f into master Dec 12, 2023
3 checks passed
@benpankow benpankow deleted the benpankow/fix-branching-io-manager branch December 12, 2023 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants