i try retrain with freeze method ,i  follow the example ,but i didnt succeed ,my code is this way:
def main():
global args, best_prec1
args = parser.parse_args()
    # create model
    if args.pretrained:
        print("=> using pre-trained model '{}'".format(args.arch))
        model = models.__dict__[args.arch](pretrained=True)
       #xxxxxxxxxxxxxx to modify  resnet 18 the fc layer xxxxxxxxxxxxxx
        model.fc=nn.Linear(512,100)
    else:
        print("=> creating model '{}'".format(args.arch))
        model = models.__dict__[args.arch]()

    #for param in model.parameters():
        #param.requires_grad = False
    if args.arch.startswith('alexnet') or args.arch.startswith('vgg'):
        model.features = torch.nn.DataParallel(model.features)
        model.cuda()
    else:
        model = torch.nn.DataParallel(model).cuda()

    # optionally resume from a checkpoint
    if args.resume:
        if os.path.isfile(args.resume):
            print("=> loading checkpoint '{}'".format(args.resume))
            checkpoint = torch.load(args.resume)
            args.start_epoch = checkpoint['epoch']
            best_prec1 = checkpoint['best_prec1']
            model.load_state_dict(checkpoint['state_dict'])
            print("=> loaded checkpoint '{}' (epoch {})"
                  .format(args.resume, checkpoint['epoch']))
        else:
            print("=> no checkpoint found at '{}'".format(args.resume))
#xxxxxxxxxxxxxx freeze  update xxxxxxxxxxxxxx
    for param in model.parameters():
        param.requires_grad = False
    
    # Replace the last fully-connected layer
    # Parameters of newly constructed modules have requires_grad=True by default
    #model.fc = torch.nn.Linear(512, 3)
    print(model)

    cudnn.benchmark = True

    # Data loading code
    traindir = os.path.join(args.data, 'train')
    valdir = os.path.join(args.data, 'val')
    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])

    train_loader = torch.utils.data.DataLoader(
        datasets.ImageFolder(traindir, transforms.Compose([
            transforms.RandomSizedCrop(224),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            normalize,
        ])),
        batch_size=args.batch_size, shuffle=True,
        num_workers=args.workers, pin_memory=True)

    val_loader = torch.utils.data.DataLoader(
        datasets.ImageFolder(valdir, transforms.Compose([
            transforms.Scale(256),
            transforms.CenterCrop(224),
            transforms.ToTensor(),
            normalize,
        ])),
        batch_size=args.batch_size, shuffle=False,
        num_workers=args.workers, pin_memory=True)

    # define loss function (criterion) and pptimizer
    criterion = nn.CrossEntropyLoss().cuda()
   #xxxxxxxxxxxxxx try to  make sgd only changing fc layer xxxxxxxxxxxxxx
    ignored_params = list(map(id, model.module.fc.parameters()))
    base_params = filter(lambda p: id(p) not in ignored_params,
                     model.module.parameters())


    optimizer = torch.optim.SGD([
            {'params': base_params},
            {'params': model.module.fc.parameters()
           }], args.lr,momentum=args.momentum, weight_decay=args.weight_decay)
    # optimizer = torch.optim.SGD(model.module.fc.parameters(), args.lr,momentum=args.momentum,                          weight_decay=args.weight_decay)

it occured a problem
ValueError: optimizing a parameter that doesn’t require gradients
where did  i missed