This flag would be true, if you explicitly create a TensorOptions object and set the memory format as shown in this example:
import torch
import torch.nn as nn
from torch.utils import cpp_extension

cuda_source = """
std::vector<torch::Tensor> my_fun(void)
{
    auto options = at::TensorOptions(at::MemoryFormat::ChannelsLast);
    auto out = torch::ones({2, 3, 4, 5}, options);
    std::cout << std::boolalpha << options.has_memory_format() << std::endl;
    return {out};
}
"""

cpp_source = """
    std::vector<torch::Tensor> my_fun(void);
"""

module = torch.utils.cpp_extension.load_inline(
    name="cuda_test_extension",
    cpp_sources=cpp_source,
    cuda_sources=cuda_source,
    functions="my_fun",
    verbose=True,
)

out = module.my_fun()