[Torch5-bugs] [ torch5-Bugs-1797573 ] Bug in deep copy produced by memory files
Status: Pre-Alpha
Brought to you by:
andresy
|
From: SourceForge.net <no...@so...> - 2007-10-27 00:24:51
|
Bugs item #1797573, was opened at 2007-09-19 01:20 Message generated for change (Settings changed) made by andresy You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=905598&aid=1797573&group_id=183526 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: thespermwhale (thespermwhale) Assigned to: Raoul d'Andresy (andresy) Summary: Bug in deep copy produced by memory files Initial Comment: Somehow the deep copy is actually only a shallow copy.. This code shows the bug: require "torch" require "nn" mlp= nn.Sequential(); mlp:add(nn.Linear(5,1)) -- create a deepcopy of the mlp file = torch.Archiver(); file:writeObject(mlp); file:seek(1) mlp_tmp = file:readObject() mlp_tmp:get(1).weight[1][1]=99 print(mlp_tmp:get(1).weight) print(mlp:get(1).weight) ---------------------------------------------------------------------- Comment By: Raoul d'Andresy (andresy) Date: 2007-10-27 00:24 Message: Logged In: YES user_id=1651867 Originator: NO this bug was actually not related to memory files, but to Archiver: because of the tree of objects it generates internally it is non-sense to use an Archiver in read-write mode. all the files now can be open open in "r", "w" or "rw" mode (read/write/read-write). by default MemoryFile opens in "rw". an Archiver can be open only in "r" or "w" mode. asking for the file possibility is done by methods isReadable() and isWritable(). to achieve what Jason wanted to do, one can now do: (1) f = torch.MemoryFile() -- opened in "rw" mode by default (2) a = torch.Archiver(f, "w") -- we want to write some stuff (3) a:writeObject(mlp) -- we write some stuff (4) a = torch.Archiver(f, "r") -- we want to read now! (5) a:seek(1) -- seek at the beginning (6) obj = a:readObject() -- we got a clone of the mlp! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=905598&aid=1797573&group_id=183526 |