• bitcoinBitcoin(BTC)$78,094.00-1.98%
  • ethereumEthereum(ETH)$2,471.34-1.91%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$718.88-4.81%
  • rippleXRP(XRP)$1.38-4.15%
  • usd-coinUSDC(USDC)$1.00-0.02%
  • solanaSolana(SOL)$101.19-3.49%
  • tronTRON(TRX)$0.3396680.08%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.030.00%
  • zcashZcash(ZEC)$1,220.48-1.79%
  • HyperliquidHyperliquid(HYPE)$83.24-3.70%
  • dogecoinDogecoin(DOGE)$0.085328-6.41%
  • RainRain(RAIN)$0.0163101.20%
  • USDSUSDS(USDS)$1.000.00%
  • moneroMonero(XMR)$514.002.33%
  • whitebitWhiteBIT Coin(WBT)$80.66-2.18%
  • chainlinkChainlink(LINK)$11.75-5.89%
  • leo-tokenLEO Token(LEO)$9.190.08%
  • cardanoCardano(ADA)$0.213313-4.09%
  • stellarStellar(XLM)$0.179290-5.82%
  • bitcoin-cashBitcoin Cash(BCH)$247.63-4.85%
  • daiDai(DAI)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.00-0.03%
  • USD1USD1(USD1)$1.00-0.02%
  • CantonCanton(CC)$0.104268-3.75%
  • litecoinLitecoin(LTC)$52.47-3.88%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.37-2.77%
  • uniswapUniswap(UNI)$5.99-12.52%
  • avalanche-2Avalanche(AVAX)$7.76-3.43%
  • hedera-hashgraphHedera(HBAR)$0.076319-4.43%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • nearNEAR Protocol(NEAR)$2.43-1.55%
  • suiSui(SUI)$0.76-7.46%
  • shiba-inuShiba Inu(SHIB)$0.000005-5.64%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.01%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.056929-6.12%
  • MemeCoreMemeCore(M)$1.200.19%
  • tether-goldTether Gold(XAUT)$4,395.57-0.06%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • BittensorBittensor(TAO)$252.61-3.93%
  • Ripple USDRipple USD(RLUSD)$1.00-0.02%
  • okbOKB(OKB)$112.43-2.19%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.11%
  • mantleMantle(MNT)$0.59-8.74%
  • AsterAster(ASTER)$0.71-6.35%
  • aaveAave(AAVE)$124.43-4.85%
  • pax-goldPAX Gold(PAXG)$4,399.32-0.08%
  • polkadotPolkadot(DOT)$1.11-6.08%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.055942-0.14%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

A Coding Implementation to Compress and Benchmark Instruction-Tuned LLMs with FP8, GPTQ, and SmoothQuant Quantization using llmcompressor

May 17, 2026
in AI & Technology
Reading Time: 2 mins read
A A
A Coding Implementation to Compress and Benchmark Instruction-Tuned LLMs with FP8, GPTQ, and SmoothQuant Quantization using llmcompressor
ShareShareShareShareShare

YOU MAY ALSO LIKE

DeepSeek AI Released DeepSeek-V4.1-Flash with 1M Context, FP4 KV Cache, and Cross-Layer Attention Reuse

2028 Volvo XC40 First Look: Hello new tech, goodbye EV

import subprocess, sys
def pip(*pkgs):
   subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", *pkgs])
pip("llmcompressor", "compressed-tensors",
   "transformers>=4.45", "accelerate", "datasets")
import os, gc, time, json, math
from pathlib import Path
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import load_dataset
assert torch.cuda.is_available(), \
   "Enable a GPU: Runtime > Change runtime type > T4 GPU"
print("GPU:", torch.cuda.get_device_name(0),
     "| CUDA:", torch.version.cuda,
     "| torch:", torch.__version__)
MODEL_ID = "Qwen/Qwen2.5-0.5B-Instruct"
WORKDIR = Path("/content/quant_lab"); WORKDIR.mkdir(exist_ok=True)
os.chdir(WORKDIR)
def free_mem():
   gc.collect(); torch.cuda.empty_cache()
def dir_size_gb(path):
   total = 0
   for root, _, files in os.walk(path):
       for f in files:
           total += os.path.getsize(os.path.join(root, f))
   return total / 1e9
