microsoft/qlib · error · ValueError
Empty data from dataset, please check your dataset config.
Error message
Empty data from dataset, please check your dataset config.
What it means
Raised by SFM model fit() in qlib/contrib/model/pytorch_sfm.py:372 when dataset.prepare(['train','valid']) yields an empty train or valid DataFrame. It is a data sanity guard identical in spirit to the other pytorch contrib models: zero rows in a segment means the dataset/handler config does not intersect the available data, and training cannot proceed.
Source
Thrown at qlib/contrib/model/pytorch_sfm.py:372
self.train_optimizer.zero_grad()
loss.backward()
torch.nn.utils.clip_grad_value_(self.sfm_model.parameters(), 3.0)
self.train_optimizer.step()
def fit(
self,
dataset: DatasetH,
evals_result=dict(),
save_path=None,
):
df_train, df_valid = dataset.prepare(
["train", "valid"],
col_set=["feature", "label"],
data_key=DataHandlerLP.DK_L,
)
if df_train.empty or df_valid.empty:
raise ValueError("Empty data from dataset, please check your dataset config.")
x_train, y_train = df_train["feature"], df_train["label"]
x_valid, y_valid = df_valid["feature"], df_valid["label"]
save_path = get_or_create_path(save_path)
stop_steps = 0
train_loss = 0
best_score = -np.inf
best_epoch = 0
evals_result["train"] = []
evals_result["valid"] = []
# train
self.logger.info("training...")
self.fitted = True
for step in range(self.n_epochs):
self.logger.info("Epoch%d:", step)
self.logger.info("training...")View on GitHub (pinned to 79633dd950)
Solutions
- Print dataset.prepare('train', col_set=['feature','label']) and .empty for both segments to identify the empty one.
- Align segment boundaries with the data calendar (check via qlib.calendar).
- Verify qlib.init(provider_uri=...) points at a valid dumped dataset and instruments exist.
- Register custom segments in DatasetH if you reference non-default segment names.
Example fix
# before valid: [2019-01-01, 2022-12-31] # dump ends 2020 # after valid: [2018-01-01, 2020-12-31]
Defensive patterns
Strategy: validation
Validate before calling
for seg in ("train", "valid"):
df = dataset.prepare(seg, col_set=["feature", "label"], data_key="learn")
if df.empty:
raise ValueError(f"SFM fit(): segment '{seg}' empty — check date ranges, instruments, provider_uri") Try / catch
try:
model.fit(dataset)
except ValueError as e:
if "Empty data" in str(e):
print({s: dataset.prepare(s, col_set=["feature", "label"]).shape for s in ("train", "valid")})
raise
raise Prevention
- Validate segments against the data calendar before training.
- Confirm provider_uri is initialized and contains your instrument universe.
- Prefer explicit segment tuples in DatasetH over ad-hoc names.
When it happens
Trigger: Segments whose date ranges fall outside the data dump's calendar; expression filters in the handler that eliminate all rows; wrong provider_uri / missing qlib.init; segment names not defined in the DatasetH.
Common situations: Valid segment set past the last dumped date; custom instruments file with codes absent from the dump; running examples against a different market than the data downloaded.
Related errors
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- invalid memory_mode `{self.memory_mode}`
- Must specify the path to save the dataset.
- Empty data from dataset, please check your dataset config.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/bd38b96acd9f1aa2.
Report an issue: GitHub.