code: def smooth_ln_fcs(ln, fcs, act_scales, alpha=0.5):
      if not isinstance(fcs, list):
          fcs = [fcs]
      assert isinstance(
          ln, (nn.LayerNorm, LlamaRMSNorm, MistralRMSNorm)
      )
      for fc in fcs:
          assert isinstance(fc, nn.Linear)
          assert (
              ln.weight.numel() == fc.in_features == act_scales.numel()
          )
  
      device, dtype = fcs[0].weight.device, fcs[0].weight.dtype
      act_scales = act_scales.to(device=device, dtype=dtype)
      weight_scales = torch.cat(
          [fc.weight.abs().max(dim=0, keepdim=True)[0] for fc in fcs],
          dim=0,
      )
      weight_scales = weight_scales.max(dim=0)[0].clamp(min=1e-5)
  
      scales = (
          (act_scales.pow(alpha) / weight_scales.pow(1 - alpha))
          .clamp(min=1e-5)
          .to(device)
          .to(dtype)
      )
  
      ln.weight.div_(scales)
      if getattr(ln, "bias", None) is not None:
          ln.bias.div_(scales)
  
      for fc in fcs:
          fc.weight.mul_(scales.view(1, -1))
  
file_path: quanto/external/smoothquant/smoothquant.py
imports: import argparse
  import functools
  import os
  import torch
  import torch.nn
  from datasets import load_dataset
  from tqdm import tqdm
  from transformers import AutoModelForCausalLM, AutoTokenizer
  from transformers.models.bloom.modeling_bloom import BloomBlock
  from transformers.models.opt.modeling_opt import OPTDecoderLayer
  from transformers.models.llama.modeling_llama import LlamaDecoderLayer, LlamaRMSNorm
  from transformers.models.mistral.modeling_mistral import MistralDecoderLayer, MistralRMSNorm
label_desc: Use image node_id 2 for calling a global function with example usage: smooth_ln_fcs(ln, fcs, act_scales, alpha) without return types