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

Is there a way to export a pipeline stage? #1016

Open
nrs-status opened this issue Mar 29, 2024 · 2 comments
Open

Is there a way to export a pipeline stage? #1016

nrs-status opened this issue Mar 29, 2024 · 2 comments

Comments

@nrs-status
Copy link

nrs-status commented Mar 29, 2024

I'd like to load a pipeline stage into a VM with low disk storage. Is there a way to export a pipeline stage and have it run independently from the file responsible for wrapping the model into Pipe?

@kwen2501
Copy link
Contributor

kwen2501 commented Apr 2, 2024

Hi, in the topmost of main, we added a new API:

pipe = pippy.pipeline(model, ...)
stage_module = pipe.get_stage_module(stage_idx)

I think you can export stage_module in a couple ways:

Method 1. torch.export

exported_program = torch.export.export(stage_module, ...)

(nit: you may need an example input for stage_module for the ... part for export to work)

I think torch.export also has save and load methods, e.g.:

torch.export.save(exported_program, PATH)

Method 2. torch.save

torch.save(stage_module.state_dict(), PATH)

On the new VM with limited memory, use meta device to create the stage_module:

with torch.device("meta"):
    model = ModelConstructor(...)

pipe = pippy.pipeline(model, ...)

# stage_module will be on meta device as well
stage_module = pipe.get_stage_module(stage_idx)

# Load real weights into it
stage_module.load_state_dict(torch.load(PATH))

@nrs-status
Copy link
Author

Thanks a lot! Thanks for the extensive comments and instructions, highly appreciated. Will be using this to do some tests on a distributed setup.

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