Skip to content

feat: Add type hints and validation to core utility modules #103

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion gpt_oss/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
# torchrun --nproc-per-node=4 -m gpt_oss.generate -p "why did the chicken cross the road?" model/

import argparse
import os
from pathlib import Path

from gpt_oss.tokenizer import get_tokenizer


def main(args):
def main(args: argparse.Namespace) -> None:
# Validate checkpoint path exists
checkpoint_path = Path(args.checkpoint)
if not checkpoint_path.exists():
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the case of vllm this doesn't have to be a path though. Could you modify the check for this?

Copy link
Author

Choose a reason for hiding this comment

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

@dkundel-openai thanks! vLLM now checks local files only when required...

raise FileNotFoundError(f"Checkpoint path does not exist: {args.checkpoint}")

match args.backend:
case "torch":
from gpt_oss.torch.utils import init_distributed
Expand Down
3 changes: 2 additions & 1 deletion gpt_oss/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tiktoken

def get_tokenizer():

def get_tokenizer() -> tiktoken.Encoding:
o200k_base = tiktoken.get_encoding("o200k_base")
tokenizer = tiktoken.Encoding(
name="o200k_harmony",
Expand Down
2 changes: 1 addition & 1 deletion gpt_oss/torch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch.distributed as dist


def suppress_output(rank):
def suppress_output(rank: int) -> None:
"""Suppress printing on the current device. Force printing with `force=True`."""
import builtins as __builtin__
builtin_print = __builtin__.print
Expand Down