Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/textless_nlp/gslm/unit2speech/glow.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, n_in_channels, n_mel_channels, n_layers, n_channels,
self.res_skip_layers = torch.nn.ModuleList()

start = torch.nn.Conv1d(n_in_channels, n_channels, 1)
start = torch.nn.utils.weight_norm(start, name='weight')
start = torch.nn.utils.parametrizations.weight_norm(start, name='weight')
self.start = start

# Initializing last layer to 0 makes the affine coupling layers
Expand All @@ -131,14 +131,14 @@ def __init__(self, n_in_channels, n_mel_channels, n_layers, n_channels,
self.end = end

cond_layer = torch.nn.Conv1d(n_mel_channels, 2*n_channels*n_layers, 1)
self.cond_layer = torch.nn.utils.weight_norm(cond_layer, name='weight')
self.cond_layer = torch.nn.utils.parametrizations.weight_norm(cond_layer, name='weight')

for i in range(n_layers):
dilation = 2 ** i
padding = int((kernel_size*dilation - dilation)/2)
in_layer = torch.nn.Conv1d(n_channels, 2*n_channels, kernel_size,
dilation=dilation, padding=padding)
in_layer = torch.nn.utils.weight_norm(in_layer, name='weight')
in_layer = torch.nn.utils.parametrizations.weight_norm(in_layer, name='weight')
self.in_layers.append(in_layer)


Expand All @@ -148,7 +148,7 @@ def __init__(self, n_in_channels, n_mel_channels, n_layers, n_channels,
else:
res_skip_channels = n_channels
res_skip_layer = torch.nn.Conv1d(n_channels, res_skip_channels, 1)
res_skip_layer = torch.nn.utils.weight_norm(res_skip_layer, name='weight')
res_skip_layer = torch.nn.utils.parametrizations.weight_norm(res_skip_layer, name='weight')
self.res_skip_layers.append(res_skip_layer)

def forward(self, forward_input):
Expand Down
41 changes: 38 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,27 @@ def get_files(path, relative_to="fairseq"):
# symlink examples into fairseq package so package_data accepts them
fairseq_examples = os.path.join("fairseq", "examples")
if "build_ext" not in sys.argv[1:] and not os.path.exists(fairseq_examples):
os.symlink(os.path.join("..", "examples"), fairseq_examples)
if os.name == 'nt': # Windows
# Use junction or copy instead of symlink on Windows
import shutil

# Get absolute path to examples directory
script_dir = os.path.dirname(os.path.abspath(__file__))
examples_source = os.path.join(script_dir, "examples")

# Verify source exists
if not os.path.exists(examples_source):
raise FileNotFoundError(f"Source examples directory not found: {examples_source}")

try:
# Try to create junction first (requires admin on older Windows)
subprocess.run(['mklink', '/J', fairseq_examples, examples_source],
shell=True, check=True)
except (subprocess.CalledProcessError, FileNotFoundError):
# Fallback to copying directory
shutil.copytree(examples_source, fairseq_examples)
else:
os.symlink(os.path.join("..", "examples"), fairseq_examples)

package_data = {
"fairseq": (
Expand All @@ -253,5 +273,20 @@ def get_files(path, relative_to="fairseq"):
}
do_setup(package_data)
finally:
if "build_ext" not in sys.argv[1:] and os.path.islink(fairseq_examples):
os.unlink(fairseq_examples)
if "build_ext" not in sys.argv[1:] and os.path.exists(fairseq_examples):
if os.name == 'nt': # Windows
import shutil
try:
# For junction points and directories, use rmtree
if os.path.isdir(fairseq_examples):
shutil.rmtree(fairseq_examples)
except (OSError, PermissionError) as e:
# If deletion fails, try alternative methods
try:
subprocess.run(['rmdir', '/S', '/Q', fairseq_examples],
shell=True, check=True)
except subprocess.CalledProcessError:
print(f"Warning: Failed to remove {fairseq_examples}: {e}")
else:
if os.path.islink(fairseq_examples):
os.unlink(fairseq_examples)