DeepFellow DOCS
Finetuning

DF-Finetune CLI Reference

Commands, flags, and the training configuration file format for the df-finetune scripts.

DF-Finetune ships as a set of standalone Python scripts. Run each one with python SCRIPT.py [OPTIONS] from the root of the df-finetune repository, inside its virtual environment.

Configuration File

train.py, run.py, and generate.py take a --config flag pointing to a YAML file that describes the model, dataset, and training hyperparameters. Example configs live under configs/.

FieldDescription
model.nameAdapter output folder name.
model.descriptionFree-text description of the experiment.
data.pathPath to a JSONL dataset of prompt-response pairs.
data.max_lengthMaximum token length per training example.
data.train_splitFraction of the dataset used for training, for example 0.9.
data.prompt_fieldJSONL field holding the prompt. Defaults to prompt.
data.response_fieldJSONL field holding the response. Defaults to response.
data.random_seedSeed for the train/validation split. Defaults to 42.
architecture.pretrained_modelAny Hugging Face causal language model ID.
architecture.quantization4bit, 8bit, fp32, or null for fp16. 4bit requires CUDA.
architecture.lora.rankLoRA rank.
architecture.lora.alphaLoRA alpha.
architecture.lora.dropoutLoRA dropout.
architecture.lora.target_modulesList of module names LoRA attaches to. See LoRA target modules by model.
training.epochsNumber of training epochs.
training.batch_sizePer-device training batch size.
training.gradient_accumulation_stepsNumber of steps to accumulate gradients over.
training.learning_rateLearning rate.
training.warmup_ratioFraction of steps used for learning rate warmup.
training.grad_clipGradient clipping norm.
training.gradient_checkpointingSet to true to trade compute for memory.
output.model_dirBase directory for trained adapters.
output.log_levelDefault log level. --log-level overrides this.

train.py

Train a single LoRA adapter from a configuration file.

python train.py --config CONFIG_PATH [OPTIONS]
FlagDescription
--config PATHRequired. Path to the training configuration file.
--log-level LEVELOne of debug, external, info, warning, error. Overrides output.log_level from the config.
--quietSuppress warnings from external libraries such as transformers and torch.
--helpShow help and exit.

train.py saves the LoRA adapter, tokenizer, and a metadata.json provenance file to MODEL_DIR/MODEL_NAME/.


run.py

Train a model and convert it to GGUF in a single, idempotent workflow. run.py skips training when a trained adapter already exists, and skips conversion when a GGUF file already exists.

python run.py --config CONFIG_PATH [OPTIONS]
FlagDescription
--config PATHRequired. Path to the training configuration file.
--force-retrainDelete the existing adapter directory and retrain, even when a trained adapter already exists.
--force-convertDelete the existing GGUF output and reconvert, even when a GGUF file already exists.
--skip-ggufSkip the GGUF conversion step.
--outtype TYPEGGUF output format: f32, f16, bf16, or q8_0. Defaults to f16.
--log-level LEVELOne of debug, info, warning, error. Defaults to info.
--quietSuppress warnings from external libraries.
--helpShow help and exit.

generate.py

Generate text from a prompt with the base model and, when a trained adapter exists, with the fine-tuned model, for side-by-side comparison.

python generate.py --config CONFIG_PATH --prompt "PROMPT_TEXT" [OPTIONS]
FlagDescription
--config PATHRequired. Path to the training configuration file.
--prompt TEXTRequired. Prompt to generate from.
--max-tokens NMaximum number of tokens to generate. Defaults to 150.
--helpShow help and exit.

When no trained adapter exists at the configured output path, generate.py prints the base model's output only, and tells you to run train.py first.


convert_to_gguf.py

Convert a trained LoRA adapter to GGUF format for use with llama.cpp. run.py calls this conversion internally. Run it directly to convert an adapter without retraining.

python convert_to_gguf.py --adapter ADAPTER_PATH [OPTIONS]
FlagDescription
--adapter PATHRequired. Path to a trained adapter directory containing adapter_config.json.
--output PATHOutput directory. Defaults to ADAPTER_PATH/gguf.
--outtype TYPEOutput tensor format: f32, f16, bf16, q8_0, or auto. Defaults to f16.
--log-level LEVELOne of debug, info, warning, error. Defaults to info.
--quietSuppress warnings from external libraries.
--helpShow help and exit.

On first run, convert_to_gguf.py clones a sparse checkout of llama.cpp into .cache/llama.cpp/ to use its converter script. It writes adapter.gguf and a metadata.json file to the output directory.


upload_job.py

Upload a training file to a running DeepFellow Server and create a fine-tuning job through its API. Use this script to submit jobs for worker.py to process. It does not train anything itself.

python upload_job.py FILE MODEL [OPTIONS]
ArgumentDescription
FILEPositional. Path to a JSONL training file.
MODELPositional. Base model ID, for example gpt2.
--api-url URLDeepFellow Server URL. Defaults to http://localhost:8000.
--email EMAILAdmin email used to authenticate, when --api-key is not set.
--password PASSWORDAdmin password used to authenticate, when --api-key is not set.
--epochs NNumber of training epochs, passed as a job hyperparameter.
--batch-size NTraining batch size, passed as a job hyperparameter.
--lr-multiplier FLOATLearning rate multiplier, passed as a job hyperparameter.
--api-key KEYUse an existing project API key, and skip organization, project, and key setup.

upload_job.py and worker.py are clients of DeepFellow Server's fine-tuning API. That API, including /v1/fine_tuning/jobs and its request and response shapes, is documented in the API reference, not here.


worker.py

Run the fine-tuning worker: a long-running process that polls MongoDB for queued fine-tuning jobs, trains them, and reports status back to the job document.

python worker.py

worker.py takes no command-line flags. Configure it with environment variables, typically through a .env file at the root of the repository.

VariableDefaultDescription
DF_MONGO_USERlocal development valueMongoDB username.
DF_MONGO_PASSWORDlocal development valueMongoDB password.
DF_MONGO_URLlocalhost:27017MongoDB host and port.
DF_MONGO_DBdeepfellowMongoDB database name.
DF_SERVER_BASE_URLhttp://localhost:8000Base URL of DeepFellow Server, used to download training files.
DF_WORKER_POLL_INTERVAL5Seconds to wait between polls when the queue is empty.

worker.py reads the same variable names as DeepFellow Server, so you point both processes at the same MongoDB instance without duplicating configuration.

We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.