-
Notifications
You must be signed in to change notification settings - Fork 5
Add configuration resolution and utility functions #86
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
c744d70
b93d136
ad18345
137e2f7
d9f9283
bf2a3a6
5aa7887
dd12490
4ede1d1
886b754
b63dbc5
2844fa6
bb00983
4416f0d
5b210c7
85691a1
12f52f7
ab0da89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import re | ||
|
|
||
|
|
||
| def parse_checkpoint_step(path: str) -> int | None: | ||
| """Extract training step number from checkpoint path. | ||
|
|
||
| Handles multiple formats: | ||
| - step_12345.pt / step-12345.pt | ||
| - 12345/model.pt | ||
| - model_weights/step_00012345.pt | ||
|
|
||
| Args: | ||
| path: File path or S3 key containing checkpoint | ||
|
|
||
| Returns: | ||
| Step number if found, None otherwise | ||
|
|
||
| Examples: | ||
| >>> parse_checkpoint_step("model_weights/step_12345.pt") | ||
| 12345 | ||
| >>> parse_checkpoint_step("checkpoints/12345/model.pt") | ||
| 12345 | ||
| >>> parse_checkpoint_step("step-00500.pt") | ||
| 500 | ||
| """ | ||
| m = re.search(r"step[_-]?(\d+)\.pt$", path) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This naming convention does not seem to be used in our codebase, so I would remove it |
||
| if m: | ||
| return int(m.group(1)) | ||
|
|
||
| parts = path.split("/") | ||
| if parts and parts[-1] == "model.pt" and len(parts) >= 2: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use my suggested |
||
| try: | ||
| return int(parts[-2]) | ||
| except ValueError: | ||
| pass | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def compute_step_width(max_steps: int) -> int: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is just a simple one line function used in exactly one place, you should just inline it |
||
| """Compute zero-padding width for step numbers. | ||
|
|
||
| Ensures lexicographic sorting matches chronological order. | ||
|
|
||
| Args: | ||
| max_steps: Maximum number of training steps | ||
|
|
||
| Returns: | ||
| Number of digits to use for zero-padding | ||
|
|
||
| Examples: | ||
| >>> compute_step_width(999) | ||
| 3 | ||
| >>> compute_step_width(100000) | ||
| 6 | ||
| """ | ||
| return len(str(max_steps)) | ||
|
|
||
|
|
||
| def format_step_number(step: int, max_steps: int) -> str: | ||
|
ealt marked this conversation as resolved.
|
||
| """Format step number with appropriate zero-padding. | ||
|
|
||
| Args: | ||
| step: Current training step | ||
| max_steps: Maximum number of training steps | ||
|
|
||
| Returns: | ||
| Zero-padded step string | ||
|
|
||
| Examples: | ||
| >>> format_step_number(42, max_steps=100000) | ||
| '000042' | ||
| >>> format_step_number(999, max_steps=999) | ||
| '999' | ||
| """ | ||
| width = compute_step_width(max_steps) | ||
| return f"{step:0{width}d}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| def compute_generator_sequence_length(model_n_ctx: int, use_bos: bool) -> int: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||
| """Compute the generator's sequence length from model context length and BOS usage. | ||
|
|
||
| The relationship is: model_n_ctx = generator_seq_len - 1 + BOS | ||
|
|
||
| Solving for generator_seq_len: generator_seq_len = model_n_ctx + 1 - BOS | ||
|
|
||
| Args: | ||
| model_n_ctx: The model's context length (number of input positions it processes) | ||
| use_bos: Whether a beginning-of-sequence token is prepended during data generation | ||
|
|
||
| Returns: | ||
| The sequence length to configure for the data generator | ||
|
|
||
| Examples: | ||
| >>> compute_generator_sequence_length(model_n_ctx=512, use_bos=True) | ||
| 512 | ||
| >>> compute_generator_sequence_length(model_n_ctx=512, use_bos=False) | ||
| 513 | ||
| """ | ||
| return model_n_ctx + 1 - int(use_bos) | ||
|
|
||
|
|
||
| def compute_model_context_length(generator_seq_len: int, use_bos: bool) -> int: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||
| """Compute the model's context length from generator sequence length and BOS usage. | ||
|
|
||
| The relationship is: model_n_ctx = generator_seq_len - 1 + BOS | ||
|
|
||
| Args: | ||
| generator_seq_len: The sequence length configured for the data generator | ||
| use_bos: Whether a beginning-of-sequence token is prepended during data generation | ||
|
|
||
| Returns: | ||
| The context length for the model (number of input positions it will process) | ||
|
|
||
| Examples: | ||
| >>> compute_model_context_length(generator_seq_len=512, use_bos=True) | ||
| 512 | ||
| >>> compute_model_context_length(generator_seq_len=513, use_bos=False) | ||
| 512 | ||
| """ | ||
| return generator_seq_len - 1 + int(use_bos) | ||
|
|
||
|
|
||
| def compute_model_vocab_size(generator_vocab_size: int, use_bos: bool, use_eos: bool) -> int: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we assume |
||
| """Compute the model's vocabulary size from generator vocab and special tokens. | ||
|
|
||
| When BOS or EOS tokens are used during data generation, they are added to the vocabulary, | ||
| increasing the total vocab size the model needs to handle. | ||
|
|
||
| Args: | ||
| generator_vocab_size: The vocabulary size of the data generator | ||
| use_bos: Whether a beginning-of-sequence token is used during data generation | ||
| use_eos: Whether an end-of-sequence token is used during data generation | ||
|
|
||
| Returns: | ||
| The vocabulary size the model should be configured with | ||
|
|
||
| Examples: | ||
| >>> compute_model_vocab_size(generator_vocab_size=100, use_bos=True, use_eos=False) | ||
| 101 | ||
| >>> compute_model_vocab_size(generator_vocab_size=100, use_bos=True, use_eos=True) | ||
| 102 | ||
| >>> compute_model_vocab_size(generator_vocab_size=100, use_bos=False, use_eos=False) | ||
| 100 | ||
| """ | ||
| return generator_vocab_size + int(use_bos) + int(use_eos) | ||
Uh oh!
There was an error while loading. Please reload this page.