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

[autoparallel] add rotor C version #1658

Merged
merged 52 commits into from Oct 3, 2022

Conversation

Cypher30
Copy link
Contributor

@Cypher30 Cypher30 commented Sep 27, 2022

What's New?

In this PR I add C extension of rotor dynamic programming table calculation and remove repeated MetaInfoProp in rotor solver, right now you should execute the following code before running solver rotor

if META_COMPATIBILITY:
    data_meta = MetaTensor(data, fake_device=next(gm.parameters()).device)
    MetaInfoProp(gm).run(data_meta)

As we might use rotor for simplified offload strategy, this modification is crucial as we might run solver over the same graph several time for auto capper heuristic, we don't need to run this MetaInfoProp over and over again. Actually with the new C version dynamic programming, the MetaInfoProp itself consumes more time than simply run the dynamic programming.

Cypher30 and others added 30 commits July 14, 2022 16:07
setup.py Outdated
@@ -191,6 +192,12 @@ def cuda_ext_helper(name, sources, extra_cuda_flags, extra_cxx_flags=[]):
extra_cxx_flags = ['-std=c++14', '-lcudart', '-lcublas', '-g', '-Wno-reorder', '-fopenmp', '-march=native']
ext_modules.append(cuda_ext_helper('cpu_adam', ['cpu_adam.cpp'], extra_cuda_flags, extra_cxx_flags))

if build_auto_ckpt_ext:
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no way to specify this parameter by the user.

setup.py Outdated
@@ -191,6 +192,12 @@ def cuda_ext_helper(name, sources, extra_cuda_flags, extra_cxx_flags=[]):
extra_cxx_flags = ['-std=c++14', '-lcudart', '-lcublas', '-g', '-Wno-reorder', '-fopenmp', '-march=native']
ext_modules.append(cuda_ext_helper('cpu_adam', ['cpu_adam.cpp'], extra_cuda_flags, extra_cxx_flags))

if build_auto_ckpt_ext:
print(os.path.join(this_dir, "colossalai/fx/passes/algorithms/dynamic_programs.c"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this print statement.

setup.py Outdated
if build_auto_ckpt_ext:
print(os.path.join(this_dir, "colossalai/fx/passes/algorithms/dynamic_programs.c"))
ext_modules.append(
Extension("c_version_dp",
Copy link
Contributor

Choose a reason for hiding this comment

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

do not name this variable way, it is quite meaningless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've fixed those problems, currently we will build the C extension the first time user run the rotor solver, only if C extension building fail will we use the python version of dynamic programming.

@Cypher30
Copy link
Contributor Author

I will build a unit test to compare the solution of python and C version dynamic programs.

@FrankLeeeee
Copy link
Contributor

I will convert this PR to draft until it is ready for review again.

@FrankLeeeee FrankLeeeee marked this pull request as draft September 28, 2022 03:09
@Cypher30 Cypher30 marked this pull request as ready for review September 28, 2022 07:42
@Cypher30
Copy link
Contributor Author

Screen Shot 2022-09-29 at 10 21 58

As the unit test of C version solver consistency is skipped in torch11, the above is the result on torch12.

Comment on lines 9 to 27
try:
from .dynamic_programs_C_version import persistent_compute_table
CVERSION = True
except ModuleNotFoundError:
import subprocess
import os
print("dynamic_programs_C_version hasn't been built! Building library...")
this_dir = os.path.dirname(os.path.abspath(__file__))
result = subprocess.Popen(f'python {os.path.join(this_dir, "build_c_ext.py")} build_ext --build-lib={this_dir}',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
if result.wait() == 0:
print("dynamic_programs_C_version has been built!")
from .dynamic_programs_C_version import persistent_compute_table
CVERSION = True
else:
print("dynamic_programs_C_version built failed! Using python version!")
CVERSION = False
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be put inside the solver_rotor function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

except ModuleNotFoundError:
import subprocess
import os
print("dynamic_programs_C_version hasn't been built! Building library...")
Copy link
Contributor

Choose a reason for hiding this comment

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

can replace print with colossalai logger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

@Cypher30 Cypher30 merged commit 1df98d5 into hpcaitech:main Oct 3, 2022
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.

None yet

3 participants