Mazda Motor Corp. and the United Auto Workers union will sign an agreement Wednesday that could give the Japan-based auto maker a $6 hourly labor-cost advantage over U.S.-based car companies by 1991.

Union and industry sources said yesterday that the signing will take place in Hiroshima, Japan -- Mazda headquarters -- where top UAW and company officials have been finishing details on the contract for workers at a Michigan plant.

The agreement will cover about 3,500 employes at a planned Mazda car assembly plant in Flat Rock, Mich., which is scheduled to begin production of the first of 240,000 cars annually in the spring of 1987. This will mark the first time that a Japan-based car company has welcomed the UAW into its plant.

Another Japanese manufacturer, Toyota Motor Corp., currently is negotiating with the UAW to represent production employes of New United Motor Manufacturing Inc., a joint-venture company operated by Toyota and General Motors Corp. in Fremont, Calif. The UAW there, too, is fashioning an agreement designed to give the company highly competitive labor costs.

"We're close. We will try to get it done by the end of June," said Bruce Lee, UAW's Region 6 director, commenting on the NUMMI negotiations. But Lee said that "there is nothing magic" about the tentative schedule for ending the talks. "We haven't even discussed economics, yet," said Lee, whose region includes the nine western states.

But Lee confirmed already published reports that the union in Fremont is considering new pay schemes such as "pay for knowledge" -- a system under which hourly workers are paid according to their ability to do a variety of jobs. Such a system would eliminate rigid job classifications and reduce production costs by increasing manufacturing flexibility, auto industry analysts and officials contend.

Labor-cost savings at the Michigan Mazda plant would come from initial hourly wage rates that would be 85 percent of those scheduled to be paid by Ford Motor Co., beginning in July 1988. For example, Mazda's base hourly rate would start at $14.30 that year, according to a letter of intent between Mazda and the UAW, compared with $16.82 an hour scheduled to be paid by Ford.

UAW breaks on pensions and other retirement benefits, and on job classifications, will help Mazda to make up the rest of the $6 hourly production-cost advantage, according to the letter.

The UAW-Mazda contract that will be signed Wednesday will run for three years and will include a no-strike, no-lockout cause.

UAW officials reached in Detroit yesterday said that the agreement represents progress instead of concessions. "We want a minimum of adversarial relationships" with employers, a UAW spokesman said. "We're doing all of these things for a particular reason, and that is to keep jobs for our people," the union spokesman said.