Project: s41467-024-46413-6 | Function: run_inference (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Performs malignant cell inference using the trained Cancer-Finder model with softmax probability calculation and threshold-based classification

**KEY TERMS:** {
  "algorithm": "VREx model for domain generalization",
  "torch.softmax": "softmax probability calculation",
  "out": "malignant probability scores",
  "threshold": "classification threshold (default 0.5)",
  "predict_dict": "inference results storage"
}

**CONTEXT CODE:** from torch.utils.data import TensorDataset,DataLoader
import torch
import pandas as pd 
from models import model
from utils import opt_utils,args_utils
import warnings
from typing import Optional

def run_inference(args):
    """
    Run inference using the provided arguments.

    Args:
        args: Arguments for inference.

    Returns:
        DataFrame containing the inference results.
    """
    # MASKED: Performs malignant cell inference using the trained Cancer-Finder model with softmax probability calculation and threshold-based classification implementation
    raise NotImplementedError("This function is masked for testing purposes.")

def infering(
    # Model parameters
    matrix = 'data_matrix.h5ad',
    num_classes: int = 2,
    ckp: str = 'checkpoints/sc_pretrain_article.pkl',
    threshold: float = 0.5,
    out: str = 'out.csv',
    
    # Training parameters (kept for model initialization)
    lr: float = 1e-3,
    schuse: bool = False,
    schusech: str = 'cos',
    seed: int = 0,
    gpu_id: Optional[int] = None,
    weight_decay: float = 5e-4,
    momentum: float = 0.9,
    lr_decay: float = 0.75,
    lr_decay1: float = 1.0,
    lr_decay2: float = 1.0,
    anneal_iters: int = 500,
    max_epoch: int = 5,
    lam: float = 1,
    gene_num: int = 4572,
    label_str: str = 'label',
    batch_size: int = 10,
    NEED_ROWS: int = 50,
    save_output: bool = True
) -> None:
    """
    Perform inference using a pre-trained model on AnnData object.
    
    Args:
        num_classes (int): Number of classes for classification
        ckp (str): Path to the checkpoint file containing the pre-trained model
        threshold (float): Classification threshold for binary predictions
        out (str): Path to save the output predictions
        lr (float): Learning rate
        schuse (bool): Whether to use scheduler
        schusech (str): Scheduler type
        seed (int): Random seed
        gpu_id (Optional[int]): GPU device ID
        weight_decay (float): Weight decay for optimizer
        momentum (float): Momentum for optimizer
        lr_decay (float): Learning rate decay
        lr_decay1 (float): Learning rate decay for pretrained featurizer
        lr_decay2 (float): Initial learning rate decay of network
        anneal_iters (int): Penalty anneal iterations used in VREx
        max_epoch (int): Maximum number of epochs
        lam (float): Tradeoff hyperparameter used in VREx
        gene_num (int): Number of features
        label_str (str): Row label for the label in training data
        batch_size (int): Batch size
        NEED_ROWS (int): Number of samples in one step
        save_output (bool): Option to save or not the output
    
    Returns:
        pd.DataFrame
    """
    # Convert function arguments to args object
    args = args_utils.create_args_from_infering(
        matrix=matrix,
        num_classes=num_classes,
        ckp=ckp,
        threshold=threshold,
        out=out,
        lr=lr,
        schuse=schuse,
        schusech=schusech,
        seed=seed,
        gpu_id=gpu_id,
        weight_decay=weight_decay,
        momentum=momentum,
        lr_decay=lr_decay,
        lr_decay1=lr_decay1,
        lr_decay2=lr_decay2,
        anneal_iters=anneal_iters,
        max_epoch=max_epoch,
        lam=lam,
        gene_num=gene_num,
        label_str=label_str,
        batch_size=batch_size,
        NEED_ROWS=NEED_ROWS
    )
    
    predict_df = run_inference(args)

    # save results


Complete the function implementation replacing "raise NotImplementedError".