Skip to content

Galley Sparse suitable rep#320

Open
ricky122-5 wants to merge 22 commits intomainfrom
sparse-suitable-rep
Open

Galley Sparse suitable rep#320
ricky122-5 wants to merge 22 commits intomainfrom
sparse-suitable-rep

Conversation

@ricky122-5
Copy link
Copy Markdown
Collaborator

#262

Python port of Finch.jl's Suitable Rep func, with extensive tests.

@mtsokol
Copy link
Copy Markdown
Member

mtsokol commented Feb 10, 2026

@ricky122-5 It's only for Galley scheduler, right? Let's mention it in the title.
Will the code be reused for default scheduler as well?

@mtsokol mtsokol added the Galley label Feb 10, 2026
@mtsokol mtsokol linked an issue Feb 12, 2026 that may be closed by this pull request
@ricky122-5
Copy link
Copy Markdown
Collaborator Author

@ricky122-5 It's only for Galley scheduler, right? Let's mention it in the title. Will the code be reused for default scheduler as well?

I designed it just for Galley because of the request to add functional dependencies / database style scheduling in the future. I think it could be reused for the default scheduler but it's a tradeoff for sure between compile time and runtime performance.

@ricky122-5 ricky122-5 changed the title Sparse suitable rep Galley Sparse suitable rep Feb 12, 2026
@mtsokol
Copy link
Copy Markdown
Member

mtsokol commented Feb 12, 2026

@ricky122-5 If a part of it can be reused then we should think of some abstraction, and have suitable rep finder for Galley and default scheduler.

@willow-ahrens
Copy link
Copy Markdown
Member

This PR does do the default scheduler as well.

Copy link
Copy Markdown
Member

@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.

copy-paste this file: https://github.com/finch-tensor/finch-tensor-lite/blob/main/src/finchlite/autoschedule/formatter.py, and modify it to make a "HeuristicFormatter" object that gives the "ftype" constructor function the "suitableRep" object.

Copy link
Copy Markdown
Member

@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.

  1. Move all code except format_selector.py into autoscheduler.py
  2. Add SparseRepeatData
  3. Add SequentialRead, SequentialWrite, RandomRead, RandomWrite capability traits.
  4. Add a formatter pass based on joels new formatter structure (copy paste formatter.py)

Copy link
Copy Markdown
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.

Just some code-style comments to match the rest of codebase.

Comment on lines +115 to +122
if isinstance(tns, ExtrudeData):
return ExtrudeData(child)
if isinstance(tns, SparseData):
return SparseData(child)
if isinstance(tns, RepeatData):
return RepeatData(child)
if isinstance(tns, DenseData):
return DenseData(child)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's use pattern matching everywhere there's an isinstance on a dataclass

Comment on lines +147 to +156
if any(isinstance(arg, HollowData) for arg in args):
return _map_rep_def_hollow(f, args)
if any(isinstance(arg, SparseData) for arg in args):
return _map_rep_def_sparse(f, args)
if any(isinstance(arg, DenseData) for arg in args):
return _map_rep_def_dense(f, args)
if any(isinstance(arg, RepeatData) for arg in args):
return _map_rep_def_repeat(f, args)
if any(isinstance(arg, ExtrudeData) for arg in args):
return _map_rep_def_extrude(f, args)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

def collapse_rep(rep: Representation) -> Representation:
if isinstance(rep, ElementData):
return rep
if isinstance(rep, HollowData):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

"""
Predict the representation of the result of the query expression.
"""
if isinstance(ex, Alias):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

return 1 + self.lvl.ndims()


@dataclass
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can all dataclasses be frozen=True?

Comment thread src/finchlite/autoschedule/formatter.py Outdated
)


class SmartLogicFormatter(LogicFormatter):
Copy link
Copy Markdown

@rithvikr1255 rithvikr1255 Mar 3, 2026

Choose a reason for hiding this comment

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

inherit from new abstract

Comment thread src/finchlite/autoschedule/rw_traits.py Outdated
"""


class RandomRead(SequentialRead):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dont inherit

logger = logging.LoggerAdapter(logging.getLogger(__name__), extra=LOG_LOGIC_POST_OPT)


class LogicFormatter(LogicLoader):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

rename to default

Comment thread src/finchlite/autoschedule/formatter.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bufferizedndarrayformatter


logger = logging.LoggerAdapter(logging.getLogger(__name__), extra=LOG_LOGIC_POST_OPT)


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no-op logic formatter abstract class

return []

formats = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

make new galley logic formatter

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

logic evaluator ^

@@ -0,0 +1,52 @@
from enum import Enum


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove, translate to reps

case _:
raise ValueError(f"Unrecognized expression kind: {type(ex)}")

def _handle_reorder_mapjoin(self, ex: Reorder) -> Representation:
Copy link
Copy Markdown

@rithvikr1255 rithvikr1255 Mar 3, 2026

Choose a reason for hiding this comment

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

look into @willow-ahrens

@willow-ahrens
Copy link
Copy Markdown
Member

LogicFormatter -> DefaultLogicFormatter
DefaultLogicFormatter -> BufferizedNDArrayFormatter
Add an empty class named LogicFormatter that everything inherits from
SmartLogicFormatter inherits from empty class LogicFormatter, defines an abstractmethod for get_output_tns_type(fill_value, shape_type, rep)

merge smartformatter into suitable_rep.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sparse Suitable Rep

4 participants