teeny_quant/cli/mod.rs
1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! The `teeny-quant` binary's command-line interface.
18
19pub mod inspect;
20pub mod quantize;
21pub mod validate;
22
23use clap::{Parser, Subcommand};
24
25/// Quantize `.safetensors` model checkpoints for deployment.
26#[derive(Parser, Debug)]
27#[command(
28 name = "teeny-quant",
29 about = "Quantize .safetensors model checkpoints for deployment."
30)]
31pub struct Cli {
32 /// The subcommand to run.
33 #[command(subcommand)]
34 pub command: Command,
35}
36
37/// `teeny-quant` subcommands.
38#[derive(Subcommand, Debug)]
39pub enum Command {
40 /// Quantize a checkpoint.
41 Quantize(quantize::QuantizeArgs),
42 /// List a checkpoint's tensors (and, if present, its `quantization_config`).
43 Inspect(inspect::InspectArgs),
44 /// Compare a quantized checkpoint against its original for per-tensor error.
45 Validate(validate::ValidateArgs),
46}
47
48impl Cli {
49 /// Runs the selected subcommand.
50 pub fn run(self) -> anyhow::Result<()> {
51 match self.command {
52 Command::Quantize(args) => quantize::run(args),
53 Command::Inspect(args) => inspect::run(args),
54 Command::Validate(args) => validate::run(args),
55 }
56 }
57}