This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [build-system] | |
| requires = ["setuptools >= 61.0"] | |
| build-backend = "setuptools.build_meta" | |
| [project] | |
| dynamic = ["version"] | |
| name = "lit_commit_cb" | |
| authors=[ | |
| {name = "Quentin Febvre", email = "quentin.febvre@gmail.com"}, | |
| ] | |
| dependencies=[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tqdm | |
| import torch | |
| import numpy as np | |
| import pandas as pd | |
| def oi( | |
| outgrid_da, | |
| patcher_cls, | |
| obs, | |
| obs_var='ssh', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def log_mem_amp_cp(model, inp, mem_log=None, exp=None, cp_chunks=3): | |
| mem_log = mem_log or [] | |
| exp = exp or f'exp_{len(mem_log)}' | |
| hr = [] | |
| optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9) | |
| amp_model, optimizer = amp.initialize(model, optimizer) | |
| for idx, module in enumerate(amp_model.modules()): | |
| add_memory_hooks(idx, module, mem_log, exp, hr) | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # %% Create Sequential version of model | |
| class Flatten(nn.Module): | |
| def forward(self, x): | |
| return torch.flatten(x, 1) | |
| seq_model = nn.Sequential( | |
| model.conv1, | |
| model.bn1, | |
| model.relu, | |
| model.maxpool, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # %% Analysis baseline | |
| model = resnet18().cuda() | |
| bs = 128 | |
| input = torch.rand(bs, 3, 224, 224).cuda() | |
| mem_log = [] | |
| try: | |
| mem_log.extend(log_mem(model, input, exp='baseline')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def log_mem_amp(model, inp, mem_log=None, exp=None): | |
| mem_log = mem_log or [] | |
| exp = exp or f'exp_{len(mem_log)}' | |
| hr = [] | |
| optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9) | |
| amp_model, optimizer = amp.initialize(model, optimizer) | |
| for idx, module in enumerate(amp_model.modules()): | |
| add_memory_hooks(idx, module, mem_log, exp, hr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def log_mem_cp(model, inp, mem_log=None, exp=None, cp_chunks=3): | |
| mem_log = mem_log or [] | |
| exp = exp or f'exp_{len(mem_log)}' | |
| hr = [] | |
| for idx, module in enumerate(model.modules()): | |
| add_memory_hooks(idx, module, mem_log, exp, hr) | |
| try: | |
| out = checkpoint_sequential(model, cp_chunks, inp) | |
| loss = out.sum() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def _get_gpu_mem(synchronize=True, empty_cache=True): | |
| return torch.cuda.memory_allocated(), torch.cuda.memory_cached() | |
| def _generate_mem_hook(handle_ref, mem, idx, hook_type, exp): | |
| def hook(self, *args): | |
| if len(mem) == 0 or mem[-1]["exp"] != exp: | |
| call_idx = 0 | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from s3_api_raw import S3ApiRaw | |
| from s3_model import S3Model | |
| from schema import Schema | |
| #We define the model | |
| class User(S3Model): | |
| """ | |
| User: | |
| - name: "user" | |
| - schema: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Then, create a folder for you app: | |
| mkdir my-sls-rest && cd my-sls-rest | |
| # create a virtualenv | |
| virtualenv venv — python=python3.6 | |
| source venv/bin/activate | |
| # create a create a serverlessproject | |
| serverless create — template aws-python3 — name my-sls-rest | |
| serverless plugin install -n serverless-python-requirements |
NewerOlder