{"slug": "how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python", "title": "How to Fine-Tune a Small Language Model Without Writing a Single Line of Python Code on Modal Cloud", "summary": "A tutorial published on Modal Cloud's platform shows how to fine-tune the 135M-parameter HuggingFaceTB/SmolLM2-135M-Instruct model on the b-mc2/sql-create-context dataset using a single YAML configuration file and no Python code. The job runs on a T4 GPU via the TRLoom library, uses SFT with LoRA (lora_r 16, lora_alpha 32), trains on the first 2,000 of the dataset's 78,577 rows for 3 epochs at a learning rate of 2.0e-4, then pushes the adapters to Hugging Face and metrics to W&B.", "body_md": "This is a short article that demonstrates how to fine-tune a small language model without writing a single line of Python code. The fine-tuning job is dispatched on the Modal Cloud platform and uses a **T4 GPU.** The fine-tuned adapters are then pushed to Hugging Face, and metrics are pushed to **W&B**. We use a library called [** TRLoom**](https://github.com/saqlain2204/trloom) that provides us the ability to dispatch fine-tuning jobs with a single yaml configuration file.\n\n**Dataset used:** [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) available on huggingface. For simplicity we consider only the first 2000 items of the train split of the dataset. This can be extended based on your usage.\n\n**Base Model:** [HuggingFaceTB/SmolLM2–135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct). We use a 135M Instruction-tuned model.\n\nStep 1:\n\nInstall the dependency. “all” installs wandb and modal dependencies.\n\n```\npip install \"trloom[all]\"\n```\n\nStep 2:\n\nSetup modal and authenticate via browser\n\n```\npython -m modal setup\n```\n\nStep 3:\n\nAdd secrets to Modal Cloud\n\n```\npython -m modal secret create wandb WANDB_API_KEY=your_key_herepython -m modal secret create huggingface HF_TOKEN=your_hf_token_here\n```\n\nStep 4:\n\nSo we are all set. Our environments are prepared to take up the fine-tuning job. Create a configuration file for your fine-tuning configurations. Refer to the yaml below.\n\n```\n# TRLoom config: fine-tune a tiny instruct model to turn natural-language# questions + a table schema into a SQL query.## Model  : HuggingFaceTB/SmolLM2-135M-Instruct  (135M params — very small)# Dataset: b-mc2/sql-create-context             (question, context, answer)# Method : SFT + LoRA## Validate:  trloom validate sft_sql_config.yaml# Run local: trloom run sft_sql_config.yaml --local# Run modal: trloom run sft_sql_config.yaml --modalmethod: sftmodel:  model_name_or_path: HuggingFaceTB/SmolLM2-135M-Instruct  dtype: bfloat16  use_peft: true          # set to false to full-finetune (model is tiny enough to afford it)  lora_r: 16  lora_alpha: 32  lora_dropout: 0.05  lora_target_modules:    - q_proj    - k_proj    - v_proj    - o_projdataset:  path: b-mc2/sql-create-context  split: \"train[:2000]\"   # smoke-test subset — remove this line (or widen it) to use all 78,577 rows  train_split: train  eval_split: null        # this dataset ships one split only  # Turn {question, context, answer} into one \"text\" field via an inline  # Jinja2 template — no extra Python file needed.  prompt_template: |    ### Task:    Given the SQL table schema below, write a SQL query that answers the question.    ### Schema:    {{ context }}    ### Question:    {{ question }}    ### SQL:    {{ answer }}  prompt_output_column: text  prompt_remove_columns: true  text_column: texttraining:  output_dir: ./outputs/sql-sft  learning_rate: 2.0e-4  num_train_epochs: 3  per_device_train_batch_size: 8  gradient_accumulation_steps: 2  logging_steps: 10  save_steps: 200  bf16: true  dataset_text_field: text  max_length: 512wandb:  enabled: true  project: trloom-sql-tiny-sft  run_name: smollm2-135m-sql-lora  tags: [sft, lora, sql, smollm2]  notes: \"Fine-tuning SmolLM2-135M-Instruct on b-mc2/sql-create-context for NL-to-SQL generation.\"  mode: online             # switch to \"offline\" to debug without network accessmodal:  enabled: true  app_name: trloom-sql-sft  gpu: T4                  # plenty for a 135M model; bump to A10G/A100 for the full dataset + more epochs  timeout: 14400  volume_name: trloom-sql-outputs  volume_mount: /outputs  secrets:    - wandb                # created via: python -m modal secret create wandb WANDB_API_KEY=...    - huggingface           # created via: python -m modal secret create huggingface HF_TOKEN=hf_...  install_source: pypi      # \"local\" while developing against a cloned trloom repo; use \"pypi\" otherwise  download_dir: ./outputs/remote-download# Push the trained adapter (or full model, if use_peft: false) to the Hub# once training finishes. Requires being logged in locally (`huggingface-cli# login`) or, on Modal, the \"huggingface\" secret above.push_to_hub: truehub_model_id: <your_huggingface_username>/trloom-test-smollm2-135m-sql-lora   # <-- change to your namespace/reposeed: 42\n```\n\nStep 4.1 (Optional)\n\nValidate the yaml:\n\n```\ntrloom validate sft_config.yaml\n```\n\nYou should get the response like below:\n\n```\n{  \"ok\": true,  \"method\": \"sft\",  \"trainer\": \"SFTTrainer\",  \"config_class\": \"SFTConfig\",  \"experimental\": false,  \"output_dir\": <whatever the output directory is>,  \"wandb_enabled\": true,  \"modal_enabled\": true}\n```\n\nStep 5:\n\nRun the fine tuning job:\n\n```\ntrloom run sft_config.yaml\n```\n\nYour fine tuning job will be live on Modal and You will get the link of W&B runs in the Modal container logs.\n\nAfter the training has been completed the Model will be pushed to hub.\n\nThe W&B runs will be visible in the project page of W&B\n\nThanks for reading. TRLoom is now open for contributions. A star to the repo ⭐️ would be much appreciated.\n\nFor documentation: [https://saqlain2204.github.io/trloom](https://saqlain2204.github.io/trloom)\n\nGithub Repo: [https://github.com/saqlain2204/trloom](https://github.com/saqlain2204/trloom)\n\nPypi: [https://pypi.org/project/trloom/](https://pypi.org/project/trloom/)\n\n[How to Fine-Tune a Small Language Model Without Writing a Single Line of Python Code on Modal Cloud](https://pub.towardsai.net/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python-code-on-modal-cloud-aba98bd0220d) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python", "canonical_source": "https://pub.towardsai.net/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python-code-on-modal-cloud-aba98bd0220d?source=rss----98111c9905da---4", "published_at": "2026-09-17 06:08:06+00:00", "updated_at": "2026-09-17 06:25:33.494932+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "mlops", "ai-infrastructure"], "entities": ["Modal Cloud", "TRLoom", "Hugging Face", "Weights & Biases", "HuggingFaceTB/SmolLM2-135M-Instruct", "b-mc2/sql-create-context", "T4 GPU"], "alternates": {"html": "https://wpnews.pro/news/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python", "markdown": "https://wpnews.pro/news/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python.md", "text": "https://wpnews.pro/news/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python.txt", "jsonld": "https://wpnews.pro/news/how-to-fine-tune-a-small-language-model-without-writing-a-single-line-of-python.jsonld"}}