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

Add Galley option to compute() #79

Merged
merged 13 commits into from
Dec 5, 2024
Merged

Add Galley option to compute() #79

merged 13 commits into from
Dec 5, 2024

Conversation

kylebd99
Copy link
Collaborator

This PR enables galley optimization through the python interface in two ways 1) as a parameter to compute 2) by setting the global scheduler with set_optimizer.

@kylebd99
Copy link
Collaborator Author

kylebd99 commented Nov 19, 2024

All tests pass locally if you point to the Finch main branch.

@kylebd99
Copy link
Collaborator Author

Example Script:

import finch
import time

def main():
    A = finch.lazy(finch.random((1000, 1000), density=.5))
    B = finch.lazy(finch.random((1000, 1000), density=.5))
    C = finch.lazy(finch.random((1000, 1000), density=.01))
    finch.set_optimizer("galley")
    finch.compute(A @ B @ C)
    start = time.time()
    finch.compute(A @ B @ C)
    end = time.time()
    print("Galley Exec Time: ", end-start)
    finch.clear_optimizer_cache()
    finch.set_optimizer("default")
    finch.compute(A @ B @ C)
    start = time.time()
    finch.compute(A @ B @ C)
    end = time.time()
    print("Default Exec Time: ", end-start)
    return

main()

Galley Exec Time: 0.4668142795562744
Default Exec Time: 43.4676399230957

Copy link
Member

@mtsokol mtsokol left a comment

Choose a reason for hiding this comment

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

Overall, changes LGTM!

tests/test_ops.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@willow-ahrens willow-ahrens left a comment

Choose a reason for hiding this comment

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

This looks good, but I'd like to make the galley optimizer and the default optimizer be separate functions, so that we can pass them different options. does that make sense?

jl.Finch.set_scheduler_b(jl.Finch.galley_scheduler())
return

def clear_optimizer_cache():
Copy link
Collaborator

@willow-ahrens willow-ahrens Nov 26, 2024

Choose a reason for hiding this comment

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

This should not be necessary with the latest update (Finch 1.0.0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean the separate functions or the clearing of the cache?

I just checked and the cache is still being hit without the clearing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you pulled the latest finch? I just want to double check. It was my intention that Finch 1.0.0 would clear the cache if you use a different tag, but not if you use the same tag. the default does not clear the cache,

Copy link
Collaborator

Choose a reason for hiding this comment

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

if you want to clear it every time, you may want to give it a different tag every time

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if I will be able to clear the cache efficiently in future versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I see. I need to add tag parameters to this then. That makes sense. I'll update it with that.

@mtsokol
Copy link
Member

mtsokol commented Nov 27, 2024

Let's also make this PR one that moves to 1.0.0 Finch version (but I guess this is required here anyway).

@mtsokol
Copy link
Member

mtsokol commented Nov 27, 2024

Also, in pyproject.toml you can bump finch-tensor version. We can upgrade to version = "0.1.36" or 0.2.0 if it makes more sense. WDYT?

src/finch/compiled.py Outdated Show resolved Hide resolved
src/finch/compiled.py Outdated Show resolved Hide resolved
@kylebd99
Copy link
Collaborator Author

kylebd99 commented Dec 5, 2024

Pending @willow-ahrens final review, I think this is good to merge!

Copy link
Collaborator

@willow-ahrens willow-ahrens left a comment

Choose a reason for hiding this comment

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

a few very minor points.


class DefaultScheduler(AbstractScheduler):
def __init__(self, verbose=False):
self.verbose=verbose
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's put get_julia_scheduler inside the classes, so that we can pass different flags. Then we can just call opt.get_julia_scheduler() in compute.

self.verbose=verbose

def get_julia_scheduler(opt):
if isinstance(opt, DefaultScheduler):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just commenting that the isinstance checks can be avoided here, and make it more modular to change just one scheduler or extend in the future


def compute(tensor: Tensor, *, verbose: bool = False):
def compute(tensor: Tensor, *, verbose: bool = False, opt=None, tag=-1):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if tag=-1 is respected by Finch anymore, it will just be a tag named "-1" without a sentinel behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's fine I guess. It can just be the default tag, and programs can be cached unless the user makes a new tag.

@kylebd99 kylebd99 merged commit 79b6f0d into main Dec 5, 2024
5 checks passed
@kylebd99 kylebd99 deleted the kbd-add-galley branch December 5, 2024 22:51
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.

Corrupted double-linked list when running Galley scheduler
3 participants