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

(zeros|ones|full)_like and axes/tags #232

Open
majosm opened this issue May 23, 2023 · 2 comments
Open

(zeros|ones|full)_like and axes/tags #232

majosm opened this issue May 23, 2023 · 2 comments

Comments

@majosm
Copy link
Collaborator

majosm commented May 23, 2023

Argh, accidentally pressed Enter. Ignore for the moment. 🙂 (See below.)

@majosm majosm changed the title (zeros_like and (zeros|ones|full)_like and axes/tags May 23, 2023
@majosm
Copy link
Collaborator Author

majosm commented May 23, 2023

While debugging axis tagging I've run into a couple of snags with zeros_like, etc. and wanted to mention them for discussion.

  1. In Copy axes and tags in zeros_like/full_like #229, we modified these functions to propagate both axes and tags. In retrospect, I'm not sure if tags should be propagated. For example, when using Add tag to store array creation traceback pytato#284, this caused the CreatedAt tag from the source array to be propagated to the new array of zeros, giving the impression that the array was created somewhere where it wasn't. I'm not terribly familiar with the other tags, but I'm wondering if it makes much sense to propagate those either?
  2. Another issue I ran into is that since the result of zeros_like does not explicitly depend on the incoming source array, AFAIK axes are not able to be inferred from this array. In the case of a simulation state initialization, where the computation being done might only depend on nodes (i.e., no grudge operators are used), removing the dependency on the source could cut off the only source of axis inferral for the new array. I don't have a clear idea of how to fix this, apart from using the old 0*array method. Thoughts?

cc @inducer, @kaushikcfd, @matthiasdiener

@inducer
Copy link
Owner

inducer commented May 23, 2023

These are good questions. Thanks for raising them!

For your first question, a simple-but-perhaps-too-ad-hoc way of addressing the issue would be to tell tags (e.g. by being a subclass of PropagatableTag or so, with TBD semantics) whether they should propagate in inference and in situations like zeros_like. "Descriptive" tags definitely should propagate, but many others shouldn't. I'd welcome opinions on this.

The second one is thornier. 🤔 The problem, IIUC, is that information propagates from the "source" array to the "target" array only at the moment when zeros_like runs, but not after that. There's a menu of (bad?) options here for how to ensure information continues to propagate:

  • We could make a tag 🤦 to say so. A problem with this is that such a tag would hold a reference to another array, which would have to be replaced upon every DAG rewrite. I would guess that this would drive up the cost of DAG rewrites, because suddenly we have to go hunt for these arrays in the tags on every array we traverse.
  • We could make a less-bad version of 0*array. One way to do so would be a function zero(...) that returns zero no matter the input. (This would address the issue that 0*array propagates NaNs.) This would allow the connection from source to target to exist just long enough for tag propagation to work (with a definable axis mapping). Upon code generation, we might need to find a way to drop the spurious dependency edge.

None of these options are particularly lovely IMO. If there are better ideas, I'd be all ears.

majosm added a commit to majosm/arraycontext that referenced this issue May 25, 2023
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

No branches or pull requests

2 participants