Skip to content

Instantly share code, notes, and snippets.

@jesuscast
Last active October 16, 2017 05:08
Show Gist options
  • Save jesuscast/42a2aae76b5f02e28bdfd1e76bb36f77 to your computer and use it in GitHub Desktop.
Save jesuscast/42a2aae76b5f02e28bdfd1e76bb36f77 to your computer and use it in GitHub Desktop.

Revisions

  1. jesuscast revised this gist Oct 16, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -34,4 +34,5 @@ def exp():
    p.start()
    p.join()
    assert p.exitcode != 0, "Child process call to qr did not fail"
    assert p.exitcode == -11, "The error is not a segmentation fault %s" % p.exitcode
    print("Child process call to QR failed as expected")
  2. jesuscast revised this gist Oct 16, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -23,11 +23,12 @@ def exp():
    flattened = get_flattened(tensor)
    # It should fail if being called
    # in a child process.
    torch.qr(flattened)
    return torch.qr(flattened)

    if __name__=="__main__":
    # First call
    exp()
    result = exp()
    assert result is not None, "Oops, it should have not failed here"
    # Now create child process.
    p = mp.Process(target=exp)
    p.start()
  3. jesuscast revised this gist Oct 16, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ def get_flattened(tensor):
    return flattened

    def get_mat():
    """ This is what we send when doing the initialization """
    """ This is what we send when during the initialization """
    wc_dim = 200
    mat = nn.utils.weight_norm(nn.Linear(wc_dim, wc_dim, bias=False), name="weight")
    tensor = mat.weight.data
  4. jesuscast revised this gist Oct 16, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    import torch.nn as nn
    import multiprocessing as mp

    def get_flattened():
    def get_flattened(tensor):
    """ This is just the first part of orthogonal initialization.
    Taken directly from https://github.com/pytorch/pytorch/blob/master/torch/nn/init.py
    """
  5. jesuscast revised this gist Oct 16, 2017. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -6,19 +6,24 @@ def get_flattened():
    """ This is just the first part of orthogonal initialization.
    Taken directly from https://github.com/pytorch/pytorch/blob/master/torch/nn/init.py
    """
    wc_dim = 200
    mat = nn.utils.weight_norm(nn.Linear(wc_dim, wc_dim, bias=False), name="weight")
    tensor = mat.weight.data

    rows = tensor.size(0)
    cols = tensor[0].numel()
    flattened = torch.Tensor(rows, cols).normal_(0, 1)
    return flattened

    def get_mat():
    """ This is what we send when doing the initialization """
    wc_dim = 200
    mat = nn.utils.weight_norm(nn.Linear(wc_dim, wc_dim, bias=False), name="weight")
    tensor = mat.weight.data
    return tensor

    def exp():
    tensor = get_mat()
    flattened = get_flattened(tensor)
    # It should fail if being called
    # in a child process.
    torch.qr(get_flattened())
    torch.qr(flattened)

    if __name__=="__main__":
    # First call
  6. jesuscast revised this gist Oct 16, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions torch_qr_fail.py
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,9 @@
    import multiprocessing as mp

    def get_flattened():
    """ This is just the first part of orthogonal initialization.
    Taken directly from https://github.com/pytorch/pytorch/blob/master/torch/nn/init.py
    """
    wc_dim = 200
    mat = nn.utils.weight_norm(nn.Linear(wc_dim, wc_dim, bias=False), name="weight")
    tensor = mat.weight.data
  7. jesuscast renamed this gist Oct 16, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. jesuscast created this gist Oct 16, 2017.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import torch
    import torch.nn as nn
    import multiprocessing as mp

    def get_flattened():
    wc_dim = 200
    mat = nn.utils.weight_norm(nn.Linear(wc_dim, wc_dim, bias=False), name="weight")
    tensor = mat.weight.data

    rows = tensor.size(0)
    cols = tensor[0].numel()
    flattened = torch.Tensor(rows, cols).normal_(0, 1)
    return flattened

    def exp():
    # It should fail if being called
    # in a child process.
    torch.qr(get_flattened())

    if __name__=="__main__":
    # First call
    exp()
    # Now create child process.
    p = mp.Process(target=exp)
    p.start()
    p.join()
    assert p.exitcode != 0, "Child process call to qr did not fail"
    print("Child process call to QR failed as expected")