grade-client 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- grade/__init__.py +3 -0
- grade/__main__.py +5 -0
- grade/cli.py +91 -0
- grade/cloud.py +600 -0
- grade/ifm.py +182 -0
- grade/inference.py +441 -0
- grade/inputs.py +60 -0
- grade/model_registry.py +54 -0
- grade/modeling.py +88 -0
- grade/pam.py +118 -0
- grade/resume.py +197 -0
- grade/runner.py +72 -0
- grade/targets/__init__.py +0 -0
- grade/targets/targets_gpcr_v2.fa +658 -0
- grade/tcm.py +109 -0
- grade/writers.py +120 -0
- grade_client-1.2.0.dist-info/METADATA +291 -0
- grade_client-1.2.0.dist-info/RECORD +22 -0
- grade_client-1.2.0.dist-info/WHEEL +5 -0
- grade_client-1.2.0.dist-info/entry_points.txt +3 -0
- grade_client-1.2.0.dist-info/licenses/LICENSE +21 -0
- grade_client-1.2.0.dist-info/top_level.txt +1 -0
grade/__init__.py
ADDED
grade/__main__.py
ADDED
grade/cli.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Unified Cloud/local command-line parsing without inference dependencies."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
|
|
7
|
+
from . import __version__
|
|
8
|
+
from .model_registry import DEFAULT_MODEL_ID, available_models, get_model_spec
|
|
9
|
+
from .writers import infer_format_from_path, supported_formats
|
|
10
|
+
|
|
11
|
+
# Retained for Python callers; not used as an implicit local model selection.
|
|
12
|
+
DEFAULT_MODEL_DIR = get_model_spec(DEFAULT_MODEL_ID).local_dir
|
|
13
|
+
LOCAL_DEFAULTS = {
|
|
14
|
+
"batch_size": 8, "num_workers": 0, "max_length": 1024,
|
|
15
|
+
"fp16": False, "bf16": False, "attn_implementation": "sdpa",
|
|
16
|
+
"checkpoint_interval": 100, "no_resume": False, "no_target_cache": False,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
|
|
21
|
+
parser = argparse.ArgumentParser(
|
|
22
|
+
description="GRADE: use Cloud by default, or --model-dir for local GPCR-peptide inference.",
|
|
23
|
+
allow_abbrev=False,
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument("--version", action="version", version=f"grade-client {__version__}")
|
|
26
|
+
parser.add_argument("--target-name", help="Full target header in --target-fasta or the bundled GPCR FASTA.")
|
|
27
|
+
parser.add_argument("--target-seq", help="Raw target amino acid sequence.")
|
|
28
|
+
parser.add_argument("--target-fasta", help="FASTA file containing target sequence(s).")
|
|
29
|
+
parser.add_argument("--peptides", help="Candidate file (.fasta/.faa/.fa, .csv, .txt).")
|
|
30
|
+
parser.add_argument("--output", "--output-csv", "-o", dest="output_csv", help="Output file (CSV, TSV or JSON); --output-csv is a compatibility alias.")
|
|
31
|
+
parser.add_argument("--output-format", choices=supported_formats(), help="Output format; otherwise inferred from the output extension.")
|
|
32
|
+
parser.add_argument("--top-k", type=int, help="Keep the highest K results; Cloud quota counts all submitted peptides.")
|
|
33
|
+
parser.add_argument("--source-label", help="Optional src label; default: grade-api on Cloud, candidate file stem locally.")
|
|
34
|
+
parser.add_argument("--email", help="Cloud email; otherwise GRADE_EMAIL, saved email, or terminal input.")
|
|
35
|
+
parser.add_argument("--usage", action="store_true", help="Query Cloud quota without prediction inputs.")
|
|
36
|
+
selection = parser.add_mutually_exclusive_group()
|
|
37
|
+
selection.add_argument("--model", choices=available_models(), help=f"Cloud model (default: {DEFAULT_MODEL_ID}).")
|
|
38
|
+
selection.add_argument("--model-dir", help="Use local weights/tokenizer from this directory instead of Cloud.")
|
|
39
|
+
|
|
40
|
+
local = parser.add_argument_group("local inference only (requires --model-dir)")
|
|
41
|
+
local.add_argument("--batch-size", type=int, default=argparse.SUPPRESS, help="Per-process batch size (default: 8).")
|
|
42
|
+
local.add_argument("--num-workers", type=int, default=argparse.SUPPRESS, help="DataLoader workers per process (default: 0).")
|
|
43
|
+
local.add_argument("--max-length", type=int, default=argparse.SUPPRESS, help="Tokenizer length (default: 1024).")
|
|
44
|
+
local.add_argument("--fp16", action="store_true", default=argparse.SUPPRESS, help="Float16 autocast on CUDA.")
|
|
45
|
+
local.add_argument("--bf16", action="store_true", default=argparse.SUPPRESS, help="Bfloat16 autocast on CUDA.")
|
|
46
|
+
local.add_argument("--attn-implementation", choices=["eager", "sdpa", "flash_attention_2"], default=argparse.SUPPRESS, help="Encoder attention (default: sdpa).")
|
|
47
|
+
local.add_argument("--checkpoint-interval", type=int, default=argparse.SUPPRESS, help="Save progress every N batches (default: 100).")
|
|
48
|
+
local.add_argument("--no-resume", action="store_true", default=argparse.SUPPRESS, help="Start fresh, replacing progress and output.")
|
|
49
|
+
local.add_argument("--no-target-cache", action="store_true", default=argparse.SUPPRESS, help="Disable target encoding reuse.")
|
|
50
|
+
args = parser.parse_args(argv)
|
|
51
|
+
|
|
52
|
+
if args.model_dir is not None and not args.model_dir.strip():
|
|
53
|
+
parser.error("--model-dir must be a non-empty path")
|
|
54
|
+
args.mode = "local" if args.model_dir is not None else "cloud"
|
|
55
|
+
explicit_local = [name for name in LOCAL_DEFAULTS if hasattr(args, name)]
|
|
56
|
+
if args.mode == "cloud" and explicit_local:
|
|
57
|
+
options = ", ".join("--" + name.replace("_", "-") for name in explicit_local)
|
|
58
|
+
parser.error(f"{options} require --model-dir; Cloud computation settings are fixed")
|
|
59
|
+
if args.mode == "cloud" and int(os.environ.get("WORLD_SIZE", "1")) > 1:
|
|
60
|
+
parser.error("Distributed execution requires --model-dir; refusing duplicate Cloud submissions")
|
|
61
|
+
if args.mode == "local" and (args.email is not None or args.usage):
|
|
62
|
+
parser.error("--email and --usage are Cloud-only options")
|
|
63
|
+
for name, default in LOCAL_DEFAULTS.items():
|
|
64
|
+
if not hasattr(args, name):
|
|
65
|
+
setattr(args, name, default)
|
|
66
|
+
if args.mode == "cloud":
|
|
67
|
+
args.model = args.model or DEFAULT_MODEL_ID
|
|
68
|
+
|
|
69
|
+
if args.usage:
|
|
70
|
+
if any(value is not None for value in (
|
|
71
|
+
args.target_name, args.target_seq, args.target_fasta, args.peptides,
|
|
72
|
+
args.output_csv, args.output_format, args.top_k, args.source_label,
|
|
73
|
+
)):
|
|
74
|
+
parser.error("--usage cannot be combined with prediction or output arguments")
|
|
75
|
+
return args
|
|
76
|
+
|
|
77
|
+
if not args.peptides or not args.output_csv:
|
|
78
|
+
parser.error("--peptides and --output are required for prediction")
|
|
79
|
+
if args.checkpoint_interval <= 0:
|
|
80
|
+
parser.error("--checkpoint-interval must be a positive integer")
|
|
81
|
+
if args.top_k is not None and args.top_k <= 0:
|
|
82
|
+
parser.error("--top-k must be a positive integer")
|
|
83
|
+
if args.fp16 and args.bf16:
|
|
84
|
+
parser.error("--fp16 and --bf16 cannot be enabled at the same time")
|
|
85
|
+
if not any((args.target_name, args.target_seq, args.target_fasta)):
|
|
86
|
+
parser.error("one of --target-name, --target-seq, or --target-fasta is required")
|
|
87
|
+
if args.target_seq and (args.target_name or args.target_fasta):
|
|
88
|
+
parser.error("--target-seq cannot be used together with --target-name or --target-fasta")
|
|
89
|
+
if args.output_format is None:
|
|
90
|
+
args.output_format = infer_format_from_path(args.output_csv)
|
|
91
|
+
return args
|