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

[Runtime] solve the problem that llama frequently calls autotuner #332

Merged
merged 14 commits into from
Dec 19, 2024

Conversation

StrongSpoon
Copy link
Collaborator

PR Category

Runtime

Type of Change

New Feature

Description

implement LibTuner to take place of Autotuner.
it stores tuned configs in database and preloads them before calling.

Issue

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is responded to an issue.
  • Change is fully covered by a UT.

Performance

@StrongSpoon StrongSpoon changed the title Dev lzx [Runtime] solve the problem that llama frequently calls autotuner Nov 27, 2024
Comment on lines 57 to 96
connect = sqlite3.connect(self.cache_dir)
c = connect.cursor()
c.execute(f"CREATE TABLE IF NOT EXISTS {self.__name__} (key TEXT, config TEXT)")
cursor = c.execute(f"SELECT key, config from {self.__name__}")

for row in cursor:
key_str, config_str = row
key = (self.getvalue(k) for k in key_str[1:-1].split(", "))

cfg_ls = [item.split(": ") for item in config_str.split(", ")]
config = triton.Config({})
for k, v in cfg_ls[:-4]:
config.kwargs[k] = eval(v)
config.num_warps = int(cfg_ls[-4][1])
config.num_ctas = int(cfg_ls[-3][1])
config.num_stages = int(cfg_ls[-2][1])
config.enable_fp_fusion = eval(cfg_ls[-1][1])

self.cache[key] = config

connect.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we could leave the connection open and shared because we need to fetch stored params for all gems ops. A try catch block is possibly necessary for external IO operations.

Copy link
Contributor

Choose a reason for hiding this comment

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

But I think its fine at this stage. Let's improve it later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is not always a explicit exit of flag_gems. I'm not sure what time to close the connection if keep it open.



def config_cache_dir() -> Path:
_config_cache_dir = cache_dir() / "config_cache"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion for name: "tunning_cache"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what's the difference?

StrongSpoon and others added 11 commits December 16, 2024 09:32
* new feature, muti_backend

* update auto_tune_module

* update auto_tune_module

* update auto_tune_module

* update __init__

* rebase

* fix bug

* modifiy auto_tune_config

* fix bug

* fix bug

* update

* update

* update scatter&gather

* fix auto_tune

* add gen_torch_device_fn

* fix codestyle

* fix codestyle

* Modify code based on comments

* Modify gen_impl with loops instead of recursion

* Update code structure

* Polish code

* update

* Polish code

* Modify code based on comments

* modify based on comment

* Modify code based on comments

* update

* final fix
@StrongSpoon StrongSpoon marked this pull request as ready for review December 18, 2024 10:02
@StrongSpoon StrongSpoon merged commit e9c7aa7 into master Dec 19, 2024
@StrongSpoon StrongSpoon deleted the dev_lzx branch December 19, 2024 02:52
Gxiandy pushed a commit to Gxiandy/FlagGems that referenced this pull request Jan 12, 2025
…agOpen#332)

* [operator] turn autotuner to heuristics

* [operator] heuristics for gather & index_select

* [runtime] libtuner for matmul

* [runtime] store config data in one db

* [bugfix] parse key as list instead of tuple

* [no ci] update var name

* [Muti_backend] muti_backend-part_1-framework-and-tune_config (FlagOpen#294)

* new feature, muti_backend

* update auto_tune_module

* update auto_tune_module

* update auto_tune_module

* update __init__

* rebase

* fix bug

* modifiy auto_tune_config

* fix bug

* fix bug

* update

* update

* update scatter&gather

* fix auto_tune

* add gen_torch_device_fn

* fix codestyle

* fix codestyle

* Modify code based on comments

* Modify gen_impl with loops instead of recursion

* Update code structure

* Polish code

* update

* Polish code

* Modify code based on comments

* modify based on comment

* Modify code based on comments

* update

* final fix

* [bugfix] update libtuner to be compatible with triton2

* [no ci]reformat

* [operator] update log_softmax

* [pretune] move pretune to ./examples for models

* [format] delete useless print

* [format] delete unused import

* [format] [no ci] remove useless print

---------

Co-authored-by: Galaxy1458 <[email protected]>
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.

5 participants