Solving the 'Works in Interactive' Gap with Kaggle Commits
Stop relying on interactive sessions for Kaggle submissions. Learn how to use the 'Save & Run All' workflow and the /kaggle/working directory to ensure your model scores consistently on the leaderboard.
03 Sept 2025, 17:59 UTC

The Gap Between Interactive Sessions and Leaderboard Scores
A common frustration for Kaggle competitors is the "interactive success, submission failure" loop. You spend hours tuning a model in an interactive notebook session, achieve a great local score, and hit submit—only to find the actual leaderboard score is different or the notebook crashes entirely.
The problem is that a Kaggle submission is not a snapshot of your current live session. It is a request for the platform to execute your notebook from top to bottom in a fresh, isolated environment. If your code relies on a variable you created manually in a cell three hours ago, or a library you installed via a temporary pip install that isn't scripted, the submission will fail.
To ensure reproducibility, treat the Save & Run All (Commit) workflow as your primary unit of deployment. This process transforms your notebook from a scratchpad into a deterministic artifact.
The Kaggle File System Architecture
Understanding where data lives is critical for a successful commit. Kaggle uses a specific directory structure that persists differently depending on the session type:
/kaggle/input/: A read-only directory where all attached datasets and competition data reside. Any external weights or custom libraries must be added as datasets to be accessible here./kaggle/working/: The only writable directory. This is where yoursubmission.csvmust be saved. Files created here during aSave & Run Allexecution are persisted as output artifacts for that version.
Enforcing Determinism with the "Internet Off" Toggle
One of the most effective engineering decisions you can make is disabling the Internet toggle in the notebook settings before your final commit. While interactive development requires the web to fetch documentation or libraries, a submission notebook should be self-contained.
Turning the Internet off forces you to resolve dependencies upfront. If your code attempts to download a pre-trained model from Hugging Face or a CSV from a URL during execution, the commit will fail. By forcing this failure early, you ensure that all required assets are attached as Kaggle datasets, eliminating "works on my machine" errors caused by API timeouts or changed external URLs during the scoring phase.
Worked Example: An Inference-Only Submission
For many competitions, the most stable approach is to separate training from inference. You train your model, save the weights as a dataset, and use a clean notebook for the submission. Here is the configuration for a deterministic inference run:
# Run this in a Kaggle Notebook with:
# 1. Accelerator: GPU (if needed)
# 2. Internet: Off
# 3. Dataset attached: 'my-pretrained-weights'
import pandas as pd
import joblib
import os
# 1. Load data from the read-only input directory
test_df = pd.read_csv('/kaggle/input/competition-name/test.csv')
model = joblib.load('/kaggle/input/my-pretrained-weights/model.pkl')
# 2. Ensure deterministic predictions (fixed seeds)
import numpy as np
np.random.seed(42)
# 3. Generate predictions
predictions = model.predict(test_df)
# 4. Write to the writable working directory
submission = pd.DataFrame({'id': test_df['id'], 'target': predictions})
submission.to_csv('/kaggle/working/submission.csv', index=False)
# Verification check: Ensure output matches sample format
print(f"Submission shape: {submission.shape}")
Trade-offs: Iteration Speed vs. Reliability
The primary trade-off is time. Interactive sessions allow for rapid experimentation, but they are volatile. A Save & Run All commit is queued and must run to completion, which can be slow for heavy models and consumes your daily GPU/TPU quotas.
To balance this, use the Interactive → Commit → Verify cycle: iterate quickly in the interactive editor, but never trust a result until it has been produced by a clean commit with Internet disabled.
Verifying the Result
Before submitting the version to the leaderboard, perform these three checks:
- Check the Output Tab: After the commit finishes, navigate to the "Output" section of the notebook version. Confirm that
submission.csvexists. - Validate Row Counts: Compare the row count of your generated
submission.csvagainst thesample_submission.csvprovided by the competition. A mismatch here is the most common cause of submission errors. - Log Review: Check the execution logs for any warnings regarding memory usage or deprecated libraries that might trigger a crash during the hidden test set evaluation.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.