Thousands flee NW Pakistan valley ahead of offensive