liveBook · Manning

Pretrained model

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A pretrained model is a machine-learning model whose parameters were learned previously on a dataset or task before subsequent use.

A pretrained model has learned parameters from an earlier dataset or task, so it can be applied without repeating the full training process. For TSP, this avoids the substantial code and data preprocessing required to train an ML model from scratch. section 11.7

Using a pretrained model for TSP involves:

  • Selecting a dataset, batch size, sample count, graph-sparsification proportion, and nearest-neighbor strategy. section 11.7
  • Loading the saved model, moving it to the selected CUDA or CPU device, choosing greedy decoding, and switching to evaluation mode. section 11.7
  • Producing a feasible candidate tour from the model’s edge probability distribution; Gurobi can help eliminate subtours and calculate reduced costs. section 11.7
Listing 11.4 Solving TSP using supervised ML
import os
import math
import itertools
import numpy as np
import networkx as nx
from scipy.spatial.distance import pdist, squareform
import seaborn as sns
import matplotlib.pyplot as plt
  
import torch
from torch.utils.data import DataLoader
from torch.nn import DataParallel
  
from learning_tsp.problems.tsp.problem_tsp import TSP
from learning_tsp.utils import load_model, move_to
  
from gurobipy import *
  
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

Inspect the Python setup for loading and evaluating a pretrained model on TSP instances. section 11.7

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Explains loading, device selection, decoding, evaluation, and configuration, but not parameter-training internals.
Examples
Uses a pretrained GNN model, TSP datasets, greedy decoding, CUDA configuration, and a plotted TSP50 solution.
What you can do after
Operate/configure a pretrained model to evaluate TSP instances without rebuilding the complete training pipeline.
How it connects
Connects supervised learning, reinforcement learning, graph machine learning, TSP, and Gurobi optimization.

Also explained in

Compare how 7 books explain pretrained model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.