code: def get_act_scales(
      model, tokenizer, dataset, num_samples=512, seq_len=512
  ):
      model.eval()
      device = next(model.parameters()).device
      act_scales = {}
  
      def stat_tensor(name, tensor):
          hidden_dim = tensor.shape[-1]
          tensor = tensor.view(-1, hidden_dim).abs().detach()
          comming_max = torch.max(tensor, dim=0)[0].float().cpu()
          if name in act_scales:
              act_scales[name] = torch.max(
                  act_scales[name], comming_max
              )
          else:
              act_scales[name] = comming_max
  
      def stat_input_hook(m, x, y, name):
          if isinstance(x, tuple):
              x = x[0]
          stat_tensor(name, x)
  
      hooks = []
      for name, m in model.named_modules():
          if isinstance(m, nn.Linear):
              hooks.append(
                  m.register_forward_hook(
                      functools.partial(stat_input_hook, name=name)
                  )
              )
  
      for i in tqdm(range(num_samples)):
          input_ids = tokenizer(
              dataset[i]["text"],
              return_tensors="pt",
              max_length=seq_len,
              truncation=True,
          ).input_ids.to(device)
          model(input_ids)
  
      for h in hooks:
          h.remove()
  
      return act_scales
  
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 1 for calling a global function with example usage: get_act_scales(model, tokenizer, dataset, num_samples, seq_len) and returns: act_scales