|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +set -euo pipefail |
| 9 | + |
| 10 | +status=0 |
| 11 | + |
| 12 | +green='\e[1;32m'; red='\e[1;31m'; cyan='\e[1;36m'; reset='\e[0m' |
| 13 | + |
| 14 | +# Following is the rules for the file size linting: |
| 15 | +# 1. For all files, the file size can't be larger than 1MB |
| 16 | +# 2. For images/videos, the file size can't be larger than 8MB |
| 17 | +# 3. There is an exception list defined in the script if it's really needed |
| 18 | + |
| 19 | +# List of files to skip (relative paths) |
| 20 | +EXCEPTIONS=( |
| 21 | + "examples/models/llama/params/demo_rand_params.pth" |
| 22 | + "examples/models/llama/tokenizer/test/resources/test_tiktoken_tokenizer.model" |
| 23 | + "examples/qualcomm/oss_scripts/llama/artifacts/stories260k_hybrid_llama_qnn.pte" |
| 24 | + # Following needs to be clean up |
| 25 | + "examples/mediatek/models/llm_models/weights/Llama-3.2-1B-Instruct/tokenizer.json" |
| 26 | + "examples/mediatek/models/llm_models/weights/Llama-3.2-3B-Instruct/tokenizer.json" |
| 27 | + "examples/mediatek/models/llm_models/weights/llama3-8B-instruct/tokenizer.json" |
| 28 | +) |
| 29 | + |
| 30 | +is_exception() { |
| 31 | + local f=$1 |
| 32 | + for ex in "${EXCEPTIONS[@]}"; do |
| 33 | + if [[ "$f" == "$ex" ]]; then |
| 34 | + return 0 |
| 35 | + fi |
| 36 | + done |
| 37 | + return 1 |
| 38 | +} |
| 39 | + |
| 40 | +if [ $# -eq 2 ]; then |
| 41 | + base=$1 |
| 42 | + head=$2 |
| 43 | + echo "Checking changed files between $base...$head" |
| 44 | + files=$(git diff --name-only "$base...$head") |
| 45 | +else |
| 46 | + echo "Checking all files in repository" |
| 47 | + files=$(git ls-files) |
| 48 | +fi |
| 49 | + |
| 50 | +for file in $files; do |
| 51 | + if is_exception "$file"; then |
| 52 | + echo -e "${cyan}SKIP${reset} $file (in exception list)" |
| 53 | + continue |
| 54 | + fi |
| 55 | + if [ -f "$file" ]; then |
| 56 | + # Set size limit depending on extension |
| 57 | + if [[ "$file" =~ \.(png|jpg|jpeg|gif|svg|mp3|mp4)$ ]]; then |
| 58 | + MAX_SIZE=$((8 * 1024 * 1024)) # 8 MB for pictures |
| 59 | + else |
| 60 | + MAX_SIZE=$((1 * 1024 * 1024)) # 1 MB for others |
| 61 | + fi |
| 62 | + |
| 63 | + size=$(wc -c <"$file") |
| 64 | + if [ "$size" -gt "$MAX_SIZE" ]; then |
| 65 | + echo -e "${red}FAIL${reset} $file (${cyan}${size} bytes${reset}) exceeds ${MAX_SIZE} bytes" |
| 66 | + status=1 |
| 67 | + else |
| 68 | + echo -e "${green}OK${reset} $file (${size} bytes)" |
| 69 | + fi |
| 70 | + fi |
| 71 | +done |
| 72 | + |
| 73 | +exit $status |
0 commit comments