def time_generation(model, tok, prompt, max_new_tokens=64):
   """Greedy decode; reports latency & tokens/sec after a brief warmup."""
   inputs = tok(prompt, return_tensors="pt").to(model.device)
   _ = model.generate(**inputs, max_new_tokens=4, do_sample=False)
   torch.cuda.synchronize()
   t0 = time.time()
   out = model.generate(**inputs, max_new_tokens=max_new_tokens,
                        do_sample=False, pad_token_id=tok.eos_token_id)
   torch.cuda.synchronize()
   dt = time.time() - t0
   new_ids = out[0][inputs["input_ids"].shape[1]:]
   return tok.decode(new_ids, skip_special_tokens=True), dt, max_new_tokens/dt
@torch.no_grad()
def wikitext_ppl(model, tok, seq_len=512, max_chunks=20, stride=512):
   """Light WikiText-2 perplexity probe (fast, indicative)."""
   ds = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")
   text = "\n\n".join(t for t in ds["text"][:400] if t.strip())
   enc = tok(text, return_tensors="pt").input_ids.to(model.device)
   nll_sum, tok_count = 0.0, 0
   for begin in range(0, enc.size(1) - seq_len, stride):
       chunk = enc[:, begin:begin+seq_len]
       out = model(chunk, labels=chunk)
       nll_sum += out.loss.float().item() * seq_len
       tok_count += seq_len
       if tok_count // seq_len >= max_chunks: break
   return math.exp(nll_sum / tok_count)
results = {}
PROMPT = ("<|im_start|>user\nIn two sentences, explain why post-training "
         "quantization works for large language models.<|im_end|>\n"
         "<|im_start|>assistant\n")
def benchmark(label, model_path_or_id):
   free_mem()
   print(f"\n──── benchmarking: {label} ────")
   tok = AutoTokenizer.from_pretrained(model_path_or_id)
   m = AutoModelForCausalLM.from_pretrained(
           model_path_or_id, torch_dtype="auto", device_map="cuda").eval()
   sample, dt, tps = time_generation(m, tok, PROMPT)
   ppl = wikitext_ppl(m, tok)
   size = dir_size_gb(model_path_or_id) if os.path.isdir(str(model_path_or_id)) else None
   results[label] = {"size_gb": size, "ppl": round(ppl, 3),
                     "latency_s": round(dt, 3), "tok_per_s": round(tps, 1),
                     "sample": sample.strip().replace("\n", " ")[:180]}
   print(json.dumps(results[label], indent=2))
   del m; free_mem()

Credit: Source link

ShareTweetSendSharePin

Related Posts

DeepSeek AI Released DeepSeek-V4.1-Flash with 1M Context, FP4 KV Cache, and Cross-Layer Attention Reuse
AI & Technology

DeepSeek AI Released DeepSeek-V4.1-Flash with 1M Context, FP4 KV Cache, and Cross-Layer Attention Reuse

September 10, 2026
2028 Volvo XC40 First Look: Hello new tech, goodbye EV
AI & Technology

2028 Volvo XC40 First Look: Hello new tech, goodbye EV

September 10, 2026
Anthropic Discloses Fourth Cyber Incident in Alignment Assessment – Unite.AI
AI & Technology

Anthropic Discloses Fourth Cyber Incident in Alignment Assessment – Unite.AI

September 10, 2026
LandingAI Releases Agentic Document Extraction Gen2 with DPT-3 Pro and DPT-3 Verity
AI & Technology

LandingAI Releases Agentic Document Extraction Gen2 with DPT-3 Pro and DPT-3 Verity

September 10, 2026
Next Post
Meta to lay off 10% of company as Microsoft offers buyouts

Meta to lay off 10% of company as Microsoft offers buyouts

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Heroic scenes on highway after car drives off overpass

Heroic scenes on highway after car drives off overpass

September 5, 2026
When Are Portable Apple CarPlay Screens Actually Worth It?

When Are Portable Apple CarPlay Screens Actually Worth It?

September 7, 2026
AI is writing, acting and producing China’s minidramas. It’s shaking up a  billion industry.

AI is writing, acting and producing China’s minidramas. It’s shaking up a $14 billion industry.

September 7, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!