(
checkpoint_dir: Path, model_filename: str = 'lit_model.pth'
)
| 65 | |
| 66 | |
| 67 | def check_valid_checkpoint_dir( |
| 68 | checkpoint_dir: Path, model_filename: str = 'lit_model.pth' |
| 69 | ) -> None: |
| 70 | files = { |
| 71 | model_filename: (checkpoint_dir / model_filename).is_file(), |
| 72 | 'model_config.yaml': (checkpoint_dir / 'model_config.yaml').is_file(), |
| 73 | 'tokenizer.json OR tokenizer.model': ( |
| 74 | checkpoint_dir / 'tokenizer.json' |
| 75 | ).is_file() |
| 76 | or (checkpoint_dir / 'tokenizer.model').is_file(), |
| 77 | 'tokenizer_config.json': (checkpoint_dir / 'tokenizer_config.json').is_file(), |
| 78 | } |
| 79 | if checkpoint_dir.is_dir(): |
| 80 | if all(files.values()): |
| 81 | # we're good |
| 82 | return |
| 83 | problem = f' is missing the files: {[f for f, exists in files.items() if not exists]!r}' |
| 84 | else: |
| 85 | problem = ' is not a checkpoint directory' |
| 86 | |
| 87 | # list locally available checkpoints |
| 88 | available = list(Path('checkpoints').glob('*/*')) |
| 89 | if available: |
| 90 | options = '\n --checkpoint_dir '.join( |
| 91 | [''] + [repr(str(p.resolve())) for p in available] |
| 92 | ) |
| 93 | extra = f'\nYou have downloaded locally:{options}\n' |
| 94 | else: |
| 95 | extra = '' |
| 96 | |
| 97 | error_message = ( |
| 98 | f'--checkpoint_dir {str(checkpoint_dir.absolute())!r}{problem}.' |
| 99 | '\nFind download instructions at https://github.com/Lightning-AI/litgpt/blob/main/tutorials\n' |
| 100 | f'{extra}\nSee all download options by running:\n litgpt download' |
| 101 | ) |
| 102 | print(error_message, file=sys.stderr) |
| 103 | raise SystemExit(1) |
| 104 | |
| 105 | |
| 106 | class SavingProxyForStorage: |
nothing calls this directly
no outgoing calls
no test coverage detected